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
44 const config = context.options[0];
45 const exceptions = (config && config.exceptions) || [];
48 * Reports write references.
49 * @param {Reference} reference A reference to check.
50 * @param {int} index The index of the reference in the references.
51 * @param {Reference[]} references The array that the reference belongs to.
54 function checkReference(reference, index, references) {
55 const identifier = reference.identifier;
57 if (reference.init === false &&
58 reference.isWrite() &&
61 * Destructuring assignments can have multiple default value,
62 * so possibly there are multiple writeable references for the same identifier.
64 (index === 0 || references[index - 1].identifier !== identifier)
68 message: "Read-only global '{{name}}' should not be modified.",
75 * Reports write references if a given variable is read-only builtin.
76 * @param {Variable} variable A variable to check.
79 function checkVariable(variable) {
80 if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) {
81 variable.references.forEach(checkReference);
87 const globalScope = context.getScope();
89 globalScope.variables.forEach(checkVariable);