Skip to content

siraben/ts-lint-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linting example with tree-sitter

Minimal complete example of how to use the tree-sitter bindings to perform some linting checks for the Imp 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:

  • redundant assignments
  • 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

$ 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 } ]

About

Minimal linting example with tree-sitter

Topics

Resources

License

Stars

Watchers

Forks