reference Rule syntax

languages

See also
--show-supported-languages, --lang, pattern-regex, generic_engine

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:

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: WARNING
app.js
el.innerHTML = comment;
app.ts
el.innerHTML = comment;
Command and result
$ opengrep scan -q --config rule.yaml --files-with-matches .
app.js
app.ts

An unknown language

rule.yaml
rules:  - id: find-eval    pattern: eval(...)    message: found eval    languages: [pyton]    severity: WARNING
app.py
eval(1)
Command and result
$ opengrep scan --config rule.yaml app.py > /dev/null 2>&1; echo "exit status: $?"
exit status: 8