Sha256: d6848582c67505b9d5493f8868c4f0f548a9f3b3771aca68b526554575737f5d

Contents?: true

Size: 956 Bytes

Versions: 5

Compression:

Stored size: 956 Bytes

Contents

# frozen_string_literal: true

module SlimLint
  # Checks for missing or superfluous spacing before and after control statements.
  class Linter::ControlStatementSpacing < Linter
    include LinterRegistry

    on [:slim, :control] do |sexp|
      expr = sexp.last[0]
      expr_line, expr_col = sexp.start
      line = document.source_lines[expr_line - 1][(expr_col - 1)..]
      after_pattern, after_action = after_config

      unless line.match?(after_pattern)
        report_lint(expr, "Please #{after_action} the dash")
      end
    end

    def after_config
      @after_config ||= case config["space_after"]
      when "never", false, nil
        [/^ *-#?[^# ]/, "remove spaces after"]
      when "always", "single", true
        [/^ *-#? [^ ]/, "use one space after"]
      when "ignore", "any"
        [//, ""]
      else
        raise ArgumentError, "Unknown value for `space_after`; please use 'never' or 'always'"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slim_lint_standard-0.0.2.2 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint_standard-0.0.2.1 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint_standard-0.0.2 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint_standard-0.0.1 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint_standard-0.0.0 lib/slim_lint/linter/control_statement_spacing.rb