Class: Collie::Linter::Rules::MissingStartSymbol
- Defined in:
- lib/collie/linter/rules/missing_start_symbol.rb
Overview
Detects missing %start declaration when it’s ambiguous
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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/collie/linter/rules/missing_start_symbol.rb', line 13 def check(ast, _context = {}) has_start = ast.declarations.any? { |decl| decl.is_a?(AST::StartDeclaration) } # If %start is declared, no problem return @offenses if has_start # If no rules defined, it's ambiguous if ast.rules.empty? # Create a pseudo-location since we don't have a specific node location = AST::Location.new(file: "grammar", line: 1, column: 1) offense = Offense.new( rule: self.class, location: location, message: "No %start declaration and no rules defined" ) @offenses << offense end @offenses end |