Class: Collie::Linter::Rules::UnusedToken
- Defined in:
- lib/collie/linter/rules/unused_token.rb
Overview
Detects tokens that are declared but never used
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#autocorrectable?, #initialize
Constructor Details
This class inherits a constructor from Collie::Linter::Base
Instance Method Details
#check(ast, context = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/collie/linter/rules/unused_token.rb', line 15 def check(ast, context = {}) symbol_table = context[:symbol_table] || build_symbol_table(ast) Analyzer::SymbolResolver.resolve(ast, symbol_table) # Track token usage in normal rules ast.rules.each do |rule| rule.alternatives.each do |alt| alt.symbols.each { |symbol| mark_token_usage(symbol_table, symbol) } mark_precedence_usage(symbol_table, alt) end end # Track token usage in parameterized rules (%rule) ast.declarations.each do |decl| next unless decl.is_a?(AST::ParameterizedRule) || decl.is_a?(AST::InlineRule) decl.alternatives.each do |alt| alt.symbols.each { |symbol| mark_token_usage(symbol_table, symbol) } mark_precedence_usage(symbol_table, alt) end end # Find unused tokens symbol_table.unused_tokens.each do |token_name| token_info = symbol_table.tokens[token_name] add_offense_for_declaration(ast, token_name, token_info[:location]) end @offenses end |