Sha256: 2997e5f6515e7ea4ed954969a00942cffe17e0239ebbf8140e175e0ee1a941c7

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

require 'sass'

module SCSSLint
  class Linter::PropertyFormatLinter < Linter
    include LinterRegistry

    class << self
      def run(engine)
        lints = []
        engine.tree.each do |node|
          if node.is_a?(Sass::Tree::PropNode)
            lints << check_property_format(node, engine.lines[node.line - 1]) if node.line
          end
        end
        lints.compact
      end

      def description
        'Property declarations should always be on one line of the form ' <<
        '`name: value;` or `name: [value] {`'
      end

    private

      VALUE_RE = %r{(\S+\s)*\S+} # eg. "10px", "10px normal"
      PROPERTY_RE = %r{
        ^\s*[\w-]+:\s           # property name, colon, one space
          (                     # followed by
          #{VALUE_RE};          # property and terminating semi-colon eg. a b c;
          |                     # or
          ((#{VALUE_RE}\s)?\{)  # nested property, optional value, trailing curly
          )
      }x

      def check_property_format(prop_node, line)
        return create_lint(prop_node) unless line =~ PROPERTY_RE
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scss-lint-0.5.2 lib/scss_lint/linter/property_format_linter.rb
scss-lint-0.5.1 lib/scss_lint/linter/property_format_linter.rb
scss-lint-0.5 lib/scss_lint/linter/property_format_linter.rb
scss-lint-0.4 lib/scss_lint/linter/property_format_linter.rb
scss-lint-0.3 lib/scss_lint/linter/property_format_linter.rb
scss-lint-0.2 lib/scss_lint/linter/property_format_linter.rb