Files
codeql/javascript/ql/src/Expressions/UnknownDirective.ql
2021-11-18 15:41:25 +01:00

23 lines
801 B
Plaintext

/**
* @name Unknown directive
* @description An unknown directive has no effect and may indicate a misspelling.
* @kind problem
* @problem.severity warning
* @id js/unknown-directive
* @tags correctness
* @precision high
*/
import javascript
from Directive d
where
not d instanceof KnownDirective and
// ignore ":" pseudo-directive sometimes seen in dual-use shell/node.js scripts
not d.getExpr().getStringValue() = ":" and
// but exclude attribute top-levels: `<a href="javascript:'some-attribute-string'">`
not d.getParent() instanceof CodeInAttribute and
// exclude babel generated directives like "@babel/helpers - typeof".
not d.getDirectiveText().matches("@babel/helpers%")
select d, "Unknown directive: '" + truncate(d.getDirectiveText(), 20, " ... (truncated)") + "'."