source: imaps-frontend/node_modules/eslint/lib/rules/default-case-last.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * @fileoverview Rule to enforce default clauses in switch statements to be last
3 * @author Milos Djermanovic
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12/** @type {import('../shared/types').Rule} */
13module.exports = {
14 meta: {
15 type: "suggestion",
16
17 docs: {
18 description: "Enforce default clauses in switch statements to be last",
19 recommended: false,
20 url: "https://eslint.org/docs/latest/rules/default-case-last"
21 },
22
23 schema: [],
24
25 messages: {
26 notLast: "Default clause should be the last clause."
27 }
28 },
29
30 create(context) {
31 return {
32 SwitchStatement(node) {
33 const cases = node.cases,
34 indexOfDefault = cases.findIndex(c => c.test === null);
35
36 if (indexOfDefault !== -1 && indexOfDefault !== cases.length - 1) {
37 const defaultClause = cases[indexOfDefault];
38
39 context.report({ node: defaultClause, messageId: "notLast" });
40 }
41 }
42 };
43 }
44};
Note: See TracBrowser for help on using the repository browser.