Skip to content

Commit 3b9d372

Browse files
committedFeb 6, 2024
Require Node.js 18
1 parent 71857a0 commit 3b9d372

File tree

13 files changed

+140
-114
lines changed

13 files changed

+140
-114
lines changed
 

Diff for: ‎.github/workflows/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ jobs:
1212
node-version:
1313
- 20
1414
- 18
15-
- 16
1615
steps:
17-
- uses: actions/checkout@v3
18-
- uses: actions/setup-node@v3
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1918
with:
2019
node-version: ${{ matrix.node-version }}
2120
- run: npm install --force

Diff for: ‎config/plugins.cjs

+61-54
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
checkFilenames: false,
4242
checkDefaultAndNamespaceImports: false,
4343
checkShorthandImports: false,
44-
extendDefaultReplacements: false,
44+
extendDefaultReplacements: true,
4545
replacements: {
4646
// https://thenextweb.com/dd/2020/07/13/linux-kernel-will-no-longer-use-terms-blacklist-and-slave/
4747
whitelist: {
@@ -57,76 +57,83 @@ module.exports = {
5757
secondary: true,
5858
},
5959

60-
// Not part of `eslint-plugin-unicorn`
60+
// Reverse.
6161
application: {
6262
app: true,
6363
},
6464
applications: {
6565
apps: true,
6666
},
6767

68-
// Part of `eslint-plugin-unicorn`
69-
arr: {
70-
array: true,
68+
// Disable some that may be too annoying.
69+
env: false,
70+
i: false, // Do it at some point, but not ready for it yet. Maybe 2025.
71+
72+
// Not part of `eslint-plugin-unicorn`. Upstream them at some point.
73+
bin: {
74+
binary: true,
7175
},
72-
e: {
73-
error: true,
74-
event: true,
76+
eof: {
77+
endOfFile: true,
7578
},
76-
el: {
77-
element: true,
79+
impl: {
80+
implement: true,
81+
implementation: true,
7882
},
79-
elem: {
80-
element: true,
83+
anim: {
84+
animation: true,
8185
},
82-
len: {
83-
length: true,
86+
calc: {
87+
calculate: true,
8488
},
85-
msg: {
86-
message: true,
89+
dict: {
90+
dictionary: true,
8791
},
88-
num: {
89-
number: true,
92+
dup: {
93+
duplicate: true,
9094
},
91-
obj: {
92-
object: true,
95+
enc: {
96+
encode: true,
97+
encryption: true,
9398
},
94-
opts: {
95-
options: true,
99+
gen: {
100+
generate: true,
101+
general: true,
96102
},
97-
param: {
98-
parameter: true,
103+
gfx: {
104+
graphics: true,
99105
},
100-
params: {
101-
parameters: true,
106+
inc: {
107+
increment: true,
102108
},
103-
prev: {
104-
previous: true,
109+
iter: {
110+
iterate: true,
111+
iterator: true,
105112
},
106-
req: {
107-
request: true,
113+
nav: {
114+
navigate: true,
115+
navigation: true,
108116
},
109-
res: {
110-
response: true,
111-
result: true,
117+
norm: {
118+
normalize: true,
112119
},
113-
ret: {
114-
returnValue: true,
120+
notif: {
121+
notification: true,
115122
},
116-
str: {
117-
string: true,
123+
perf: {
124+
performance: true,
118125
},
119-
temp: {
120-
temporary: true,
126+
proc: {
127+
process: true,
121128
},
122-
tmp: {
123-
temporary: true,
129+
rand: {
130+
random: true,
124131
},
125-
val: {
126-
value: true,
132+
sys: {
133+
system: true,
127134
},
128-
err: {
129-
error: true,
135+
temp: {
136+
temporary: true,
130137
},
131138
},
132139
},
@@ -153,13 +160,10 @@ module.exports = {
153160
},
154161
],
155162

156-
// Temporarily disabled because it's buggy with TypeScript: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2175
163+
// Temporarily disabled because of https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2218
157164
'unicorn/no-empty-file': 'off',
158165

159-
// TODO: Disabled for now until it becomes more stable: https://github.com/sindresorhus/eslint-plugin-unicorn/search?q=consistent-destructuring+is:issue&state=open&type=issues
160-
'unicorn/consistent-destructuring': 'off',
161-
162-
// TODO: Disabled for now as I don't have time to deal with the backslash that might come from this. Try to enable this rule in 2021.
166+
// TODO: Disabled for now as I don't have time to deal with the backslash that might come from this. Try to enable this rule in 2025.
163167
'unicorn/no-null': 'off',
164168

165169
// We only enforce it for single-line statements to not be too opinionated.
@@ -355,10 +359,13 @@ module.exports = {
355359
// 'n/shebang': 'error',
356360

357361
'n/no-deprecated-api': 'error',
358-
'n/prefer-global/buffer': [
359-
'error',
360-
'never',
361-
],
362+
363+
// We no longer enforce this as we don't want to use Buffer at all, but sometimes we need to conditionally use the `Buffer` global, but we then don't want the import so the module works cross-platform.
364+
// 'n/prefer-global/buffer': [
365+
// 'error',
366+
// 'never',
367+
// ],
368+
362369
'n/prefer-global/console': [
363370
'error',
364371
'always',

Diff for: ‎index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ const globFiles = async (patterns, options) => {
2828

2929
const files = await globby(
3030
patterns,
31-
{ignore: ignores, gitignore: true, absolute: true, cwd},
31+
{
32+
ignore: ignores, gitignore: true, absolute: true, cwd,
33+
},
3234
);
3335

3436
return files.filter(file => extensions.includes(path.extname(file).slice(1)));

Diff for: ‎lib/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const DEFAULT_IGNORES = [
77
'**/*.min.js',
88
'vendor/**',
99
'dist/**',
10+
'distribution/**',
1011
'tap-snapshots/*.{cjs,js}',
1112
];
1213

Diff for: ‎lib/options-manager.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os from 'node:os';
44
import path from 'node:path';
55
import arrify from 'arrify';
66
import {mergeWith, flow, pick} from 'lodash-es';
7-
import {findUpSync} from 'find-up';
7+
import {findUpSync} from 'find-up-simple';
88
import findCacheDir from 'find-cache-dir';
99
import prettier from 'prettier';
1010
import semver from 'semver';
@@ -83,7 +83,7 @@ const getEmptyXOConfig = () => ({
8383
extends: [],
8484
});
8585

86-
const mergeFn = (previousValue, value, key) => {
86+
const mergeFunction = (previousValue, value, key) => {
8787
if (Array.isArray(previousValue)) {
8888
if (MERGE_OPTIONS_CONCAT.includes(key)) {
8989
return [...previousValue, ...value];
@@ -102,14 +102,12 @@ The config files are searched starting from `options.filePath` if defined or `op
102102
const mergeWithFileConfig = async options => {
103103
options.cwd = path.resolve(options.cwd || process.cwd());
104104
const configExplorer = cosmiconfig(MODULE_NAME, {searchPlaces: CONFIG_FILES, loaders: {noExt: defaultLoaders['.json']}, stopDir: options.cwd});
105-
const pkgConfigExplorer = cosmiconfig('engines', {searchPlaces: ['package.json'], stopDir: options.cwd});
106-
if (options.filePath) {
107-
options.filePath = path.resolve(options.cwd, options.filePath);
108-
}
105+
const packageConfigExplorer = cosmiconfig('engines', {searchPlaces: ['package.json'], stopDir: options.cwd});
106+
options.filePath &&= path.resolve(options.cwd, options.filePath);
109107

110108
const searchPath = options.filePath || options.cwd;
111109
const {config: xoOptions, filepath: xoConfigPath} = (await configExplorer.search(searchPath)) || {};
112-
const {config: enginesOptions} = (await pkgConfigExplorer.search(searchPath)) || {};
110+
const {config: enginesOptions} = (await packageConfigExplorer.search(searchPath)) || {};
113111

114112
options = normalizeOptions({
115113
...xoOptions,
@@ -274,7 +272,7 @@ const buildConfig = (options, prettierOptions) => {
274272
buildTSConfig(options),
275273
buildExtendsConfig(options),
276274
buildPrettierConfig(options, prettierOptions),
277-
)(mergeWith(getEmptyConfig(), DEFAULT_CONFIG, mergeFn));
275+
)(mergeWith(getEmptyConfig(), DEFAULT_CONFIG, mergeFunction));
278276
};
279277

280278
const toValueMap = (array, value = true) => Object.fromEntries(array.map(item => [item, value]));
@@ -473,7 +471,7 @@ const mergeWithPrettierConfig = (options, prettierOptions) => {
473471
semi: options.semicolon !== false,
474472
},
475473
prettierOptions,
476-
mergeFn,
474+
mergeFunction,
477475
);
478476
};
479477

@@ -503,7 +501,7 @@ const applyOverrides = (file, options) => {
503501

504502
const {applicable, hash} = findApplicableOverrides(path.relative(options.cwd, file), overrides);
505503

506-
options = mergeWith(getEmptyXOConfig(), options, ...applicable.map(override => normalizeOptions(override)), mergeFn);
504+
options = mergeWith(getEmptyXOConfig(), options, ...applicable.map(override => normalizeOptions(override)), mergeFunction);
507505
delete options.files;
508506
return {options, hash};
509507
}

Diff for: ‎package.json

+30-29
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
},
1313
"type": "module",
1414
"bin": "./cli.js",
15+
"sideEffects": false,
1516
"engines": {
16-
"node": ">=16"
17+
"node": ">=18"
1718
},
1819
"scripts": {
1920
"test:clean": "find ./test -type d -name 'node_modules' -prune -not -path ./test/fixtures/project/node_modules -exec rm -rf '{}' +",
@@ -53,53 +54,53 @@
5354
"typescript"
5455
],
5556
"dependencies": {
56-
"@eslint/eslintrc": "^2.1.0",
57-
"@typescript-eslint/eslint-plugin": "^6.0.0",
58-
"@typescript-eslint/parser": "^6.0.0",
57+
"@eslint/eslintrc": "^3.0.0",
58+
"@typescript-eslint/eslint-plugin": "^6.21.0",
59+
"@typescript-eslint/parser": "^6.21.0",
5960
"arrify": "^3.0.0",
60-
"cosmiconfig": "^8.2.0",
61+
"cosmiconfig": "^8.3.6",
6162
"define-lazy-prop": "^3.0.0",
62-
"eslint": "^8.45.0",
63-
"eslint-config-prettier": "^8.8.0",
64-
"eslint-config-xo": "^0.43.1",
65-
"eslint-config-xo-typescript": "^1.0.0",
66-
"eslint-formatter-pretty": "^5.0.0",
67-
"eslint-import-resolver-webpack": "^0.13.2",
63+
"eslint": "^8.53.0",
64+
"eslint-config-prettier": "^9.1.0",
65+
"eslint-config-xo": "^0.44.0",
66+
"eslint-config-xo-typescript": "^2.0.0",
67+
"eslint-formatter-pretty": "^6.0.1",
68+
"eslint-import-resolver-webpack": "^0.13.8",
6869
"eslint-plugin-ava": "^14.0.0",
6970
"eslint-plugin-eslint-comments": "^3.2.0",
70-
"eslint-plugin-import": "~2.27.5",
71-
"eslint-plugin-n": "^16.0.1",
71+
"eslint-plugin-import": "^2.29.1",
72+
"eslint-plugin-n": "^16.6.2",
7273
"eslint-plugin-no-use-extend-native": "^0.5.0",
73-
"eslint-plugin-prettier": "^5.0.0",
74-
"eslint-plugin-unicorn": "^48.0.0",
75-
"esm-utils": "^4.1.2",
76-
"find-cache-dir": "^4.0.0",
77-
"find-up": "^6.3.0",
74+
"eslint-plugin-prettier": "^5.1.3",
75+
"eslint-plugin-unicorn": "^51.0.0",
76+
"esm-utils": "^4.2.1",
77+
"find-cache-dir": "^5.0.0",
78+
"find-up-simple": "^1.0.0",
7879
"get-stdin": "^9.0.0",
79-
"get-tsconfig": "^4.6.2",
80-
"globby": "^13.2.2",
80+
"get-tsconfig": "^4.7.2",
81+
"globby": "^14.0.0",
8182
"imurmurhash": "^0.1.4",
8283
"json-stable-stringify-without-jsonify": "^1.0.1",
8384
"lodash-es": "^4.17.21",
84-
"meow": "^12.0.1",
85+
"meow": "^13.1.0",
8586
"micromatch": "^4.0.5",
86-
"open-editor": "^4.0.0",
87-
"prettier": "^3.0.0",
88-
"semver": "^7.5.4",
87+
"open-editor": "^4.1.1",
88+
"prettier": "^3.2.5",
89+
"semver": "^7.6.0",
8990
"slash": "^5.1.0",
9091
"to-absolute-glob": "^3.0.0",
91-
"typescript": "^5.1.6"
92+
"typescript": "^5.3.3"
9293
},
9394
"devDependencies": {
94-
"ava": "^5.3.1",
95+
"ava": "^6.1.1",
9596
"eslint-config-xo-react": "^0.27.0",
96-
"eslint-plugin-react": "^7.31.10",
97+
"eslint-plugin-react": "^7.33.2",
9798
"eslint-plugin-react-hooks": "^4.6.0",
98-
"execa": "^7.1.1",
99+
"execa": "^8.0.1",
99100
"nyc": "^15.1.0",
100101
"proxyquire": "^2.1.3",
101102
"temp-write": "^5.0.0",
102-
"webpack": "^5.88.1"
103+
"webpack": "^5.90.1"
103104
},
104105
"xo": {
105106
"ignores": [

Diff for: ‎readme.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ If some files in your project are transpiled in order to support an older Node.j
384384

385385
For example, if your project targets Node.js 8 but you want to use the latest JavaScript syntax as supported in Node.js 12:
386386
1. Set the `engines.node` property of your `package.json` to `>=8`
387-
2. Configure [Babel](https://babeljs.io) to transpile your source files (in `src` directory in this example)
387+
2. Configure [Babel](https://babeljs.io) to transpile your source files (in `source` directory in this example)
388388
3. Make sure to include the transpiled files in your published package with the [`files`](https://docs.npmjs.com/files/package.json#files) and [`main`](https://docs.npmjs.com/files/package.json#main) properties of your `package.json`
389389
4. Configure the XO `overrides` option to set `nodeVersion` to `>=12` for your source files directory
390390

@@ -394,14 +394,16 @@ For example, if your project targets Node.js 8 but you want to use the latest Ja
394394
"node": ">=12"
395395
},
396396
"scripts": {
397-
"build": "babel src --out-dir dist"
397+
"build": "babel source --out-dir distribution"
398398
},
399-
"main": "dist/index.js",
400-
"files": ["dist/**/*.js"],
399+
"main": "distribution/index.js",
400+
"files": [
401+
"distribution/**/*.js"
402+
],
401403
"xo": {
402404
"overrides": [
403405
{
404-
"files": "{src}/**/*.js",
406+
"files": "source/**/*.js",
405407
"nodeVersion": ">=16"
406408
}
407409
]

Diff for: ‎test/fixtures/webpack/no-config/file1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import __ from 'inexistent'; // eslint-disable-line no-unused-vars
2-
import _ from 'file2alias'; // eslint-disable-line no-unused-vars
1+
import __ from 'inexistent';
2+
import _ from 'file2alias';

Diff for: ‎test/fixtures/webpack/no-config/file2.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
const foo = 1;
2+
23
export default foo;

Diff for: ‎test/fixtures/webpack/no-config/file3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import _ from '!./file2.js'; // eslint-disable-line no-unused-vars
1+
import _ from '!./file2.js';

Diff for: ‎test/fixtures/webpack/with-config/file1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import __ from 'inexistent'; // eslint-disable-line no-unused-vars
2-
import _ from 'file2alias'; // eslint-disable-line no-unused-vars
1+
import __ from 'inexistent';
2+
import _ from 'file2alias';

Diff for: ‎test/fixtures/webpack/with-config/file2.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
const foo = 1;
2+
23
export default foo;

Diff for: ‎test/options-manager.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,19 @@ test('mergeWithFileConfig: use child if closest', async t => {
498498
const cwd = path.resolve('fixtures', 'nested', 'child');
499499
const {options} = await manager.mergeWithFileConfig({cwd});
500500
const eslintConfigId = new MurmurHash3(path.join(cwd, 'package.json')).result();
501-
const expected = {...childConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId};
501+
const expected = {
502+
...childConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId,
503+
};
502504
t.deepEqual(options, expected);
503505
});
504506

505507
test('mergeWithFileConfig: use parent if closest', async t => {
506508
const cwd = path.resolve('fixtures', 'nested');
507509
const {options} = await manager.mergeWithFileConfig({cwd});
508510
const eslintConfigId = new MurmurHash3(path.join(cwd, 'package.json')).result();
509-
const expected = {...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId};
511+
const expected = {
512+
...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId,
513+
};
510514
t.deepEqual(options, expected);
511515
});
512516

@@ -515,38 +519,48 @@ test('mergeWithFileConfig: use parent if child is ignored', async t => {
515519
const filePath = path.resolve(cwd, 'child-ignore', 'file.js');
516520
const {options} = await manager.mergeWithFileConfig({cwd, filePath});
517521
const eslintConfigId = new MurmurHash3(path.join(cwd, 'package.json')).result();
518-
const expected = {...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, filePath, eslintConfigId};
522+
const expected = {
523+
...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, filePath, eslintConfigId,
524+
};
519525
t.deepEqual(options, expected);
520526
});
521527

522528
test('mergeWithFileConfig: use child if child is empty', async t => {
523529
const cwd = path.resolve('fixtures', 'nested', 'child-empty');
524530
const {options} = await manager.mergeWithFileConfig({cwd});
525531
const eslintConfigId = new MurmurHash3(path.join(cwd, 'package.json')).result();
526-
t.deepEqual(options, {extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId});
532+
t.deepEqual(options, {
533+
extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId,
534+
});
527535
});
528536

529537
test('mergeWithFileConfig: read engines from package.json', async t => {
530538
const cwd = path.resolve('fixtures', 'engines');
531539
const {options} = await manager.mergeWithFileConfig({cwd});
532540
const eslintConfigId = new MurmurHash3().result();
533-
const expected = {nodeVersion: enginesConfig.engines.node, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId};
541+
const expected = {
542+
nodeVersion: enginesConfig.engines.node, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId,
543+
};
534544
t.deepEqual(options, expected);
535545
});
536546

537547
test('mergeWithFileConfig: XO engine options supersede package.json\'s', async t => {
538548
const cwd = path.resolve('fixtures', 'engines');
539549
const {options} = await manager.mergeWithFileConfig({cwd, nodeVersion: '>=8'});
540550
const eslintConfigId = new MurmurHash3().result();
541-
const expected = {nodeVersion: '>=8', extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId};
551+
const expected = {
552+
nodeVersion: '>=8', extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId,
553+
};
542554
t.deepEqual(options, expected);
543555
});
544556

545557
test('mergeWithFileConfig: XO engine options false supersede package.json\'s', async t => {
546558
const cwd = path.resolve('fixtures', 'engines');
547559
const {options} = await manager.mergeWithFileConfig({cwd, nodeVersion: false});
548560
const eslintConfigId = new MurmurHash3().result();
549-
const expected = {nodeVersion: false, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId};
561+
const expected = {
562+
nodeVersion: false, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, eslintConfigId,
563+
};
550564
t.deepEqual(options, expected);
551565
});
552566

0 commit comments

Comments
 (0)
Please sign in to comment.