etiennebacher / flint

Find and Fix Lints in R Code
https://flint.etiennebacher.com
Other
42 stars 1 forks source link

Ignore semicolons in comments #41

Open etiennebacher opened 2 months ago

etiennebacher commented 2 months ago
flint::lint_text("# foobar;")
#> Original code: # foobar; 
#> Suggestion: Trailing semicolons are not needed. 
#> Rule ID: semicolon_1
etiennebacher commented 2 months ago

Don't know why not: kind: comment doesn't work here

etiennebacher commented 1 month ago

Seems like a bigger issue with negating a comment. In the last case, this should return 0 node:

library(astgrepr)

no_comment <- "foo"

# CORRECT
no_comment |> 
  tree_new() |> 
  tree_root() |> 
  node_find(ast_rule(kind = "comment"))
#> <List of 1 rule>
#> |--rule_1: 0 node

# CORRECT
no_comment |> 
  tree_new() |> 
  tree_root() |> 
  node_find(ast_rule(not = ast_rule(kind = "comment")))
#> <List of 1 rule>
#> |--rule_1: 1 node

is_comment <- "# foo"

# CORRECT
is_comment |> 
  tree_new() |> 
  tree_root() |> 
  node_find(ast_rule(kind = "comment"))
#> <List of 1 rule>
#> |--rule_1: 1 node

# WRONG
is_comment |> 
  tree_new() |> 
  tree_root() |> 
  node_find(ast_rule(not = ast_rule(kind = "comment")))
#> <List of 1 rule>
#> |--rule_1: 1 node