Skip to content

Commit

Permalink
ESLint 9, flat config migration (#1537)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Aaron Moat <[email protected]>
Co-authored-by: skuba <[email protected]>
Co-authored-by: Sam Chung <[email protected]>
  • Loading branch information
4 people committed Sep 24, 2024
1 parent c9c79a7 commit 7797915
Show file tree
Hide file tree
Showing 63 changed files with 1,857 additions and 912 deletions.
18 changes: 18 additions & 0 deletions .changeset/big-weeks-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'skuba': major
---

lint: Migrate to ESLint 9 and `@typescript-eslint` 8.

These changes may affect your project setup if customising your ESLint configuration. See the individual migration guides:

- https://eslint.org/docs/latest/use/migrate-to-9.0.0
- https://typescript-eslint.io/blog/announcing-typescript-eslint-v8

In addition, through these major upgrades, some lint rules have changed or have been renamed. You will likely need adjust your code after running ESLint.

Furthermore, `eslint-plugin-import` has been replaced with `eslint-plugin-import-x`. To migrate, any references to `eslint-plugin-import` should be replaced with `eslint-plugin-import-x`, and `import/` rules with `import-x/`.

As part of this migration, skuba has migrated to using Flat ESLint configuration. Read the migration: https://eslint.org/docs/latest/use/configure/migration-guide.

`skuba format` will attempt to migrate to flat configuration for you, where `.eslintignore` and `.eslintrc` are replaced by `eslint.config.js`.
14 changes: 9 additions & 5 deletions .changeset/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ const gitHubChangelogFunctions = {

const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
let num = Number(pr);
if (!isNaN(num)) prFromSummary = num;
const num = Number(pr);
if (!isNaN(num)) {
prFromSummary = num;
}
return '';
})
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
commitFromSummary = commit;
return '';
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
usersFromSummary.push(user);
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, () => {
return '';
})
.trim();
Expand All @@ -87,6 +88,7 @@ const gitHubChangelogFunctions = {

const links = await (async () => {
if (prFromSummary !== undefined) {
// eslint-disable-next-line no-shadow
let { links } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary,
Expand All @@ -101,7 +103,8 @@ const gitHubChangelogFunctions = {
}
const commitToFetchFrom = commitFromSummary || changeset.commit;
if (commitToFetchFrom) {
let { links } = await getInfo({
// eslint-disable-next-line no-shadow
const { links } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom,
});
Expand All @@ -128,6 +131,7 @@ const gitHubChangelogFunctions = {
if (process.env.GITHUB_TOKEN) {
module.exports = gitHubChangelogFunctions;
} else {
// eslint-disable-next-line no-console
console.warn(
`Defaulting to Git-based versioning.
Enable GitHub-based versioning by setting the GITHUB_TOKEN environment variable.
Expand Down
1 change: 1 addition & 0 deletions .changeset/inject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Hack to add a preamble from .changeset/.PREAMBLE.md to the CHANGELOG.md for a given release
/* eslint-disable no-sync */

const fs = require('fs');

Expand Down
20 changes: 20 additions & 0 deletions .changeset/rich-chairs-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'skuba': minor
---

lint: Replace `.buildkite/` files with duplicated YAML merge keys, for example:

```yaml
# Before
- <<: *deploy
<<: *docker
label: stuff

# After
- <<: [*deploy, *docker]
label: stuff
```
This should have no functional change, and is to support standardised YAML parsing across different tools, including the latest ESLint upgrades.
This migration will not be capture all cases of this (e.g. if there are keys between the merge keys). If you have other cases, update them following the example above.
16 changes: 16 additions & 0 deletions .changeset/thick-taxis-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'eslint-config-skuba': major
---

Migrate to ESLint 9, `@typescript-eslint` 8, `eslint-config-seek` 14.

These changes may affect your project setup if customising your ESLint configuration. See the individual migration guides:

- https://eslint.org/docs/latest/use/migrate-to-9.0.0
- https://typescript-eslint.io/blog/announcing-typescript-eslint-v8

Through these major upgrades, some lint rules have changed or have been renamed. You will likely need to adjust your code after running ESLint.

As part of this migration, this project has migrated to Flat ESLint configuration. Read the migration: https://eslint.org/docs/latest/use/configure/migration-guide.

Furthermore, `eslint-plugin-import` has been replaced with `eslint-plugin-import-x`. To migrate, any references to `eslint-plugin-import` should be replaced with `eslint-plugin-import-x`, and `import/` rules with `import-x/`.
20 changes: 0 additions & 20 deletions .eslintignore

This file was deleted.

37 changes: 0 additions & 37 deletions .eslintrc.js

This file was deleted.

4 changes: 1 addition & 3 deletions config/eslint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
module.exports = {
extends: ['skuba'],
};
module.exports = require('eslint-config-skuba');
3 changes: 1 addition & 2 deletions docs/cli/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ Familiarise yourself with the directory structure that **skuba** has created:
├── app.test.ts
├── app.ts
├── .dockerignore
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .nvmrc
├── .prettierignore
├── .prettierrc.js
├── Dockerfile
├── eslint.config.js
├── README.md
├── docker-compose.yml
├── jest.config.js
Expand Down
15 changes: 8 additions & 7 deletions docs/deep-dives/eslint.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ Please contribute to the [eslint-config-seek] preset if you feel something is mi
It may worthwhile starting with a discussion in [#typescriptification] to garner feedback.

If you wish to enforce additional rules within a given codebase or team,
you can [extend] your `.eslintrc.js`:
you can [extend] your `eslint.config.js`:

```javascript
module.exports = {
extends: ['skuba'],
rules: {
// https://eslint.org/docs/rules/complexity
complexity: ['error', { max: 3 }],
module.exports = [
...require('eslint-config-skuba'),
{
rules: {
// Your custom rules here
},
},
};
];
```

Let's check that our new rule has taken effect.
Expand Down
56 changes: 56 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const tsParser = require('@typescript-eslint/parser');

const skuba = require('eslint-config-skuba');

module.exports = [
{
ignores: [
'integration/base/',
'integration/format/',
'template/',
'packages/**/*/lib*/',
],
},
...skuba,
{
rules: {
'no-process-exit': 'off',
},
},
{
files: ['integration/**/*.{ts,cts,mts,tsx}'],

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
allowAutomaticSingleRunInference: false,
},
},
},
{
files: ['src/**/*.{ts,cts,mts,tsx}'],

rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'fs',
message:
'Prefer fs-extra as it implements graceful-fs behaviour.',
},
{
name: 'fs/promises',
message:
'Prefer fs-extra as it implements graceful-fs behaviour.',
},
],
},
],
},
},
];
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},
"dependencies": {
"@esbuild-plugins/tsconfig-paths": "^0.1.0",
"@eslint/migrate-config": "^1.2.0",
"@jest/types": "^29.0.0",
"@octokit/graphql": "^8.0.0",
"@octokit/graphql-schema": "^15.3.0",
Expand All @@ -83,7 +84,7 @@
"ejs": "^3.1.6",
"enquirer": "^2.3.6",
"esbuild": "~0.24.0",
"eslint": "^8.56.0",
"eslint": "^9.11.1",
"eslint-config-skuba": "workspace:*",
"execa": "^5.0.0",
"fast-glob": "^3.3.2",
Expand Down
15 changes: 0 additions & 15 deletions packages/eslint-config-skuba/.eslintignore

This file was deleted.

1 change: 1 addition & 0 deletions packages/eslint-config-skuba/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('.');
Loading

0 comments on commit 7797915

Please sign in to comment.