Skip to content

Commit cb7abc5

Browse files
authored
Get globals directly from globals package (#2395)
1 parent 3c33820 commit cb7abc5

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

configs/flat-config-base.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
2-
const eslintrc = require('@eslint/eslintrc');
3-
4-
const {globals} = eslintrc.Legacy.environments.get('es2024');
2+
const globals = require('globals');
53

64
module.exports = {
75
languageOptions: {
8-
globals,
6+
globals: globals.builtin,
97
},
108
};

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@
5353
"dependencies": {
5454
"@babel/helper-validator-identifier": "^7.24.5",
5555
"@eslint-community/eslint-utils": "^4.4.0",
56-
"@eslint/eslintrc": "^3.0.2",
5756
"ci-info": "^4.0.0",
5857
"clean-regexp": "^1.0.0",
5958
"core-js-compat": "^3.37.0",
6059
"esquery": "^1.5.0",
60+
"globals": "^15.7.0",
6161
"indent-string": "^4.0.0",
6262
"is-builtin-module": "^3.2.1",
6363
"jsesc": "^3.0.2",
@@ -72,13 +72,14 @@
7272
"@babel/code-frame": "^7.24.2",
7373
"@babel/core": "^7.24.5",
7474
"@babel/eslint-parser": "^7.24.5",
75+
"@eslint/eslintrc": "^3.1.0",
7576
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
7677
"@typescript-eslint/parser": "^8.0.0-alpha.12",
7778
"ava": "^6.1.3",
7879
"c8": "^9.1.0",
7980
"chalk": "^5.3.0",
8081
"enquirer": "^2.4.1",
81-
"eslint": "^9.2.0",
82+
"eslint": "^9.6.0",
8283
"eslint-ava-rule-tester": "^5.0.1",
8384
"eslint-doc-generator": "1.7.0",
8485
"eslint-plugin-eslint-plugin": "^6.1.0",

readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ If you don't use the preset, ensure you use the same `languageOptions` config as
2727

2828
```js
2929
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
30-
import * as eslintrc from '@eslint/eslintrc';
30+
import globals from 'globals';
3131

3232
export default [
3333
{
3434
languageOptions: {
35-
globals: eslintrc.Legacy.environments.get('es2024'),
35+
globals: globals.builtin,
3636
},
3737
plugins: {
3838
unicorn: eslintPluginUnicorn,
@@ -51,12 +51,12 @@ export default [
5151
```js
5252
'use strict';
5353
const eslintPluginUnicorn = require('eslint-plugin-unicorn');
54-
const eslintrc = require('@eslint/eslintrc');
54+
const globals = require('globals');
5555

5656
module.exports = [
5757
{
5858
languageOptions: {
59-
globals: eslintrc.Legacy.environments.get('es2024'),
59+
globals: globals.builtin,
6060
},
6161
plugins: {
6262
unicorn: eslintPluginUnicorn,

test/package.mjs

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import process from 'node:process';
44
import test from 'ava';
55
import eslintExperimentalApis from 'eslint/use-at-your-own-risk';
66
import * as eslintrc from '@eslint/eslintrc';
7+
import globals from 'globals';
78
import eslintPluginUnicorn from '../index.js';
89

910
const {FlatESLint} = eslintExperimentalApis;
@@ -157,6 +158,14 @@ function getCompactConfig(config) {
157158
// https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-objects
158159
delete languageOptions.ecmaVersion;
159160
delete languageOptions.sourceType;
161+
languageOptions.globals = {
162+
...languageOptions.globals,
163+
// When use `env.es*: true` in legacy config, `es5` globals are not included
164+
...globals.es5,
165+
// `Intl` was added to ESLint https://github.com/eslint/eslint/pull/18318
166+
// But `@eslint/eslintrc` choose not to update `globals` https://github.com/eslint/eslintrc/pull/164
167+
Intl: false,
168+
};
160169
result[key] = languageOptions;
161170
} else if (key === 'plugins') {
162171
result[key] = undefined;

test/utils/language-options.mjs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import {Legacy} from '@eslint/eslintrc';
21
import * as espree from 'espree';
2+
import globals from 'globals';
33

44
const DEFAULT_LANGUAGE_OPTIONS = {
55
// When `parser` in `undefined`, `languageOptions` seems has no effect
66
parser: espree,
7-
globals: Object.fromEntries(
8-
['es2024', 'node', 'browser']
9-
.flatMap(environment => Object.entries(Legacy.environments.get(environment).globals)),
10-
),
7+
globals: {
8+
...globals.builtin,
9+
...globals.node,
10+
...globals.browser,
11+
},
1112
};
1213

1314
function cleanLanguageOptions(languageOptions) {

0 commit comments

Comments
 (0)