| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | "use strict";/* * eslint-plugin-sonarjs * Copyright (C) 2018-2021 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. */// https://sonarsource.github.io/rspec/#/rspec/S1862const nodes_1 = require("../utils/nodes");const equivalence_1 = require("../utils/equivalence");const locations_1 = require("../utils/locations");const docs_url_1 = require("../utils/docs-url");const message = 'This branch duplicates the one on line {{line}}';const rule = {    meta: {        messages: {            duplicatedBranch: message,            sonarRuntime: '{{sonarRuntimeData}}',        },        type: 'problem',        docs: {            description: 'Related "if/else if" statements should not have the same condition',            recommended: 'error',            url: (0, docs_url_1.default)(__filename),        },        schema: [            {                // internal parameter                enum: ['sonar-runtime'],            },        ],    },    create(context) {        return {            IfStatement(node) {                const ifStmt = node;                const condition = ifStmt.test;                let statement = ifStmt.alternate;                while (statement) {                    if ((0, nodes_1.isIfStatement)(statement)) {                        if ((0, equivalence_1.areEquivalent)(condition, statement.test, context.getSourceCode())) {                            const line = ifStmt.loc && ifStmt.loc.start.line;                            if (line && condition.loc) {                                (0, locations_1.report)(context, {                                    messageId: 'duplicatedBranch',                                    data: {                                        line,                                    },                                    node: statement.test,                                }, [(0, locations_1.issueLocation)(condition.loc, condition.loc, 'Original')], message);                            }                        }                        statement = statement.alternate;                    }                    else {                        break;                    }                }            },        };    },};module.exports = rule;//# sourceMappingURL=no-identical-conditions.js.map
 |