Skip to content

Commit

Permalink
fix: resolve globals
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jun 1, 2024
1 parent 96387ca commit 56bfa91
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions src/lib/convert-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,106 @@ import * as semver from "semver";
import type { LinterConfigForV8 } from "../v8-props";
import { safeRequire, safeRequireResolve } from "./require";

const builtInGlobals = new Map<number, [string, boolean][]>([
[
3,
Object.entries({
Array: false,
Boolean: false,
constructor: false,
Date: false,
decodeURI: false,
decodeURIComponent: false,
encodeURI: false,
encodeURIComponent: false,
Error: false,
escape: false,
eval: false,
EvalError: false,
Function: false,
hasOwnProperty: false,
Infinity: false,
isFinite: false,
isNaN: false,
isPrototypeOf: false,
Math: false,
NaN: false,
Number: false,
Object: false,
parseFloat: false,
parseInt: false,
propertyIsEnumerable: false,
RangeError: false,
ReferenceError: false,
RegExp: false,
String: false,
SyntaxError: false,
toLocaleString: false,
toString: false,
TypeError: false,
undefined: false,
unescape: false,
URIError: false,
valueOf: false,
}),
],
[
5,
Object.entries({
JSON: false,
}),
],
[
2015,
Object.entries({
ArrayBuffer: false,
DataView: false,
Float32Array: false,
Float64Array: false,
Int16Array: false,
Int32Array: false,
Int8Array: false,
Intl: false,
Map: false,
Promise: false,
Proxy: false,
Reflect: false,
Set: false,
Symbol: false,
Uint16Array: false,
Uint32Array: false,
Uint8Array: false,
Uint8ClampedArray: false,
WeakMap: false,
WeakSet: false,
}),
],
[
2017,
Object.entries({
Atomics: false,
SharedArrayBuffer: false,
}),
],
[
2020,
Object.entries({
BigInt: false,
BigInt64Array: false,
BigUint64Array: false,
globalThis: false,
}),
],
[
2021,
Object.entries({
AggregateError: false,
FinalizationRegistry: false,
WeakRef: false,
}),
],
]);

/** Convert to eslintrc config from v9 config */
export function convertConfigToRc(
config: eslint.Linter.FlatConfig | eslint.Linter.FlatConfig[],
Expand Down Expand Up @@ -37,6 +137,16 @@ export function convertConfigToRc(
...parserOptions,
...(newConfig as LinterConfigForV8).parserOptions,
};
const resolvedEcmaVersion = (newConfig as LinterConfigForV8).parserOptions!
.ecmaVersion! as number;
(newConfig as LinterConfigForV8).globals = {
...Object.fromEntries(
[...builtInGlobals.entries()].flatMap(([version, editionGlobals]) =>
resolvedEcmaVersion < version ? [] : editionGlobals,
),
),
...(newConfig as LinterConfigForV8).globals,
};
if (globals) {
(newConfig as LinterConfigForV8).globals = {
...globals,
Expand Down

0 comments on commit 56bfa91

Please sign in to comment.