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-17.6.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-17.5.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-17.4.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-17.3.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-17.2.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-17.1.1 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-17.1.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-17.0.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.29.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.28.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.27.1 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.27.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.26.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.25.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.24.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.23.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.22.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.21.0 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.20.1 node_modules/eslint/lib/rules/no-self-compare.js
govuk_publishing_components-16.20.0 node_modules/eslint/lib/rules/no-self-compare.js