{"size": 1135, "ext": "js", "max_stars_repo_path": "lib/linters/color_variables.js", "max_stars_repo_name": "mikermcneil/lesshint", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/linters/color_variables.js", "max_issues_repo_name": "mikermcneil/lesshint", "max_issues_repo_issues_event_min_datetime": "2020-07-07T20:10:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-07T20:10:16.000Z", "max_forks_repo_path": "lib/linters/color_variables.js", "max_forks_repo_name": "mikermcneil/lesshint", "max_forks_repo_forks_event_min_datetime": "2019-06-22T18:36:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-22T18:36:47.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 25.7954545455, "max_line_length": 64, "alphanum_fraction": 0.504845815}
'use strict';

const util = require('util');
const parseValue = require('../utils/parse-value');
const isVariable = require('../utils/is-variable');

module.exports = {
    name: 'colorVariables',
    nodeTypes: ['decl'],
    message: '%s should be replaced with an existing variable.',

    lint: function colorVariablesLinter (config, node) {
        const ast = parseValue(node.value);
        const results = [];

        ast.first.walk((child) => {
            // Only evaluate hex colors
            if (child.type !== 'word' || !child.isColor) {
                return;
            }

            // If it's a variable assignment, allow hex colors
            if (isVariable(node.prop)) {
                return;
            }

            const color = child.value;
            const position = node.positionBy({
                word: color
            });

            results.push({
                column: position.column,
                line: position.line,
                message: util.format(this.message, color)
            });
        });

        if (results.length) {
            return results;
        }
    }
};
