diff --git a/lib/source-code/source-code.js b/lib/source-code/source-code.js index f3418e7e5b7..0b9c41ee6e1 100644 --- a/lib/source-code/source-code.js +++ b/lib/source-code/source-code.js @@ -935,7 +935,7 @@ class SourceCode extends TokenStore { * https://github.com/eslint/eslint/issues/16302 */ const configGlobals = Object.assign( - {}, + Object.create(null), // https://github.com/eslint/eslint/issues/18363 getGlobalsForEcmaVersion(languageOptions.ecmaVersion), languageOptions.sourceType === "commonjs" ? globals.commonjs : void 0, languageOptions.globals diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index 6e98b93f3a1..4f61a56bdc1 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -10310,6 +10310,38 @@ describe("Linter with FlatConfigArray", () => { linter.verify(code, config); assert(spy && spy.calledOnce); }); + + // https://github.com/eslint/eslint/issues/18363 + it("not throw when defining a global named __defineSetter__", () => { + const code = "/*global __defineSetter__*/"; + let spy; + + const config = { + plugins: { + test: { + rules: { + checker: { + create(context) { + spy = sinon.spy(node => { + const scope = context.sourceCode.getScope(node); + const def = getVariable(scope, "__defineSetter__"); + + assert.strictEqual(def.name, "__defineSetter__"); + assert.strictEqual(def.writeable, false); + }); + + return { Program: spy }; + } + } + } + } + }, + rules: { "test/checker": "error" } + }; + + linter.verify(code, config); + assert(spy && spy.calledOnce); + }); }); describe("when evaluating code containing a /*global */ block with sloppy whitespace", () => {