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::DeprecatedClasses, ERBLint::Linters::ErbSafety, ERBLint::Linters::FinalNewline, ERBLint::Linters::Rubocop
Class Attribute Summary collapse
-
.config_schema ⇒ Object
Returns the value of attribute config_schema.
-
.simple_name ⇒ Object
Returns the value of attribute simple_name.
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
- #enabled? ⇒ Boolean
- #excludes_file?(filename) ⇒ Boolean
-
#initialize(file_loader, config) ⇒ Linter
constructor
Must be implemented by the concrete inheriting class.
- #offenses(_processed_source) ⇒ Object
Constructor Details
#initialize(file_loader, config) ⇒ Linter
Must be implemented by the concrete inheriting class.
33 34 35 36 37 38 |
# File 'lib/erb_lint/linter.rb', line 33 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) 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 |
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
#enabled? ⇒ Boolean
40 41 42 |
# File 'lib/erb_lint/linter.rb', line 40 def enabled? @config.enabled? end |
#excludes_file?(filename) ⇒ Boolean
44 45 46 |
# File 'lib/erb_lint/linter.rb', line 44 def excludes_file?(filename) @config.excludes_file?(filename) end |
#offenses(_processed_source) ⇒ Object
48 49 50 |
# File 'lib/erb_lint/linter.rb', line 48 def offenses(_processed_source) raise NotImplementedError, "must implement ##{__method__}" end |