]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-native-reassign.js
e3fed445102236cfb590b9b14f02e5edd7ecfb3f
2 * @fileoverview Rule to disallow assignments to native objects or read-only global variables
4 * @deprecated in ESLint v3.3.0
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 /** @type {import('../shared/types').Rule} */
19 description
: "Disallow assignments to native objects or read-only global variables",
21 url
: "https://eslint.org/docs/latest/rules/no-native-reassign"
26 replacedBy
: ["no-global-assign"],
34 items
: { type
: "string" },
38 additionalProperties
: false
43 nativeReassign
: "Read-only global '{{name}}' should not be modified."
48 const config
= context
.options
[0];
49 const exceptions
= (config
&& config
.exceptions
) || [];
50 const sourceCode
= context
.sourceCode
;
53 * Reports write references.
54 * @param {Reference} reference A reference to check.
55 * @param {int} index The index of the reference in the references.
56 * @param {Reference[]} references The array that the reference belongs to.
59 function checkReference(reference
, index
, references
) {
60 const identifier
= reference
.identifier
;
62 if (reference
.init
=== false &&
63 reference
.isWrite() &&
66 * Destructuring assignments can have multiple default value,
67 * so possibly there are multiple writeable references for the same identifier.
69 (index
=== 0 || references
[index
- 1].identifier
!== identifier
)
73 messageId
: "nativeReassign",
80 * Reports write references if a given variable is read-only builtin.
81 * @param {Variable} variable A variable to check.
84 function checkVariable(variable
) {
85 if (variable
.writeable
=== false && !exceptions
.includes(variable
.name
)) {
86 variable
.references
.forEach(checkReference
);
92 const globalScope
= sourceCode
.getScope(node
);
94 globalScope
.variables
.forEach(checkVariable
);