Sha256: 4f40bd0bf1d97bdea27c616d78f80223e6e65ff9e2495073d5e76dd75a7540e5

Contents?: true

Size: 1.48 KB

Versions: 19

Compression:

Stored size: 1.48 KB

Contents

module SCSSLint
  # Checks for misspelled properties.
  class Linter::PropertySpelling < Linter
    include LinterRegistry

    KNOWN_PROPERTIES = File.open(File.join(SCSS_LINT_DATA, 'properties.txt'))
                           .read
                           .split
                           .to_set

    def visit_root(_node)
      @extra_properties = config['extra_properties'].to_set
      yield # Continue linting children
    end

    def visit_prop(node)
      # Ignore properties with interpolation
      return if node.name.count > 1 || !node.name.first.is_a?(String)

      nested_properties = node.children.select { |child| child.is_a?(Sass::Tree::PropNode) }
      if nested_properties.any?
        # Treat nested properties specially, as they are a concatenation of the
        # parent with child property
        nested_properties.each do |nested_prop|
          check_property(nested_prop, node.name.join)
        end
      else
        check_property(node)
      end
    end

  private

    def check_property(node, prefix = nil) # rubocop:disable CyclomaticComplexity
      # Ignore properties with interpolation
      return if node.name.count > 1 || !node.name.first.is_a?(String)

      name = prefix ? "#{prefix}-" : ''
      name += node.name.join

      # Ignore vendor-prefixed properties
      return if name.start_with?('-')
      return if KNOWN_PROPERTIES.include?(name) ||
        @extra_properties.include?(name)

      add_lint(node, "Unknown property #{name}")
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
scss_lint-0.42.2 lib/scss_lint/linter/property_spelling.rb
scss_lint-0.42.1 lib/scss_lint/linter/property_spelling.rb
scss_lint-0.42.0 lib/scss_lint/linter/property_spelling.rb
scss_lint-0.41.0 lib/scss_lint/linter/property_spelling.rb
scss_lint-0.40.1 lib/scss_lint/linter/property_spelling.rb
scss_lint-0.40.0 lib/scss_lint/linter/property_spelling.rb
scss_lint-0.39.0 lib/scss_lint/linter/property_spelling.rb
scss_lint-0.38.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.38.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-bliss-1.0.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.37.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.36.1 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.36.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.35.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.34.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.33.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.32.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.31.0 lib/scss_lint/linter/property_spelling.rb
scss-lint-0.30.0 lib/scss_lint/linter/property_spelling.rb