2 * @fileoverview Rule to disallow assignments to native objects or read-only global variables
4 * @deprecated in ESLint v3.3.0
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
18 description: "disallow assignments to native objects or read-only global variables",
19 category: "Best Practices",
21 url: "https://eslint.org/docs/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) || [];
52 * Reports write references.
53 * @param {Reference} reference A reference to check.
54 * @param {int} index The index of the reference in the references.
55 * @param {Reference[]} references The array that the reference belongs to.
58 function checkReference(reference, index, references) {
59 const identifier = reference.identifier;
61 if (reference.init === false &&
62 reference.isWrite() &&
65 * Destructuring assignments can have multiple default value,
66 * so possibly there are multiple writeable references for the same identifier.
68 (index === 0 || references[index - 1].identifier !== identifier)
72 messageId: "nativeReassign",
79 * Reports write references if a given variable is read-only builtin.
80 * @param {Variable} variable A variable to check.
83 function checkVariable(variable) {
84 if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) {
85 variable.references.forEach(checkReference);
91 const globalScope = context.getScope();
93 globalScope.variables.forEach(checkVariable);