Skip to content

Commit

Permalink
feat: use @typescript-eslint/recommended-type-checked in create-next-…
Browse files Browse the repository at this point in the history
…app --typescript
  • Loading branch information
JoshuaKGoldberg committed Jul 20, 2023
1 parent a26bac9 commit 6c62e53
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ The `next/core-web-vitals` rule set is enabled when `next lint` is run for the f

> The `next/core-web-vitals` entry point is automatically included for new applications built with [Create Next App](/docs/app/api-reference/create-next-app).
### TypeScript

In addition to the Next.js ESLint rules, `create-next-app --typescript` will also add [`@typescript-eslint`'s base recommended rules] to your config:

```json filename=".eslintrc.json"
{
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
```

See [typescript-eslint > Configs](https://typescript-eslint.io/linting/configs) for details on those recommended rules.

## Usage With Other Tools

### Prettier
Expand Down
5 changes: 4 additions & 1 deletion examples/middleware/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
7 changes: 5 additions & 2 deletions examples/next-forms/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"root": true,
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
],
"root": true
}
4 changes: 2 additions & 2 deletions examples/with-temporal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@types/node-fetch": "^3.0.3",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"cross-env": "^7.0.3",
"nodemon": "^2.0.12",
"ts-node": "^10.2.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/create-next-app/templates/app-tw/js/eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
5 changes: 4 additions & 1 deletion packages/create-next-app/templates/app-tw/ts/eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
5 changes: 4 additions & 1 deletion packages/create-next-app/templates/app/js/eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
5 changes: 4 additions & 1 deletion packages/create-next-app/templates/app/ts/eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
5 changes: 4 additions & 1 deletion packages/create-next-app/templates/default/js/eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
5 changes: 4 additions & 1 deletion packages/create-next-app/templates/default/ts/eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"next/core-web-vitals"
]
}
16 changes: 7 additions & 9 deletions packages/eslint-config-next/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ sortedPaths.push(...keptPaths)

const hookPropertyMap = new Map(
[
['eslint-plugin-import', 'eslint-plugin-import'],
['eslint-plugin-react', 'eslint-plugin-react'],
['eslint-plugin-jsx-a11y', 'eslint-plugin-jsx-a11y'],
].map(([request, replacement]) => [
'@typescript-eslint/eslint-plugin',
'eslint-plugin-import',
'eslint-plugin-react',
'eslint-plugin-jsx-a11y',
].map((request) => [
request,
require.resolve(replacement, { paths: sortedPaths }),
require.resolve(request, { paths: sortedPaths }),
])
)

Expand Down Expand Up @@ -95,11 +96,8 @@ module.exports = {
files: ['**/*.ts?(x)'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
warnOnUnsupportedTypeScriptVersion: true,
},
},
],
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dependencies": {
"@next/eslint-plugin-next": "13.4.10",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.42.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
Expand Down
Loading

0 comments on commit 6c62e53

Please sign in to comment.