lib/scss_lint/linter/declared_name.rb in scss-lint-0.9.0 vs lib/scss_lint/linter/declared_name.rb in scss-lint-0.10.0
- old
+ new
@@ -1,36 +1,31 @@
module SCSSLint
class Linter::DeclaredName < Linter
include LinterRegistry
def visit_function(node)
- check(node)
+ check(node, 'function')
yield # Continue into content block of this function definition
end
def visit_mixindef(node)
- check(node)
+ check(node, 'mixin')
yield # Continue into content block of this mixin definition
end
- def visit_rule(node)
- add_lint(node) if selector_has_bad_placeholder?(node.rule)
- yield # Continue linting into content block of this rule definition
- end
-
def visit_variable(node)
- check(node)
+ check(node, 'variable')
yield # Continue into expression tree for this variable definition
end
- def description
- 'Names of variables, functions, mixins, and placeholders should be ' <<
- 'lowercase and use hyphens instead of underscores.'
- end
-
private
- def check(node)
- add_lint(node) if node_has_bad_name?(node)
+ def check(node, node_type)
+ if node_has_bad_name?(node)
+ fixed_name = node.name.downcase.gsub(/_/, '-')
+
+ add_lint(node, "Name of #{node_type} `#{node.name}` should " <<
+ "be written in lowercase as `#{fixed_name}`")
+ end
end
end
end