]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-label-var.js
a07d283f522b5ed33ca13b409893397df16ec396
2 * @fileoverview Rule to flag labels that are the same as an identifier
3 * @author Ian Christian Myers
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const astUtils
= require("./utils/ast-utils");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
18 /** @type {import('../shared/types').Rule} */
24 description
: "Disallow labels that share a name with a variable",
26 url
: "https://eslint.org/docs/rules/no-label-var"
32 identifierClashWithLabel
: "Found identifier with same name as label."
38 //--------------------------------------------------------------------------
40 //--------------------------------------------------------------------------
43 * Check if the identifier is present inside current scope
44 * @param {Object} scope current scope
45 * @param {string} name To evaluate
46 * @returns {boolean} True if its present
49 function findIdentifier(scope
, name
) {
50 return astUtils
.getVariableByName(scope
, name
) !== null;
53 //--------------------------------------------------------------------------
55 //--------------------------------------------------------------------------
59 LabeledStatement(node
) {
61 // Fetch the innermost scope.
62 const scope
= context
.getScope();
65 * Recursively find the identifier walking up the scope, starting
66 * with the innermost scope.
68 if (findIdentifier(scope
, node
.label
.name
)) {
71 messageId
: "identifierClashWithLabel"