Closed f19ps closed 5 years ago
This is a NegativeContextRule that cuts the file tree when a definition of a class name appears.
For example, if we have the following code:
class Employee < ApplicationRecord belongs_to :manager, class_name: "Employee" end
Ripper will throw:
[:program, [[:class, [:const_ref, [:@const, "Employee", [1, 6]]], [:var_ref, [:@const, "ApplicationRecord", [1, 17]]], [:bodystmt, [[:command, [:@ident, "belongs_to", [2, 2]], [:args_add_block, [[:symbol_literal, [:symbol, [:@ident, "manager", [2, 14]]]], [:bare_assoc_hash, [[:assoc_new, [:@label, "class_name:", [2, 23]], [:string_literal, [:string_content, [:@tstring_content, "Employee", [2, 36]]]]]]]], false]]], nil, nil, nil]]]]
So, when the branch [[:assoc_new, [:@label, "class_name:", [2, 23]], [:string_literal, [:string_content, [:@tstring_content, "Employee", [2, 36]]]]]] is checked it will be cut to prevent that "Employee" will be detected.
[[:assoc_new, [:@label, "class_name:", [2, 23]], [:string_literal, [:string_content, [:@tstring_content, "Employee", [2, 36]]]]]]
"Employee"
New version of class_name rule
This is a NegativeContextRule that cuts the file tree when a definition of a class name appears.
For example, if we have the following code:
Ripper will throw:
So, when the branch
[[:assoc_new, [:@label, "class_name:", [2, 23]], [:string_literal, [:string_content, [:@tstring_content, "Employee", [2, 36]]]]]]
is checked it will be cut to prevent that"Employee"
will be detected.