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

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] {` ' <<
        '(are you missing a trailing semi-colon?)'
      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

Improve message for property format linter
Improve message for property format linter

Changes the lint error description for the property format linter to
suggest that the user is missing a semi-colon, as that usually is the
reason they are seeing the lint, and the more general language of the
error can be confusing the read at times.

Change-Id: I58dcb2845ba206e42de444381ab77d8bd1503614
Reviewed-on: https://gerrit.causes.com/17772
Tested-by: Shane da Silva <6f6e68d1df92f30cb4b3ce35260ddf94a402f33d@causes.com>
Reviewed-by: Joe Lencioni <1dd72cf724deaab5db236f616560fc7067b734e1@causes.com>
