mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
|
/**
|
||
|
* @fileoverview Rule to disallow a duplicate case label.
|
||
|
* @author Dieter Oberkofler
|
||
|
* @author Burak Yigit Kaya
|
||
|
*/
|
||
|
|
||
|
"use strict";
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
// Rule Definition
|
||
|
//------------------------------------------------------------------------------
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
type: "problem",
|
||
|
|
||
|
docs: {
|
||
|
description: "disallow duplicate case labels",
|
||
|
category: "Possible Errors",
|
||
|
recommended: true,
|
||
|
url: "https://eslint.org/docs/rules/no-duplicate-case"
|
||
|
},
|
||
|
|
||
|
schema: [],
|
||
|
|
||
|
messages: {
|
||
|
unexpected: "Duplicate case label."
|
||
|
}
|
||
|
},
|
||
|
|
||
|
create(context) {
|
||
|
const sourceCode = context.getSourceCode();
|
||
|
|
||
|
return {
|
||
|
SwitchStatement(node) {
|
||
|
const mapping = {};
|
||
|
|
||
|
node.cases.forEach(switchCase => {
|
||
|
const key = sourceCode.getText(switchCase.test);
|
||
|
|
||
|
if (mapping[key]) {
|
||
|
context.report({ node: switchCase, messageId: "unexpected" });
|
||
|
} else {
|
||
|
mapping[key] = switchCase;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
};
|