Class: SlimLint::Linter::DynamicOutputSpacing
- Inherits:
-
SlimLint::Linter
- Object
- SlimLint::Linter
- SlimLint::Linter::DynamicOutputSpacing
- Includes:
- SlimLint::LinterRegistry
- Defined in:
- lib/slim_lint/linter/dynamic_output_spacing.rb
Overview
Checks for missing or superfluous spacing before and after dynamic tag output indicators.
Constant Summary collapse
- PATTERN =
"==?['<>]*"
Instance Attribute Summary
Attributes inherited from SlimLint::Linter
Attributes included from SexpVisitor::DSL
Instance Method Summary collapse
Methods included from SlimLint::LinterRegistry
extract_linters_from, included
Methods inherited from SlimLint::Linter
Methods included from SexpVisitor::DSL
#anything, #capture, #on, #on_start
Methods included from SexpVisitor
#captures, #on_start, #patterns, #traverse, #traverse_children, #trigger_pattern_callbacks
Constructor Details
This class inherits a constructor from SlimLint::Linter
Instance Method Details
#after_config ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/slim_lint/linter/dynamic_output_spacing.rb', line 64 def after_config @after_config ||= case config["space_after"] when "never", false, nil [/^ *#{PATTERN}[^ ]/, "remove spaces after"] when "always", "single", true [/^ *#{PATTERN} [^ ]/, "use one space after"] when "ignore", "any" [//, ""] else raise ArgumentError, "Unknown value for `space_after`; please use 'never', 'always', or 'ignore'" end end |
#before_config ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/slim_lint/linter/dynamic_output_spacing.rb', line 51 def before_config @before_config ||= case config["space_before"] when "never", false, nil [/^#{PATTERN}/, "remove spaces before"] when "always", "single", true [/^ #{PATTERN}/, "use one space before"] when "ignore", "any" [//, ""] else raise ArgumentError, "Unknown value for `space_before`; please use 'never', 'always', or 'ignore'" end end |
#report(expr, *results) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/slim_lint/linter/dynamic_output_spacing.rb', line 33 def report(expr, *results) _, before_action = before_config _, after_action = after_config case results when [false, true] report_lint(expr, "Please #{before_action} the equals sign") when [true, false] report_lint(expr, "Please #{after_action} the equals sign") when [false, false] if before_action[0] == after_action[0] report_lint(expr, "Please #{before_action} and after the equals sign") else report_lint(expr, "Please #{before_action} and #{after_action} the equals sign") end end end |