mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
Merge pull request #5656 from asgerf/js/files-diagnostics
JS: Add file diagnostics queries
This commit is contained in:
18
javascript/ql/src/Diagnostics/ExtractionErrors.ql
Normal file
18
javascript/ql/src/Diagnostics/ExtractionErrors.ql
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @name Extraction errors
|
||||
* @description List all extraction errors for files in the source code directory.
|
||||
* @kind diagnostic
|
||||
* @id js/diagnostics/extraction-errors
|
||||
*/
|
||||
|
||||
import javascript
|
||||
|
||||
/** Gets the SARIF severity to associate an error. */
|
||||
int getSeverity() { result = 2 }
|
||||
|
||||
from Error error
|
||||
where
|
||||
exists(error.getFile().getRelativePath()) and
|
||||
error.isFatal()
|
||||
select error, "Extraction failed in " + error.getFile() + " with error " + error.getMessage(),
|
||||
getSeverity()
|
||||
14
javascript/ql/src/Diagnostics/SuccessfullyExtractedFiles.ql
Normal file
14
javascript/ql/src/Diagnostics/SuccessfullyExtractedFiles.ql
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @name Successfully extracted files
|
||||
* @description Lists all files in the source code directory that were extracted without encountering an error in the file.
|
||||
* @kind diagnostic
|
||||
* @id js/diagnostics/successfully-extracted-files
|
||||
*/
|
||||
|
||||
import javascript
|
||||
|
||||
from File f
|
||||
where
|
||||
not exists(Error e | e.isFatal() and e.getFile() = f) and
|
||||
exists(f.getRelativePath())
|
||||
select f, ""
|
||||
@@ -10,6 +10,9 @@ abstract class Error extends Locatable {
|
||||
abstract string getMessage();
|
||||
|
||||
override string toString() { result = getMessage() }
|
||||
|
||||
/** Holds if this error prevented the file from being extracted. */
|
||||
predicate isFatal() { any() }
|
||||
}
|
||||
|
||||
/** A JavaScript parse error encountered during extraction. */
|
||||
@@ -21,4 +24,6 @@ class JSParseError extends @js_parse_error, Error {
|
||||
|
||||
/** Gets the source text of the line this error occurs on. */
|
||||
string getLine() { js_parse_errors(this, _, _, result) }
|
||||
|
||||
override predicate isFatal() { not getTopLevel() instanceof Angular2::TemplateTopLevel }
|
||||
}
|
||||
|
||||
@@ -840,6 +840,8 @@ class RegExpParseError extends Error, @regexp_parse_error {
|
||||
override string getMessage() { regexp_parse_errors(this, _, result) }
|
||||
|
||||
override string toString() { result = getMessage() }
|
||||
|
||||
override predicate isFatal() { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
| bad1.js:1:7:1:7 | Error: Unexpected token | Extraction failed in bad1.js with error Error: Unexpected token | 2 |
|
||||
| bad2.ts:1:11:1:11 | Error: Expression expected. | Extraction failed in bad2.ts with error Error: Expression expected. | 2 |
|
||||
| bad2.ts:1:13:1:13 | Error: Expression expected. | Extraction failed in bad2.ts with error Error: Expression expected. | 2 |
|
||||
| bad3.html:2:11:2:11 | Error: Unexpected token | Extraction failed in bad3.html with error Error: Unexpected token | 2 |
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/ExtractionErrors.ql
|
||||
@@ -0,0 +1,4 @@
|
||||
| contains-template.js:0:0:0:0 | contains-template.js | |
|
||||
| good1.js:0:0:0:0 | good1.js | |
|
||||
| good2.ts:0:0:0:0 | good2.ts | |
|
||||
| good3.html:0:0:0:0 | good3.html | |
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/SuccessfullyExtractedFiles.ql
|
||||
1
javascript/ql/test/query-tests/Diagnostics/bad1.js
Normal file
1
javascript/ql/test/query-tests/Diagnostics/bad1.js
Normal file
@@ -0,0 +1 @@
|
||||
let x x x;
|
||||
1
javascript/ql/test/query-tests/Diagnostics/bad2.ts
Normal file
1
javascript/ql/test/query-tests/Diagnostics/bad2.ts
Normal file
@@ -0,0 +1 @@
|
||||
const z = ??;
|
||||
3
javascript/ql/test/query-tests/Diagnostics/bad3.html
Normal file
3
javascript/ql/test/query-tests/Diagnostics/bad3.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<script>
|
||||
let q q q q ; // error
|
||||
</script>
|
||||
@@ -0,0 +1,4 @@
|
||||
const obj = {
|
||||
// Template where we can't parse `x x x` but surrounding file still OK
|
||||
template: '<b [foo]="x x x"></a>'
|
||||
};
|
||||
1
javascript/ql/test/query-tests/Diagnostics/good1.js
Normal file
1
javascript/ql/test/query-tests/Diagnostics/good1.js
Normal file
@@ -0,0 +1 @@
|
||||
let x = 123;
|
||||
1
javascript/ql/test/query-tests/Diagnostics/good2.ts
Normal file
1
javascript/ql/test/query-tests/Diagnostics/good2.ts
Normal file
@@ -0,0 +1 @@
|
||||
const y: string = "dfg";
|
||||
3
javascript/ql/test/query-tests/Diagnostics/good3.html
Normal file
3
javascript/ql/test/query-tests/Diagnostics/good3.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<script>
|
||||
let qwe = 123;
|
||||
</script>
|
||||
1
javascript/ql/test/query-tests/Diagnostics/options
Normal file
1
javascript/ql/test/query-tests/Diagnostics/options
Normal file
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --tolerate-parse-errors --experimental
|
||||
Reference in New Issue
Block a user