Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions swift/ql/src/diagnostics/SuccessfullyExtractedLines.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @name Successfully extracted lines
* @description Count all lines in source code in which something was extracted. Entities spanning multiple lines like multi-line strings or comments only contribute one line to this count.
* @kind metric
* @id swift/diagnostics/successfully-extracted-lines
* @tags summary
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm that * lines-of-code has been omitted here to avoid code-scanning from picking this up for the time being.

Copy link
Copy Markdown
Contributor Author

@redsun82 redsun82 Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this query is different than lines-of-code queries from other languages, as

  • it will not count lines for which nothing was extracted because of any kind of problem
  • it does count comment lines
  • it will count 1 line for big things spanning multiple lines. Multiline AST-entities typically have children elements that will show up in this count, but for example multiline strings and comments will contribute only 1 line in this metric.

I think this might be confusing if it were presented as the user-facing lines-of-code, but maybe this is up for debate? For the time being I'd keep it separate

Copy link
Copy Markdown
Contributor Author

@redsun82 redsun82 Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context: I've looked into how the C/C++ extractor extracts the data used by lines-of-code, and on each source file it just bluntly opens the file and counts the lines, matching empty and comment lines to fill in the different values of the numlines table (numcode is what is used in the lines-of-code query):

numlines(
int element_id: @sourceline ref,
int num_lines: int ref,
int num_code: int ref,
int num_comment: int ref
);

*/

import swift

select count(File f, int line |
exists(Location loc |
not loc instanceof UnknownLocation and loc.getFile() = f and loc.getStartLine() = line
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| 4 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
diagnostics/SuccessfullyExtractedLines.ql
3 changes: 3 additions & 0 deletions swift/ql/test/query-tests/Diagnostics/ignored.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//codeql-extractor-env: CODEQL_EXTRACTOR_SWIFT_RUN_UNDER=true

func not_compiled() {}
6 changes: 6 additions & 0 deletions swift/ql/test/query-tests/Diagnostics/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


// a comment


func foo() {}