Skip to content

Commit 6f5ecf5

Browse files
authored
Drop support for Node.js v12 and add unicorn/prefer-top-level-await to recommended preset (#1803)
1 parent 4b96057 commit 6f5ecf5

File tree

9 files changed

+56
-63
lines changed

9 files changed

+56
-63
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,48 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 18
1314
- 16
1415
- 14
15-
- 12
1616
os:
1717
- ubuntu-latest
1818
- windows-latest
1919
exclude:
2020
- os: ubuntu-latest
2121
node-version: 16
2222
steps:
23-
- uses: actions/checkout@v2
24-
- uses: actions/setup-node@v2
23+
- uses: actions/checkout@v3
24+
- uses: actions/setup-node@v3
2525
with:
2626
node-version: ${{ matrix.node-version }}
2727
- run: npm install
2828
- run: npx ava
2929
lint-test:
3030
runs-on: ubuntu-latest
3131
steps:
32-
- uses: actions/checkout@v2
33-
- uses: actions/setup-node@v2
34-
with:
35-
node-version: 16
32+
- uses: actions/checkout@v3
33+
- uses: actions/setup-node@v3
3634
- run: npm install
3735
- run: npm run lint
3836
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
3937
- run: npx c8 ava --update-snapshots
4038
env:
4139
AVA_FORCE_CI: not-ci
4240
- run: git diff --exit-code
43-
- uses: codecov/codecov-action@v1
41+
- uses: codecov/codecov-action@v2
4442
with:
4543
fail_ci_if_error: true
4644
run-rules-on-codebase:
4745
runs-on: ubuntu-latest
4846
steps:
49-
- uses: actions/checkout@v2
50-
- uses: actions/setup-node@v2
47+
- uses: actions/checkout@v3
48+
- uses: actions/setup-node@v3
5149
- run: npm install
5250
- run: npm run run-rules-on-codebase
5351
integration:
5452
runs-on: ubuntu-latest
5553
steps:
56-
- uses: actions/checkout@v2
57-
- uses: actions/setup-node@v2
54+
- uses: actions/checkout@v3
55+
- uses: actions/setup-node@v3
5856
- run: npm install
5957
- run: npm run integration

.github/workflows/smoke-test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ jobs:
99
lint:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-node@v1
14-
with:
15-
node-version: 16
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
1614
- run: |
1715
npm install
1816
npm link

configs/recommended.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ module.exports = {
105105
'unicorn/prefer-string-trim-start-end': 'error',
106106
'unicorn/prefer-switch': 'error',
107107
'unicorn/prefer-ternary': 'error',
108-
// TODO: Enable this by default when targeting Node.js 14.
109-
'unicorn/prefer-top-level-await': 'off',
108+
'unicorn/prefer-top-level-await': 'error',
110109
'unicorn/prefer-type-error': 'error',
111110
'unicorn/prevent-abbreviations': 'error',
112111
'unicorn/relative-url-style': 'error',

docs/rules/prefer-top-level-await.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
44
<!-- RULE_NOTICE -->
5+
*This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.*
6+
57
💡 *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).*
68
<!-- /RULE_NOTICE -->
79

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "https://sindresorhus.com"
1212
},
1313
"engines": {
14-
"node": ">=12"
14+
"node": ">=14"
1515
},
1616
"scripts": {
1717
"create-rule": "node ./scripts/create-rule.mjs && npm run generate-rule-notices && npm run generate-rules-table",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Each rule has emojis denoting:
144144
| [prefer-string-trim-start-end](docs/rules/prefer-string-trim-start-end.md) | Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()`. || 🔧 | |
145145
| [prefer-switch](docs/rules/prefer-switch.md) | Prefer `switch` over multiple `else-if`. || 🔧 | |
146146
| [prefer-ternary](docs/rules/prefer-ternary.md) | Prefer ternary expressions over simple `if-else` statements. || 🔧 | |
147-
| [prefer-top-level-await](docs/rules/prefer-top-level-await.md) | Prefer top-level await over top-level promises and async function calls. | | | 💡 |
147+
| [prefer-top-level-await](docs/rules/prefer-top-level-await.md) | Prefer top-level await over top-level promises and async function calls. | | | 💡 |
148148
| [prefer-type-error](docs/rules/prefer-type-error.md) | Enforce throwing `TypeError` in type checking conditions. || 🔧 | |
149149
| [prevent-abbreviations](docs/rules/prevent-abbreviations.md) | Prevent abbreviations. || 🔧 | |
150150
| [relative-url-style](docs/rules/relative-url-style.md) | Enforce consistent relative URL style. || 🔧 | 💡 |

scripts/rename-rule.mjs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
import process from 'node:process';
32
import fs, {promises as fsAsync} from 'node:fs';
43
import enquirer from 'enquirer';
54
import unicorn from '../index.js';
@@ -60,7 +59,7 @@ async function renameRule(from, to) {
6059
}
6160
}
6261

63-
(async () => {
62+
const run = async () => {
6463
const originalRuleId = await new enquirer.AutoComplete({
6564
message: 'Select the rule you want rename:',
6665
limit: 10,
@@ -83,7 +82,6 @@ async function renameRule(from, to) {
8382

8483
checkFiles(ruleId);
8584
renameRule(originalRuleId, ruleId);
86-
})().catch(error => {
87-
console.error(error);
88-
process.exit(1);
89-
});
85+
};
86+
87+
await run();

test/integration/test.mjs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,40 +148,40 @@ const list = new Listr([
148148
renderer: isCI ? 'verbose' : 'default',
149149
});
150150

151-
list.run()
152-
.catch(async error => {
153-
if (error.errors) {
154-
for (const error2 of error.errors) {
155-
console.error('\n', chalk.red.bold.underline(error2.packageName), chalk.gray('(' + error2.cliArgs.join(' ') + ')'));
156-
console.error(error2.message);
157-
158-
if (error2.stderr) {
159-
console.error(chalk.gray(error2.stderr));
160-
}
161-
162-
if (error2.eslintMessage) {
163-
const {file, project, destination} = error2.eslintJob;
164-
const {line} = error2.eslintMessage;
151+
async function logError(error) {
152+
if (error.errors) {
153+
for (const error2 of error.errors) {
154+
console.error('\n', chalk.red.bold.underline(error2.packageName), chalk.gray('(' + error2.cliArgs.join(' ') + ')'));
155+
console.error(error2.message);
156+
157+
if (error2.stderr) {
158+
console.error(chalk.gray(error2.stderr));
159+
}
165160

166-
if (project.repository) {
167-
// eslint-disable-next-line no-await-in-loop
168-
const branch = await getBranch(destination);
169-
console.error(chalk.gray(`${project.repository}/blob/${branch}/${path.relative(destination, file.filePath)}#L${line}`));
170-
} else {
171-
console.error(chalk.gray(`${path.relative(destination, file.filePath)}#L${line}`));
172-
}
161+
if (error2.eslintMessage) {
162+
const {file, project, destination} = error2.eslintJob;
163+
const {line} = error2.eslintMessage;
173164

174-
console.error(chalk.gray(JSON.stringify(error2.eslintMessage, undefined, 2)));
165+
if (project.repository) {
166+
// eslint-disable-next-line no-await-in-loop
167+
const branch = await getBranch(destination);
168+
console.error(chalk.gray(`${project.repository}/blob/${branch}/${path.relative(destination, file.filePath)}#L${line}`));
169+
} else {
170+
console.error(chalk.gray(`${path.relative(destination, file.filePath)}#L${line}`));
175171
}
172+
173+
console.error(chalk.gray(JSON.stringify(error2.eslintMessage, undefined, 2)));
176174
}
177-
} else {
178-
console.error(error);
179175
}
180-
181-
process.exit(1);
182-
})
183-
// Catch errors in last `.catch`
184-
.catch(error => {
176+
} else {
185177
console.error(error);
186-
process.exit(1);
187-
});
178+
}
179+
180+
process.exit(1);
181+
}
182+
183+
try {
184+
await list.run();
185+
} catch (error) {
186+
await logError(error);
187+
}

test/run-rules-on-codebase/lint.mjs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const eslint = new ESLint({
3131
'unicorn/no-unsafe-regex': 'off',
3232
// Not ready yet
3333
'unicorn/prefer-string-replace-all': 'off',
34-
'unicorn/prefer-top-level-await': 'off',
3534
'unicorn/prefer-at': 'off',
3635
// TODO: Turn this on when `xo` updated `eslint-plugin-unicorn`
3736
'unicorn/text-encoding-identifier-case': 'off',
@@ -52,7 +51,7 @@ const eslint = new ESLint({
5251
const sum = (collection, fieldName) =>
5352
collection.reduce((total, {[fieldName]: value}) => total + value, 0);
5453

55-
(async function () {
54+
async function run() {
5655
const results = await eslint.lintFiles(files);
5756

5857
if (fix) {
@@ -85,7 +84,6 @@ const sum = (collection, fieldName) =>
8584
}
8685

8786
process.exit(errorCount);
88-
})().catch(error => {
89-
process.exitCode = 1;
90-
console.error(error);
91-
});
87+
}
88+
89+
await run();

0 commit comments

Comments
 (0)