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::CommentSyntax, ERBLint::Linters::DeprecatedClasses, ERBLint::Linters::ErbSafety, ERBLint::Linters::ExtraNewline, ERBLint::Linters::FinalNewline, ERBLint::Linters::HardCodedString, ERBLint::Linters::NoJavascriptTagHelper, ERBLint::Linters::NoUnusedDisable, ERBLint::Linters::ParserErrors, ERBLint::Linters::PartialInstanceVariable, ERBLint::Linters::RequireInputAutocomplete, ERBLint::Linters::RequireScriptNonce, 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#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, severity = 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
- #run_and_update_offense_status(processed_source, enable_inline_configs = true) ⇒ Object
Constructor Details
#initialize(file_loader, config) ⇒ Linter
Must be implemented by the concrete inheriting class.
38 39 40 41 42 43 44 |
# File 'lib/erb_lint/linter.rb', line 38 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.
10 11 12 |
# File 'lib/erb_lint/linter.rb', line 10 def config_schema @config_schema end |
.simple_name ⇒ Object
Returns the value of attribute simple_name.
9 10 11 |
# File 'lib/erb_lint/linter.rb', line 9 def simple_name @simple_name end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
35 36 37 |
# File 'lib/erb_lint/linter.rb', line 35 def config @config end |
#offenses ⇒ Object (readonly)
Returns the value of attribute offenses.
35 36 37 |
# File 'lib/erb_lint/linter.rb', line 35 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”
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/erb_lint/linter.rb', line 18 def inherited(linter) super 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
30 31 32 |
# File 'lib/erb_lint/linter.rb', line 30 def support_autocorrect? method_defined?(:autocorrect) end |
Instance Method Details
#add_offense(source_range, message, context = nil, severity = nil) ⇒ Object
65 66 67 |
# File 'lib/erb_lint/linter.rb', line 65 def add_offense(source_range, , context = nil, severity = nil) @offenses << Offense.new(self, source_range, , context, severity) end |
#clear_offenses ⇒ Object
69 70 71 |
# File 'lib/erb_lint/linter.rb', line 69 def clear_offenses @offenses = [] end |
#enabled? ⇒ Boolean
46 47 48 |
# File 'lib/erb_lint/linter.rb', line 46 def enabled? @config.enabled? end |
#excludes_file?(filename) ⇒ Boolean
50 51 52 |
# File 'lib/erb_lint/linter.rb', line 50 def excludes_file?(filename) @config.excludes_file?(filename, @file_loader.base_path) end |
#run(_processed_source) ⇒ Object
54 55 56 |
# File 'lib/erb_lint/linter.rb', line 54 def run(_processed_source) raise NotImplementedError, "must implement ##{__method__}" end |
#run_and_update_offense_status(processed_source, enable_inline_configs = true) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/erb_lint/linter.rb', line 58 def run_and_update_offense_status(processed_source, enable_inline_configs = true) run(processed_source) if @offenses.any? && enable_inline_configs update_offense_status(processed_source) end end |