https://github.com/siraben/ts-lint-example
Minimal linting example with tree-sitter
https://github.com/siraben/ts-lint-example
imp linting rust tree-sitter
Last synced: 9 months ago
JSON representation
Minimal linting example with tree-sitter
- Host: GitHub
- URL: https://github.com/siraben/ts-lint-example
- Owner: siraben
- License: mit
- Created: 2022-02-26T22:21:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-22T16:59:18.000Z (over 4 years ago)
- Last Synced: 2025-06-19T03:41:07.575Z (about 1 year ago)
- Topics: imp, linting, rust, tree-sitter
- Language: JavaScript
- Homepage:
- Size: 54.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Linting example with tree-sitter
Minimal complete example of how to use the tree-sitter bindings to
perform some linting checks for the
[Imp](https://softwarefoundations.cis.upenn.edu/lf-current/Imp.html)
language. See the file `index.js` for more information. It uses a
tree-sitter query to pattern-match over the AST, iterates through the
matches and reports them. Planned checks include:
- [x] redundant assignments
- [x] redundant if statement
- [ ] always false condition
Since Imp has a simple operational semantics, it can be easily proven
that these suggestions preserve program behavior.
Given a file `factorial.imp` with contents
```
z := x;
y := 1;
y := y;
while ~(z = 0) do
y := y * z;
z := z - 1;
x := x;
end;
x := x;
if x = y then x := 1 else x := 1 end
```
Running the following command
```ShellSession
$ node index.js factorial.imp
```
Produces the output
```
Redundant assignments:
[
{ text: 'y := y', row: 2, column: 0 },
{ text: 'x := x', row: 6, column: 2 },
{ text: 'x := x', row: 8, column: 0 }
]
Redundant if statements:
[ { text: 'if x = y then x := 1 else x := 1 end', row: 9, column: 0 } ]
```