A linter for Soufflé Datalog, based on tree-sitter-souffle, configured with tree-sitter queries.
Table of Contents
For now, build from source with cargo
.
bash
git clone https://github.com/langston-barrett/souffle-lint
cargo build --release
To install, just copy the binary somewhere:
cp target/release/souffle-lint /usr/bin
TBD.
Just pass a list of Soufflé Datalog files to souffle-lint lint
, or pass one on
stdin:
```bash
souffle-lint lint file.dl
souffle-lint lint souffle-lint lint file.dl path/to/file2.dl souffle-lint lint ./*/.dl
``` The exit code will be See Soufflé runs the C pre-processor (CPP) on Datalog files by default, and it is
customary for developers to use its functionality. The Each rule has an associated name. These names are visible in the list shown by
the You can disable a rule entirely by passing Ignoring a specific warning on a specific line is not yet implemented. Rules with slow execution times are disabled by default, you can enable them
with The YAML configuration file consists of a list of rules. Each rule
has: Here is an example of a simple rule which exhorts its user to simplify
compile-time constant additions: You can view the built-in configuration file at
A query describes a pattern in the program's concrete syntax tree (CST), a rule
triggers a warning when the query matches its CST. Queries are written in the
tree-sitter query language. The name should be less than 30 characters, the short description should be less
than 60 characters. You can see the tree-sitter S-expression (i.e., concrete syntax tree)
corresponding to Datalog source file(s) using the By convention, rules have names starting with common prefixes: Tested with lit and FileCheck
Large Soufflé files are available in Lint two files:
Lint all the Soufflé Datalog files the current directory:
0
if souffle-lint lint
succeeded with no warnings, 1
if there were any warnings, or 2
if there was a problem (e.g., a parse error
or bad configuration).--help
for more options.Pre-Processing
souffle-lint
parser
does not handle CPP directives; if you use them you must run the
pre-processor manually and then run souffle-lint
on the result. For instance,
bash
mcpp -W 0 -P your/datalog/file.dl -o out.dl
souffle-lint lint out.dl
souffle-lint
doesn't (yet) take advantage of the #line
directives in the CPP
output, so the line numbers in its output won't correspond to your source file.Ignoring Rules
info
command, and also in warning messages. For example, in the following
message, the rule name is error-dup-type-decl
:
warn[error-dup-type-decl] Duplicated type declaration
--ignore=<rule-name>
on the command
line. In fact, you can pass a prefix to --ignore
; any rules that start with
that prefix will be ignored. For example, --ignore=simpl
will disable any
rules with names starting with simpl
. See [Rule Categories][#rule-categories]
for information about common prefixes.souffle-lint lint --slow
.Writing Rules
yaml
rules:
- name: simpl-binop-plus
short: Simplify constant binary operation (+)
long: >
Some extended description of this rule.
examples:
- before: |
even(2 + 2).
after: |
even(4).
queries:
- |
(binary_op
left: (argument (constant))
operator: "+"
right: (argument (constant)))
./config/default.yml
.Showing the Parse Tree
sexp
command:
souffle-lint sexp file.dl
See souffle-lint sexp --help
for more details and other options.Rule Categories
depr
: This functionality is deprecatederror
: Soufflé would reject this code
error-dup
: Some entity is duplicatedsimpl
: The code can be simplified, possibly for better performance
simpl-dup
: Some entity is duplicatedstyle
: This is a stylistic choice
style-name
: This is a stylistic choice about namesDevelopment
Tests
bash
cargo build
lit --path=$PWD/target/debug test/
Benchmarks
bench/
. Try passing --trace
to
souffle-lint
. Compare performance to souffle --show=parse-errors
.Releasing
CHANGELOG.md
Cargo.toml
git checkout main && git pull origin && git tag -a vX.Y.Z -m vX.Y.Z && git push --tags
cargo publish