Sha256: 4506b60a9e4c91aa903e863dfef978ec4da6b6921acc7023b0c32a142d61302f

Contents?: true

Size: 772 Bytes

Versions: 5

Compression:

Stored size: 772 Bytes

Contents

# frozen_string_literal: true

module SlimLint
  # Searches for control statements with only comments.
  class Linter::CommentControlStatement < Linter
    include LinterRegistry

    RUBOCOP_CONTROL_COMMENT_RE = /^\s*(rubocop|standard):\w+/
    TEMPLATE_DEPENDENCY_CONTROL_COMMENT_RE = /^\s*Template Dependency:/

    on [:slim, :control] do |sexp|
      _, _, code = sexp
      next unless code.last[1][/\A\s*#/]

      comment = code.last[1][/\A\s*#(.*\z)/, 1]

      next if RUBOCOP_CONTROL_COMMENT_RE.match?(comment)
      next if TEMPLATE_DEPENDENCY_CONTROL_COMMENT_RE.match?(comment)

      msg =
        "Slim code comments (`/#{comment}`) are preferred over " \
        "control statement comments (`-##{comment}`)"
      report_lint(sexp, msg)
    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/comment_control_statement.rb
slim_lint_standard-0.0.2.1 lib/slim_lint/linter/comment_control_statement.rb
slim_lint_standard-0.0.2 lib/slim_lint/linter/comment_control_statement.rb
slim_lint_standard-0.0.1 lib/slim_lint/linter/comment_control_statement.rb
slim_lint_standard-0.0.0 lib/slim_lint/linter/comment_control_statement.rb