Skip to content

Commit b10aa13

Browse files
fix: normalized eslint.config.js ordering and trimming (#1723)
## PR Checklist - [x] Addresses an existing open issue: fixes #1715 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Applies the standard ordering prototyped in #1670. That is, the flat config array elements are in the following order: 1. Necessary metadata: first `ignores` (now sorted), then `linterOptions` 2. Straightforward preset properties, in alphabetical order * `...`s are no longer necessary as of typescript-eslint/typescript-eslint#10333 3. Object literals, in alphabetical order of `files` 💖
1 parent ce1be8a commit b10aa13

File tree

4 files changed

+76
-140
lines changed

4 files changed

+76
-140
lines changed

eslint.config.js

+14-28
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,29 @@ import tseslint from "typescript-eslint";
2424
export default tseslint.config(
2525
{
2626
ignores: [
27+
"**/*.snap",
2728
"coverage*",
2829
"lib",
2930
"node_modules",
3031
"pnpm-lock.yaml",
31-
"**/*.snap",
3232
],
3333
},
34-
{
35-
linterOptions: {
36-
reportUnusedDisableDirectives: "error",
37-
},
38-
},
34+
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
3935
eslint.configs.recommended,
40-
...jsonc.configs["flat/recommended-with-json"],
41-
...markdown.configs.recommended,
42-
...yml.configs["flat/recommended"],
43-
...yml.configs["flat/prettier"],
4436
comments.recommended,
4537
jsdoc.configs["flat/contents-typescript-error"],
4638
jsdoc.configs["flat/logical-typescript-error"],
4739
jsdoc.configs["flat/stylistic-typescript-error"],
40+
jsonc.configs["flat/recommended-with-json"],
41+
markdown.configs.recommended,
4842
n.configs["flat/recommended"],
4943
packageJson,
5044
perfectionist.configs["recommended-natural"],
5145
regexp.configs["flat/recommended"],
5246
{
5347
extends: [
54-
...tseslint.configs.strictTypeChecked,
55-
...tseslint.configs.stylisticTypeChecked,
48+
tseslint.configs.strictTypeChecked,
49+
tseslint.configs.stylisticTypeChecked,
5650
],
5751
files: ["**/*.js", "**/*.ts"],
5852
languageOptions: {
@@ -94,39 +88,31 @@ export default tseslint.config(
9488
"object-shorthand": "error",
9589
"operator-assignment": "error",
9690
},
97-
settings: {
98-
perfectionist: {
99-
partitionByComment: true,
100-
type: "natural",
101-
},
102-
},
91+
settings: { perfectionist: { partitionByComment: true, type: "natural" } },
92+
},
93+
{
94+
extends: [tseslint.configs.disableTypeChecked],
95+
files: ["**/*.md/*.ts"],
10396
},
10497
{
10598
extends: [vitest.configs.recommended],
10699
files: ["**/*.test.*"],
107100
rules: {
108-
// These on-by-default rules aren't useful in test files.
109101
"@typescript-eslint/no-unsafe-assignment": "off",
110-
"@typescript-eslint/no-unsafe-call": "off",
111102
},
112103
},
113104
{
105+
extends: [yml.configs["flat/recommended"], yml.configs["flat/prettier"]],
114106
files: ["**/*.{yml,yaml}"],
115107
rules: {
116108
"yml/file-extension": ["error", { extension: "yml" }],
117109
"yml/sort-keys": [
118110
"error",
119-
{
120-
order: { type: "asc" },
121-
pathPattern: "^.*$",
122-
},
111+
{ order: { type: "asc" }, pathPattern: "^.*$" },
123112
],
124113
"yml/sort-sequence-values": [
125114
"error",
126-
{
127-
order: { type: "asc" },
128-
pathPattern: "^.*$",
129-
},
115+
{ order: { type: "asc" }, pathPattern: "^.*$" },
130116
],
131117
},
132118
},

script/__snapshots__/migrate-test-e2e.ts.snap

+24-12
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,29 @@ exports[`expected file changes > eslint.config.js 1`] = `
124124
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs";
125125
import eslint from "@eslint/js";
126126
import vitest from "@vitest/eslint-plugin";
127+
@@ ... @@ import tseslint from "typescript-eslint";
128+
129+
export default tseslint.config(
130+
{
131+
- ignores: [
132+
- "**/*.snap",
133+
- "coverage*",
134+
- "lib",
135+
- "node_modules",
136+
- "pnpm-lock.yaml",
137+
- ],
138+
+ ignores: ["**/*.snap", "coverage", "lib", "node_modules", "pnpm-lock.yaml"],
139+
},
140+
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
141+
eslint.configs.recommended,
127142
@@ ... @@ export default tseslint.config(
143+
files: ["**/*.js", "**/*.ts"],
128144
languageOptions: {
129145
parserOptions: {
130-
projectService: {
146+
- projectService: {
131147
- allowDefaultProject: ["*.config.*s", "bin/*.js", "script/*.ts"],
132-
+ allowDefaultProject: ["*.config.*s"],
133-
},
148+
- },
149+
+ projectService: { allowDefaultProject: ["*.config.*s"] },
134150
tsconfigRootDir: import.meta.dirname,
135151
},
136152
},
@@ -159,22 +175,18 @@ exports[`expected file changes > eslint.config.js 1`] = `
159175
"logical-assignment-operators": [
160176
"error",
161177
@@ ... @@ export default tseslint.config(
162-
},
163-
},
164-
},
165-
+ {
166-
+ extends: [tseslint.configs.disableTypeChecked],
167-
+ files: ["**/*.md/*.ts"],
178+
{
179+
extends: [tseslint.configs.disableTypeChecked],
180+
files: ["**/*.md/*.ts"],
168181
+ rules: {
169182
+ "n/no-missing-import": [
170183
+ "error",
171184
+ { allowModules: ["create-typescript-app"] },
172185
+ ],
173186
+ },
174-
+ },
187+
},
175188
{
176-
extends: [vitest.configs.recommended],
177-
files: ["**/*.test.*"],"
189+
extends: [vitest.configs.recommended],"
178190
`;
179191
180192
exports[`expected file changes > knip.json 1`] = `

src/steps/writing/creation/createESLintConfig.test.ts

+15-49
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,16 @@ describe("createESLintConfig", () => {
5555
import tseslint from "typescript-eslint";
5656
5757
export default tseslint.config(
58-
{
59-
ignores: ["lib", "node_modules", "pnpm-lock.yaml"],
60-
},
61-
{
62-
linterOptions: {
63-
reportUnusedDisableDirectives: "error",
64-
},
65-
},
58+
{ ignores: ["lib", "node_modules", "pnpm-lock.yaml"] },
59+
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
6660
eslint.configs.recommended,
6761
n.configs["flat/recommended"],
6862
{
6963
extends: tseslint.configs.recommendedTypeChecked,
7064
files: ["**/*.js", "**/*.ts"],
7165
languageOptions: {
7266
parserOptions: {
73-
projectService: {
74-
allowDefaultProject: ["*.config.*s"],
75-
},
67+
projectService: { allowDefaultProject: ["*.config.*s"] },
7668
tsconfigRootDir: import.meta.dirname,
7769
},
7870
},
@@ -107,43 +99,29 @@ describe("createESLintConfig", () => {
10799
108100
export default tseslint.config(
109101
{
110-
ignores: [
111-
"coverage*",
112-
"lib",
113-
"node_modules",
114-
"pnpm-lock.yaml",
115-
"**/*.snap",
116-
],
117-
},
118-
{
119-
linterOptions: {
120-
reportUnusedDisableDirectives: "error",
121-
},
102+
ignores: ["**/*.snap", "coverage", "lib", "node_modules", "pnpm-lock.yaml"],
122103
},
104+
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
123105
eslint.configs.recommended,
124-
...jsonc.configs["flat/recommended-with-json"],
125-
...markdown.configs.recommended,
126-
...yml.configs["flat/recommended"],
127-
...yml.configs["flat/prettier"],
128106
comments.recommended,
129107
jsdoc.configs["flat/contents-typescript-error"],
130108
jsdoc.configs["flat/logical-typescript-error"],
131109
jsdoc.configs["flat/stylistic-typescript-error"],
110+
jsonc.configs["flat/recommended-with-json"],
111+
markdown.configs.recommended,
132112
n.configs["flat/recommended"],
133113
packageJson,
134114
perfectionist.configs["recommended-natural"],
135115
regexp.configs["flat/recommended"],
136116
{
137117
extends: [
138-
...tseslint.configs.strictTypeChecked,
139-
...tseslint.configs.stylisticTypeChecked,
118+
tseslint.configs.strictTypeChecked,
119+
tseslint.configs.stylisticTypeChecked,
140120
],
141121
files: ["**/*.js", "**/*.ts"],
142122
languageOptions: {
143123
parserOptions: {
144-
projectService: {
145-
allowDefaultProject: ["*.config.*s"],
146-
},
124+
projectService: { allowDefaultProject: ["*.config.*s"] },
147125
tsconfigRootDir: import.meta.dirname,
148126
},
149127
},
@@ -158,12 +136,7 @@ describe("createESLintConfig", () => {
158136
"object-shorthand": "error",
159137
"operator-assignment": "error",
160138
},
161-
settings: {
162-
perfectionist: {
163-
partitionByComment: true,
164-
type: "natural",
165-
},
166-
},
139+
settings: { perfectionist: { partitionByComment: true, type: "natural" } },
167140
},
168141
{
169142
extends: [tseslint.configs.disableTypeChecked],
@@ -173,31 +146,24 @@ describe("createESLintConfig", () => {
173146
},
174147
},
175148
{
176-
files: ["**/*.test.*"],
177149
extends: [vitest.configs.recommended],
150+
files: ["**/*.test.*"],
178151
rules: {
179-
// These on-by-default rules aren't useful in test files.
180152
"@typescript-eslint/no-unsafe-assignment": "off",
181-
"@typescript-eslint/no-unsafe-call": "off",
182153
},
183154
},
184155
{
156+
extends: [yml.configs["flat/recommended"], yml.configs["flat/prettier"]],
185157
files: ["**/*.{yml,yaml}"],
186158
rules: {
187159
"yml/file-extension": ["error", { extension: "yml" }],
188160
"yml/sort-keys": [
189161
"error",
190-
{
191-
order: { type: "asc" },
192-
pathPattern: "^.*$",
193-
},
162+
{ order: { type: "asc" }, pathPattern: "^.*$" },
194163
],
195164
"yml/sort-sequence-values": [
196165
"error",
197-
{
198-
order: { type: "asc" },
199-
pathPattern: "^.*$",
200-
},
166+
{ order: { type: "asc" }, pathPattern: "^.*$" },
201167
],
202168
},
203169
},

0 commit comments

Comments
 (0)