persona-community-5/.pnpm-store/v3/files/4b/f1e6fbc62f89c6b6cd6567becaf830e5f49ceff40ce5f5cb996c59365537f8a98f56552f22ab73a81d93685be0c49dfb32614166b4ed2f28f905da5c1ebf54
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

57 lines
1.5 KiB
Plaintext

/**
* @fileoverview A rule to disallow modifying variables that are declared using `const`
* @author Toru Nagashima
*/
"use strict";
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "problem",
docs: {
description: "Disallow reassigning `const` variables",
recommended: true,
url: "https://eslint.org/docs/latest/rules/no-const-assign"
},
schema: [],
messages: {
const: "'{{name}}' is constant."
}
},
create(context) {
const sourceCode = context.sourceCode;
/**
* Finds and reports references that are non initializer and writable.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
astUtils.getModifyingReferences(variable.references).forEach(reference => {
context.report({ node: reference.identifier, messageId: "const", data: { name: reference.identifier.name } });
});
}
return {
VariableDeclaration(node) {
if (node.kind === "const") {
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
}
}
};
}
};