rootstrap / i18n_linter

Rails i18n Linter Gem
https://rootstrap.com
MIT License
44 stars 2 forks source link

Strings search refactor #16

Closed f19ps closed 5 years ago

f19ps commented 5 years ago

The way to find strings was modified to be more solid and to support multi-line strings and other characteristics.

The previous version works with the following syntax:

pry(main)> Ripper.lex("def m(a) nil end")
=> [[[1, 0], :on_kw, "def"],
 [[1, 3], :on_sp, " "],
 [[1, 4], :on_ident, "m"],
 [[1, 5], :on_lparen, "("],
 [[1, 6], :on_ident, "a"],
 [[1, 7], :on_rparen, ")"],
 [[1, 8], :on_sp, " "],
 [[1, 9], :on_kw, "nil"],
 [[1, 12], :on_sp, " "],
 [[1, 13], :on_kw, "end"]]

The new one works in the following way:

Ripper.sexp("def m(a) nil end")
=> [:program, [[:def, [:@ident, "m", [1, 4]], [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil, nil, nil, nil]], [:bodystmt, [[:var_ref, [:@kw, "nil", [1, 9]]]], nil, nil, nil]]]]

As we can see, the second works with a tree that (in a recursive method) could be pruned depending on the context. It allows us to study the context and make decisions based on that.

Now we have 3 types of rules:

1) Positive rules: Rules that must be passed to consider a string. 2) Negative context rules: Rules that cut the file tree based on the context. 3) Negative string rules: Rules that discard a candidate string.

What was uploaded is the new recursive method to find strings.

The tests were commented because the new rules have not been uploaded yet.