Skip to content

Commit

Permalink
Drop support for Node.js v12 and add unicorn/prefer-top-level-await
Browse files Browse the repository at this point in the history
… to recommended preset (#1803)
  • Loading branch information
fisker committed May 1, 2022
1 parent 4b96057 commit 6f5ecf5
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 63 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/main.yml
Expand Up @@ -10,50 +10,48 @@ jobs:
fail-fast: false
matrix:
node-version:
- 18
- 16
- 14
- 12
os:
- ubuntu-latest
- windows-latest
exclude:
- os: ubuntu-latest
node-version: 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npx ava
lint-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npm run lint
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
- run: npx c8 ava --update-snapshots
env:
AVA_FORCE_CI: not-ci
- run: git diff --exit-code
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
run-rules-on-codebase:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npm run run-rules-on-codebase
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npm run integration
6 changes: 2 additions & 4 deletions .github/workflows/smoke-test.yml
Expand Up @@ -9,10 +9,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: |
npm install
npm link
Expand Down
3 changes: 1 addition & 2 deletions configs/recommended.js
Expand Up @@ -105,8 +105,7 @@ module.exports = {
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-switch': 'error',
'unicorn/prefer-ternary': 'error',
// TODO: Enable this by default when targeting Node.js 14.
'unicorn/prefer-top-level-await': 'off',
'unicorn/prefer-top-level-await': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/prevent-abbreviations': 'error',
'unicorn/relative-url-style': 'error',
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/prefer-top-level-await.md
Expand Up @@ -2,6 +2,8 @@

<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
<!-- RULE_NOTICE -->
*This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.*

💡 *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).*
<!-- /RULE_NOTICE -->

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=12"
"node": ">=14"
},
"scripts": {
"create-rule": "node ./scripts/create-rule.mjs && npm run generate-rule-notices && npm run generate-rules-table",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -144,7 +144,7 @@ Each rule has emojis denoting:
| [prefer-string-trim-start-end](docs/rules/prefer-string-trim-start-end.md) | Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()`. || 🔧 | |
| [prefer-switch](docs/rules/prefer-switch.md) | Prefer `switch` over multiple `else-if`. || 🔧 | |
| [prefer-ternary](docs/rules/prefer-ternary.md) | Prefer ternary expressions over simple `if-else` statements. || 🔧 | |
| [prefer-top-level-await](docs/rules/prefer-top-level-await.md) | Prefer top-level await over top-level promises and async function calls. | | | 💡 |
| [prefer-top-level-await](docs/rules/prefer-top-level-await.md) | Prefer top-level await over top-level promises and async function calls. | | | 💡 |
| [prefer-type-error](docs/rules/prefer-type-error.md) | Enforce throwing `TypeError` in type checking conditions. || 🔧 | |
| [prevent-abbreviations](docs/rules/prevent-abbreviations.md) | Prevent abbreviations. || 🔧 | |
| [relative-url-style](docs/rules/relative-url-style.md) | Enforce consistent relative URL style. || 🔧 | 💡 |
Expand Down
10 changes: 4 additions & 6 deletions scripts/rename-rule.mjs
@@ -1,5 +1,4 @@
#!/usr/bin/env node
import process from 'node:process';
import fs, {promises as fsAsync} from 'node:fs';
import enquirer from 'enquirer';
import unicorn from '../index.js';
Expand Down Expand Up @@ -60,7 +59,7 @@ async function renameRule(from, to) {
}
}

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

checkFiles(ruleId);
renameRule(originalRuleId, ruleId);
})().catch(error => {
console.error(error);
process.exit(1);
});
};

await run();
62 changes: 31 additions & 31 deletions test/integration/test.mjs
Expand Up @@ -148,40 +148,40 @@ const list = new Listr([
renderer: isCI ? 'verbose' : 'default',
});

list.run()
.catch(async error => {
if (error.errors) {
for (const error2 of error.errors) {
console.error('\n', chalk.red.bold.underline(error2.packageName), chalk.gray('(' + error2.cliArgs.join(' ') + ')'));
console.error(error2.message);

if (error2.stderr) {
console.error(chalk.gray(error2.stderr));
}

if (error2.eslintMessage) {
const {file, project, destination} = error2.eslintJob;
const {line} = error2.eslintMessage;
async function logError(error) {
if (error.errors) {
for (const error2 of error.errors) {
console.error('\n', chalk.red.bold.underline(error2.packageName), chalk.gray('(' + error2.cliArgs.join(' ') + ')'));
console.error(error2.message);

if (error2.stderr) {
console.error(chalk.gray(error2.stderr));
}

if (project.repository) {
// eslint-disable-next-line no-await-in-loop
const branch = await getBranch(destination);
console.error(chalk.gray(`${project.repository}/blob/${branch}/${path.relative(destination, file.filePath)}#L${line}`));
} else {
console.error(chalk.gray(`${path.relative(destination, file.filePath)}#L${line}`));
}
if (error2.eslintMessage) {
const {file, project, destination} = error2.eslintJob;
const {line} = error2.eslintMessage;

console.error(chalk.gray(JSON.stringify(error2.eslintMessage, undefined, 2)));
if (project.repository) {
// eslint-disable-next-line no-await-in-loop
const branch = await getBranch(destination);
console.error(chalk.gray(`${project.repository}/blob/${branch}/${path.relative(destination, file.filePath)}#L${line}`));
} else {
console.error(chalk.gray(`${path.relative(destination, file.filePath)}#L${line}`));
}

console.error(chalk.gray(JSON.stringify(error2.eslintMessage, undefined, 2)));
}
} else {
console.error(error);
}

process.exit(1);
})
// Catch errors in last `.catch`
.catch(error => {
} else {
console.error(error);
process.exit(1);
});
}

process.exit(1);
}

try {
await list.run();
} catch (error) {
await logError(error);
}
10 changes: 4 additions & 6 deletions test/run-rules-on-codebase/lint.mjs
Expand Up @@ -31,7 +31,6 @@ const eslint = new ESLint({
'unicorn/no-unsafe-regex': 'off',
// Not ready yet
'unicorn/prefer-string-replace-all': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/prefer-at': 'off',
// TODO: Turn this on when `xo` updated `eslint-plugin-unicorn`
'unicorn/text-encoding-identifier-case': 'off',
Expand All @@ -52,7 +51,7 @@ const eslint = new ESLint({
const sum = (collection, fieldName) =>
collection.reduce((total, {[fieldName]: value}) => total + value, 0);

(async function () {
async function run() {
const results = await eslint.lintFiles(files);

if (fix) {
Expand Down Expand Up @@ -85,7 +84,6 @@ const sum = (collection, fieldName) =>
}

process.exit(errorCount);
})().catch(error => {
process.exitCode = 1;
console.error(error);
});
}

await run();

0 comments on commit 6f5ecf5

Please sign in to comment.