Skip to content

Commit 24de826

Browse files
committed
JS: Add file diagnostics errors
1 parent e1d0bbb commit 24de826

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Extraction errors
3+
* @description List all extraction errors for files in the source code directory.
4+
* @kind diagnostic
5+
* @id js/diagnostics/extraction-errors
6+
*/
7+
8+
import javascript
9+
10+
/** Gets the SARIF severity to associate an error. */
11+
int getSeverity() { result = 2 }
12+
13+
from Error error
14+
where
15+
exists(error.getFile().getRelativePath()) and
16+
error.isFatal()
17+
select error, "Extraction failed in " + error.getFile() + " with error " + error.getMessage(),
18+
getSeverity()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name Successfully extracted files
3+
* @description Lists all files in the source code directory that were extracted without encountering an error in the file.
4+
* @kind diagnostic
5+
* @id js/diagnostics/successfully-extracted-files
6+
*/
7+
8+
import javascript
9+
10+
from File f
11+
where
12+
not exists(Error e | e.isFatal() and e.getFile() = f) and
13+
exists(f.getRelativePath())
14+
select f, ""

javascript/ql/src/semmle/javascript/Errors.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ abstract class Error extends Locatable {
1010
abstract string getMessage();
1111

1212
override string toString() { result = getMessage() }
13+
14+
/** Holds if this error prevented the file from being extracted. */
15+
predicate isFatal() { any() }
1316
}
1417

1518
/** A JavaScript parse error encountered during extraction. */
@@ -21,4 +24,6 @@ class JSParseError extends @js_parse_error, Error {
2124

2225
/** Gets the source text of the line this error occurs on. */
2326
string getLine() { js_parse_errors(this, _, _, result) }
27+
28+
override predicate isFatal() { not getTopLevel() instanceof Angular2::TemplateTopLevel }
2429
}

javascript/ql/src/semmle/javascript/Regexp.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ class RegExpParseError extends Error, @regexp_parse_error {
827827
override string getMessage() { regexp_parse_errors(this, _, result) }
828828

829829
override string toString() { result = getMessage() }
830+
831+
override predicate isFatal() { none() }
830832
}
831833

832834
/**

0 commit comments

Comments
 (0)