Sha256: c81dc4e096c0061ae3644404414a9e8d7ed838f2a3c56a43712e51cc1f515f2c

Contents?: true

Size: 1.18 KB

Versions: 45

Compression:

Stored size: 1.18 KB

Contents

/**
 * @fileoverview Rule to flag comparison where left part is the same as the right
 * part.
 * @author Ilya Volodin
 */

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
    meta: {
        docs: {
            description: "disallow comparisons where both sides are exactly the same",
            category: "Best Practices",
            recommended: false
        },

        schema: []
    },

    create: function(context) {

        return {

            BinaryExpression: function(node) {
                var operators = ["===", "==", "!==", "!=", ">", "<", ">=", "<="];

                if (operators.indexOf(node.operator) > -1 &&
                    (node.left.type === "Identifier" && node.right.type === "Identifier" && node.left.name === node.right.name ||
                    node.left.type === "Literal" && node.right.type === "Literal" && node.left.value === node.right.value)) {
                    context.report(node, "Comparing to itself is potentially pointless.");
                }
            }
        };

    }
};

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
govuk_publishing_components-16.19.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.18.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.17.0 node_modules/eslint/lib/rules/no-self-compare.js
guard-sass-lint-0.1.2 node_modules/eslint/lib/rules/no-self-compare.js
guard-sass-lint-0.1.1 node_modules/eslint/lib/rules/no-self-compare.js