Class: ERBLint::Linter
- Inherits:
-
Object
- Object
- ERBLint::Linter
- Defined in:
- lib/erb_lint/linter.rb
Overview
Defines common functionality available to all linters.
Direct Known Subclasses
ERBLint::Linters::AllowedScriptType, ERBLint::Linters::ClosingErbTagIndent, ERBLint::Linters::DeprecatedClasses, ERBLint::Linters::ErbSafety, ERBLint::Linters::ExtraNewline, ERBLint::Linters::FinalNewline, ERBLint::Linters::HardCodedString, ERBLint::Linters::NoJavascriptTagHelper, ERBLint::Linters::ParserErrors, ERBLint::Linters::RightTrim, ERBLint::Linters::Rubocop, ERBLint::Linters::SelfClosingTag, ERBLint::Linters::SpaceAroundErbTag, ERBLint::Linters::SpaceInHtmlTag, ERBLint::Linters::SpaceIndentation, ERBLint::Linters::TrailingWhitespace
Class Attribute Summary collapse
-
.config_schema ⇒ Object
Returns the value of attribute config_schema.
-
.simple_name ⇒ Object
Returns the value of attribute simple_name.
Instance Attribute Summary collapse
-
#offenses ⇒ Object
readonly
Returns the value of attribute offenses.
Class Method Summary collapse
-
.inherited(linter) ⇒ Object
When defining a Linter class, define its simple name as well.
- .support_autocorrect? ⇒ Boolean
Instance Method Summary collapse
- #add_offense(source_range, message, context = nil) ⇒ Object
- #clear_offenses ⇒ Object
- #enabled? ⇒ Boolean
- #excludes_file?(filename) ⇒ Boolean
-
#initialize(file_loader, config) ⇒ Linter
constructor
Must be implemented by the concrete inheriting class.
- #run(_processed_source) ⇒ Object
Constructor Details
#initialize(file_loader, config) ⇒ Linter
Must be implemented by the concrete inheriting class.
35 36 37 38 39 40 41 |
# File 'lib/erb_lint/linter.rb', line 35 def initialize(file_loader, config) @file_loader = file_loader @config = config raise ArgumentError, "expect `config` to be #{self.class.config_schema} instance, "\ "not #{config.class}" unless config.is_a?(self.class.config_schema) @offenses = [] end |
Class Attribute Details
.config_schema ⇒ Object
Returns the value of attribute config_schema.
8 9 10 |
# File 'lib/erb_lint/linter.rb', line 8 def config_schema @config_schema end |
.simple_name ⇒ Object
Returns the value of attribute simple_name.
7 8 9 |
# File 'lib/erb_lint/linter.rb', line 7 def simple_name @simple_name end |
Instance Attribute Details
#offenses ⇒ Object (readonly)
Returns the value of attribute offenses.
32 33 34 |
# File 'lib/erb_lint/linter.rb', line 32 def offenses @offenses end |
Class Method Details
.inherited(linter) ⇒ Object
When defining a Linter class, define its simple name as well. This assumes that the module hierarchy of every linter starts with ‘ERBLint::Linters::`, and removes this part of the class name.
‘ERBLint::Linters::Foo.simple_name` #=> “Foo” `ERBLint::Linters::Compass::Bar.simple_name` #=> “Compass::Bar”
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/erb_lint/linter.rb', line 16 def inherited(linter) linter.simple_name = if linter.name.start_with?('ERBLint::Linters::') name_parts = linter.name.split('::') name_parts[2..-1].join('::') else linter.name end linter.config_schema = LinterConfig end |
.support_autocorrect? ⇒ Boolean
27 28 29 |
# File 'lib/erb_lint/linter.rb', line 27 def support_autocorrect? method_defined?(:autocorrect) end |
Instance Method Details
#add_offense(source_range, message, context = nil) ⇒ Object
55 56 57 |
# File 'lib/erb_lint/linter.rb', line 55 def add_offense(source_range, , context = nil) @offenses << Offense.new(self, source_range, , context) end |
#clear_offenses ⇒ Object
59 60 61 |
# File 'lib/erb_lint/linter.rb', line 59 def clear_offenses @offenses = [] end |
#enabled? ⇒ Boolean
43 44 45 |
# File 'lib/erb_lint/linter.rb', line 43 def enabled? @config.enabled? end |
#excludes_file?(filename) ⇒ Boolean
47 48 49 |
# File 'lib/erb_lint/linter.rb', line 47 def excludes_file?(filename) @config.excludes_file?(filename) end |
#run(_processed_source) ⇒ Object
51 52 53 |
# File 'lib/erb_lint/linter.rb', line 51 def run(_processed_source) raise NotImplementedError, "must implement ##{__method__}" end |