languages
A list of languages. The rule runs on the files of each of these languages, and its patterns are parsed as code of the first language of the list. Every rule must have languages, with at least one language; a single language is still written as a list, [python].
Each language has a name and some aliases: python can also be written py, javascript js, typescript ts. --show-supported-languages lists them. An unknown name makes the rule invalid, and the scan exits with status 8.
Since the patterns are parsed in the first language only, a rule with several languages is suited to languages that share a syntax, such as JavaScript and TypeScript, or C and C++.
Two values are not programming languages:
genericruns the rule on every file, regardless of its extension. Its patterns are matched as text in which brackets and quotes nest; seegeneric_engine.regex, also spellednone, runs the rule on every file withpattern-regexand the other regular-expression keys only.
Examples
Two languages with a shared syntax
rule.yaml
rules: - id: inner-html pattern: $EL.innerHTML = $VALUE message: assignment to innerHTML languages: [javascript, typescript] severity: WARNINGapp.js
el.innerHTML = comment;app.ts
el.innerHTML = comment;Command and result
$ opengrep scan -q --config rule.yaml --files-with-matches .
app.js
app.tsAn unknown language
rule.yaml
rules: - id: find-eval pattern: eval(...) message: found eval languages: [pyton] severity: WARNINGapp.py
eval(1)Command and result
$ opengrep scan --config rule.yaml app.py > /dev/null 2>&1; echo "exit status: $?"
exit status: 8