module SCSSLint
  class Linter::DeclaredName < Linter
    include LinterRegistry

    def visit_function(node)
      check(node)
      yield # Continue into content block of this function definition
    end

    def visit_mixindef(node)
      check(node)
      yield # Continue into content block of this mixin definition
    end

    def visit_variable(node)
      check(node)
      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)
    end
  end
end

module SCSSLint
  class Linter::DeclaredName < Linter
    include LinterRegistry

    def visit_function(node)
      check(node, 'function')
      yield # Continue into content block of this function definition
    end

    def visit_mixindef(node)
      check(node, 'mixin')
      yield # Continue into content block of this mixin definition
    end

    def visit_variable(node)
      check(node, 'variable')
      yield # Continue into expression tree for this variable definition
    end

  private

    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

Make DeclaredName lints more specific
Make DeclaredName lints more specific

Change the descriptions of lints reported by `DeclaredName` to be
relevant to the particular context (e.g. whether the incorrectly named
thing was a function, mixin, or variable).

Change-Id: I2191c1a3bb4f512b7d28e377eaedce4c0ec0a849
Reviewed-on: https://gerrit.causes.com/28832
Tested-by: jenkins <d95b56ce41a2e1ac4cecdd398defd7414407cc08@causes.com>
Reviewed-by: Greg Hurrell <79e2475f81a6317276bf7cbb3958b20d289b78df@causes.com>
