Skip to content

Commit

Permalink
chore: whitelist implicit globals
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Jul 15, 2022
1 parent cf5faed commit c376fbc
Showing 1 changed file with 53 additions and 4 deletions.
57 changes: 53 additions & 4 deletions eslint-local-rules/explicit-globals.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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
}

Expand Down

0 comments on commit c376fbc

Please sign in to comment.