Class: Uniword::Lint::Rule
- Inherits:
-
Object
- Object
- Uniword::Lint::Rule
- Defined in:
- lib/uniword/lint/rule.rb
Overview
Abstract base class for a single lint rule. Subclasses implement
#check (yields findings) and declare name, severity.
Open/closed: new rule type = new subclass + (optionally) a YAML schema extension. Engine unchanged.
Direct Known Subclasses
BuiltinRules::BannedWords, BuiltinRules::MaxParagraphLength, BuiltinRules::RequireBody, BuiltinRules::RequiredStyle
Constant Summary collapse
- TYPES =
Registered rule subclasses by type name. Constant on
Ruleitself (not subclasses) soregistercalls always reach the same hash.Hash.new(rather than{}) avoids the Style/MutableConstant autocorrect that would.freezeit and breakregister. Hash.new
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
Class Method Summary collapse
-
.register(name, klass) ⇒ void
Register a subclass under a type name for YAML ruleset lookup.
-
.type(name) ⇒ Class<Rule>?
Lookup a registered rule subclass by type name.
-
.types ⇒ Hash{Symbol => Class<Rule>}
All registered rule types.
Instance Method Summary collapse
-
#check(document) {|finding| ... } ⇒ void
Walk the document and yield each finding.
-
#finding(message:, path: nil) ⇒ Hash
Build a finding hash.
-
#initialize(name:, severity: :warning, **options) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(name:, severity: :warning, **options) ⇒ Rule
Returns a new instance of Rule.
23 24 25 26 27 |
# File 'lib/uniword/lint/rule.rb', line 23 def initialize(name:, severity: :warning, **) @name = name @severity = severity @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/uniword/lint/rule.rb', line 18 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/uniword/lint/rule.rb', line 18 def @options end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
18 19 20 |
# File 'lib/uniword/lint/rule.rb', line 18 def severity @severity end |
Class Method Details
.register(name, klass) ⇒ void
This method returns an undefined value.
Register a subclass under a type name for YAML ruleset
lookup. Always writes to Rule::TYPES regardless of the
calling subclass.
56 57 58 |
# File 'lib/uniword/lint/rule.rb', line 56 def register(name, klass) Rule::TYPES[name] = klass end |
Instance Method Details
#check(document) {|finding| ... } ⇒ void
This method returns an undefined value.
Walk the document and yield each finding.
34 35 36 |
# File 'lib/uniword/lint/rule.rb', line 34 def check(document) raise NotImplementedError end |
#finding(message:, path: nil) ⇒ Hash
Build a finding hash.
44 45 46 |
# File 'lib/uniword/lint/rule.rb', line 44 def finding(message:, path: nil) { rule: name, severity: severity, message: , path: path } end |