Class: LintTrappings::Linter Abstract
- Inherits:
-
Object
- Object
- LintTrappings::Linter
- Defined in:
- lib/lint_trappings/linter.rb
Overview
Base implementation for all lint checks.
Class Attribute Summary collapse
-
.options_struct_class ⇒ Object
Returns the value of attribute options_struct_class.
Class Method Summary collapse
-
.canonical_name ⇒ String
Returns the canonical name for this linter class.
-
.descendants ⇒ Array<Class>
Return all subclasses.
- .description(*args) ⇒ Object
- .option(name, options) ⇒ Object
- .options ⇒ Object
Instance Method Summary collapse
-
#canonical_name ⇒ String
Returns the canonical name of this linter’s class.
-
#initialize(config) ⇒ Linter
constructor
Initializes a linter with the specified configuration.
-
#run(document) ⇒ Object
Runs the linter against the given Slim document.
Constructor Details
#initialize(config) ⇒ Linter
Initializes a linter with the specified configuration.
89 90 91 92 93 94 |
# File 'lib/lint_trappings/linter.rb', line 89 def initialize(config) @orig_hash_config = @config = config @config = convert_config_hash_to_struct(@config) @lints = [] end |
Class Attribute Details
.options_struct_class ⇒ Object
Returns the value of attribute options_struct_class.
83 84 85 |
# File 'lib/lint_trappings/linter.rb', line 83 def @options_struct_class end |
Class Method Details
.canonical_name ⇒ String
Returns the canonical name for this linter class.
The canonical name is used as the key for configuring the linter in the configuration file, or when referring to it from the command line.
This uses the “Linter” module as an indicator of when to start removing unnecessary module prefixes.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lint_trappings/linter.rb', line 38 def canonical_name @canonical_name ||= begin full_name = name.to_s.split('::') if linter_class_index = full_name.index('Linter') # Otherwise, the name follows the `Linter` module linter_class_index += 1 else # If not found, include the full name linter_class_index = 0 end full_name[linter_class_index..-1].join('::') end end |
.descendants ⇒ Array<Class>
Return all subclasses.
13 14 15 |
# File 'lib/lint_trappings/linter.rb', line 13 def descendants ObjectSpace.each_object(Class).select { |klass| klass < self } end |
.description(*args) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/lint_trappings/linter.rb', line 55 def description(*args) if args.any? @description = args.first else @description end end |
.option(name, options) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lint_trappings/linter.rb', line 63 def option(name, ) = .dup @options_spec ||= {} opt = @options_spec[name] = {} %i[type default description].each do |option_sym| opt[option_sym] = .delete(option_sym) if [option_sym] end if .keys.any? raise InvalidOptionSpecificationError, "Unknown key `#{.keys.first}` for `#{name}` option " \ "specification on linter #{self}" end end |
.options ⇒ Object
79 80 81 |
# File 'lib/lint_trappings/linter.rb', line 79 def @options_spec || {} end |
Instance Method Details
#canonical_name ⇒ String
Returns the canonical name of this linter’s class.
111 112 113 |
# File 'lib/lint_trappings/linter.rb', line 111 def canonical_name self.class.canonical_name end |
#run(document) ⇒ Object
Runs the linter against the given Slim document.
99 100 101 102 103 104 |
# File 'lib/lint_trappings/linter.rb', line 99 def run(document) @document = document @lints = [] scan @lints end |