Sha256: 64b290a8e716e392f14e03763ac999f4df5ed5d4611e70ab5c594093b335de08

Contents?: true

Size: 751 Bytes

Versions: 8

Compression:

Stored size: 751 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

    MESSAGE = 'Please add a space before and after the `=`'

    on [:html, :tag, anything, [],
         [:slim, :output, anything, capture(:ruby, anything)]] do |sexp|
      # Fetch original Slim code that contains an element with a control statement.
      line = document.source_lines[sexp.line - 1]

      # Remove any Ruby code, because our regexp below must not match inside Ruby.
      ruby = captures[:ruby]
      line = line.sub(ruby, 'x')

      next if line =~ /[^ ] ==?<?>? [^ ]/

      report_lint(sexp, MESSAGE)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
slim_lint-0.31.1 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint-0.31.0 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint-0.30.0 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint-0.29.0 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint-0.28.0 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint-0.27.0 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint-0.26.0 lib/slim_lint/linter/control_statement_spacing.rb
slim_lint-0.24.0 lib/slim_lint/linter/control_statement_spacing.rb