From c376fbc340b597d72af4102c899dc9bd12858095 Mon Sep 17 00:00:00 2001 From: Philipp Fritsche Date: Fri, 15 Jul 2022 08:48:58 +0000 Subject: [PATCH] chore: whitelist implicit globals --- eslint-local-rules/explicit-globals.js | 57 ++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/eslint-local-rules/explicit-globals.js b/eslint-local-rules/explicit-globals.js index 5f2aba44..663953f8 100644 --- a/eslint-local-rules/explicit-globals.js +++ b/eslint-local-rules/explicit-globals.js @@ -1,3 +1,53 @@ +// ignore standard built-in objects +const whitelist = [ + 'Infinity', + 'NaN', + 'undefined', + 'Object', + 'Function', + 'Boolean', + 'Symbol', + 'Error', + 'EvalError', + 'InternalError', + 'RangeError', + 'ReferenceError', + 'SyntaxError', + 'TypeError', + 'URIError', + 'Number', + 'Math', + 'Date', + 'String', + 'RegExp', + 'Array', + 'Int8Array', + 'Uint8Array', + 'Uint8ClampedArray', + 'Int16Array', + 'Uint16Array', + 'Int32Array', + 'Uint32Array', + 'Float32Array', + 'Float64Array', + 'Map', + 'Set', + 'WeakMap', + 'WeakSet', + 'ArrayBuffer', + 'DataView', + 'JSON', + 'Promise', + 'Generator', + 'GeneratorFunction', + 'Reflect', + 'Proxy', + 'Intl', + 'Intl.Collator', + 'Intl.DateTimeFormat', + 'Intl.NumberFormat', +] + module.exports = { meta: { type: 'suggestion', @@ -13,13 +63,12 @@ module.exports = { // `scope` is `GlobalScope` and `scope.variables` are the global variables scope.variables.forEach(variable => { - // ignore `undefined` - if (variable.name === 'undefined') { + if (whitelist.includes(variable.name)) { return } + variable.references.forEach(ref => { - // Ignore types and global standard variables like `Object` - if (ref.resolved.constructor.name === 'ImplicitLibVariable') { + if (ref.identifier.parent.type.startsWith('TS')) { return }