Sha256: 46ebda4fc6e00448d62e42d256a413683d0d52213c206cc032fbc62937eb8e8c

Contents?: true

Size: 1002 Bytes

Versions: 12

Compression:

Stored size: 1002 Bytes

Contents

module SCSSLint
  # Checks for uses of renderable comments (/* ... */)
  class Linter::Comment < Linter
    include LinterRegistry

    def visit_comment(node)
      add_lint(node, message) unless valid_comment?(node)
    end

  private

    def valid_comment?(node)
      allowed_type =
        if config.fetch('style', 'silent') == 'silent'
          node.invisible?
        else
          !node.invisible?
        end
      return true if allowed_type

      # Otherwise check if comment contains content that excludes it (i.e. a
      # copyright notice for loud comments)
      allowed?(node)
    end

    # @param node [CommentNode]
    # @return [Boolean]
    def allowed?(node)
      return false unless config['allowed']
      re = Regexp.new(config['allowed'])

      node.value.join.match(re)
    end

    def message
      if config.fetch('style', 'silent') == 'silent'
        'Use `//` comments everywhere'
      else
        'Use `/* */` comments everywhere'
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
scss_lint-0.60.0 lib/scss_lint/linter/comment.rb
scss_lint-0.59.0 lib/scss_lint/linter/comment.rb
scss_lint-0.58.0 lib/scss_lint/linter/comment.rb
scss_lint-0.57.1 lib/scss_lint/linter/comment.rb
scss_lint-0.57.0 lib/scss_lint/linter/comment.rb
scss_lint-0.56.0 lib/scss_lint/linter/comment.rb
scss_lint-0.55.0 lib/scss_lint/linter/comment.rb
scss_lint-0.54.0 lib/scss_lint/linter/comment.rb
scss_lint-0.53.0 lib/scss_lint/linter/comment.rb
scss_lint-0.52.0 lib/scss_lint/linter/comment.rb
scss_lint-0.51.0 lib/scss_lint/linter/comment.rb
scss_lint-0.50.3 lib/scss_lint/linter/comment.rb