Sha256: 10580d016b3da149e7ff92a91962aeb0b814c2604704af5c2cbe2c263ca861fc

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 KB

Contents

/**
 * @fileoverview Rule to enforce default clauses in switch statements to be last
 * @author Milos Djermanovic
 */

"use strict";

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

/** @type {import('../shared/types').Rule} */
module.exports = {
    meta: {
        type: "suggestion",

        docs: {
            description: "enforce default clauses in switch statements to be last",
            recommended: false,
            url: "https://eslint.org/docs/rules/default-case-last"
        },

        schema: [],

        messages: {
            notLast: "Default clause should be the last clause."
        }
    },

    create(context) {
        return {
            SwitchStatement(node) {
                const cases = node.cases,
                    indexOfDefault = cases.findIndex(c => c.test === null);

                if (indexOfDefault !== -1 && indexOfDefault !== cases.length - 1) {
                    const defaultClause = cases[indexOfDefault];

                    context.report({ node: defaultClause, messageId: "notLast" });
                }
            }
        };
    }
};

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-0.27.1 packages/webpacker/node_modules/eslint/lib/rules/default-case-last.js
decidim-0.26.4 packages/webpacker/node_modules/eslint/lib/rules/default-case-last.js
decidim-0.27.0 packages/webpacker/node_modules/eslint/lib/rules/default-case-last.js
decidim-0.26.3 packages/webpacker/node_modules/eslint/lib/rules/default-case-last.js
decidim-0.27.0.rc2 packages/webpacker/node_modules/eslint/lib/rules/default-case-last.js
decidim-0.27.0.rc1 packages/webpacker/node_modules/eslint/lib/rules/default-case-last.js