Skip to content

Commit 97ca115

Browse files
committed
JS: Sync ApiGraphModels.qll and test
1 parent 65249da commit 97ca115

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

javascript/ql/lib/semmle/javascript/frameworks/data/internal/ApiGraphModels.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,26 @@ module ModelOutput {
420420
result = getNodeFromPath(package2, type2, path)
421421
)
422422
}
423+
424+
/**
425+
* Gets an error message relating to an invalid CSV row in a model.
426+
*/
427+
string getAWarning() {
428+
// Check number of columns
429+
exists(string row, string kind, int expectedArity, int actualArity |
430+
any(SourceModelCsv csv).row(row) and kind = "source" and expectedArity = 4
431+
or
432+
any(SinkModelCsv csv).row(row) and kind = "sink" and expectedArity = 4
433+
or
434+
any(SummaryModelCsv csv).row(row) and kind = "summary" and expectedArity = 6
435+
or
436+
any(TypeModelCsv csv).row(row) and kind = "type" and expectedArity = 5
437+
|
438+
actualArity = count(row.indexOf(";")) + 1 and
439+
actualArity != expectedArity and
440+
result =
441+
"CSV " + kind + " row should have " + expectedArity + " columns but has " + actualArity +
442+
": " + row
443+
)
444+
}
423445
}

javascript/ql/test/library-tests/frameworks/data/test.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ syntaxErrors
8888
| Member[foo]Member[bar] |
8989
| Member[foo]] |
9090
| Member[foo]].Member[bar] |
91+
warning
92+
| CSV type row should have 5 columns but has 2: test;TooFewColumns |
93+
| CSV type row should have 5 columns but has 8: test;TooManyColumns;;;Member[Foo].Instance;too;many;columns |

javascript/ql/test/library-tests/frameworks/data/test.ql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ class SyntaxErrorTest extends ModelInput::SinkModelCsv {
7373
}
7474

7575
query predicate syntaxErrors(AccessPathSyntax::AccessPath path) { path.hasSyntaxError() }
76+
77+
private class InvalidTypeModel extends ModelInput::TypeModelCsv {
78+
override predicate row(string row) {
79+
row =
80+
[
81+
"test;TooManyColumns;;;Member[Foo].Instance;too;many;columns", //
82+
"test;TooFewColumns", //
83+
]
84+
}
85+
}
86+
87+
query predicate warning = ModelOutput::getAWarning/0;

0 commit comments

Comments
 (0)