Skip to content

fix: normalized eslint.config.js ordering and trimming #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,29 @@ import tseslint from "typescript-eslint";
export default tseslint.config(
{
ignores: [
"**/*.snap",
"coverage*",
"lib",
"node_modules",
"pnpm-lock.yaml",
"**/*.snap",
],
},
{
linterOptions: {
reportUnusedDisableDirectives: "error",
},
},
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
eslint.configs.recommended,
...jsonc.configs["flat/recommended-with-json"],
...markdown.configs.recommended,
...yml.configs["flat/recommended"],
...yml.configs["flat/prettier"],
comments.recommended,
jsdoc.configs["flat/contents-typescript-error"],
jsdoc.configs["flat/logical-typescript-error"],
jsdoc.configs["flat/stylistic-typescript-error"],
jsonc.configs["flat/recommended-with-json"],
markdown.configs.recommended,
n.configs["flat/recommended"],
packageJson,
perfectionist.configs["recommended-natural"],
regexp.configs["flat/recommended"],
{
extends: [
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
],
files: ["**/*.js", "**/*.ts"],
languageOptions: {
Expand Down Expand Up @@ -101,16 +95,20 @@ export default tseslint.config(
},
},
},
{
extends: [tseslint.configs.disableTypeChecked],
files: ["**/*.md/*.ts "],
},
{
extends: [vitest.configs.recommended],
files: ["**/*.test.*"],
rules: {
// These on-by-default rules aren't useful in test files.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed intentionally. I don't think it was worth the space. This block is clearly for test files, and this list isn't something any project of mine has reasonably added to IIRC.

"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Very happy that this has since been made unnecessary. I haven't looked deeply, but I'm betting some improvement to Vitest types changed an any to something more precise.

For no-unsafe-assignment, it's down to two any types in Vitest. Filed: vitest-dev/vitest#7015

},
},
{
extends: [yml.configs["flat/recommended"], yml.configs["flat/prettier"]],
files: ["**/*.{yml,yaml}"],
rules: {
"yml/file-extension": ["error", { extension: "yml" }],
Expand Down
67 changes: 18 additions & 49 deletions src/steps/writing/creation/createESLintConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,16 @@ describe("createESLintConfig", () => {
import tseslint from "typescript-eslint";

export default tseslint.config(
{
ignores: ["lib", "node_modules", "pnpm-lock.yaml"],
},
{
linterOptions: {
reportUnusedDisableDirectives: "error",
},
},
{ ignores: ["lib", "node_modules", "pnpm-lock.yaml"] },
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
eslint.configs.recommended,
n.configs["flat/recommended"],
{
extends: tseslint.configs.recommendedTypeChecked,
files: ["**/*.js", "**/*.ts"],
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ["*.config.*s"],
},
projectService: { allowDefaultProject: ["*.config.*s"] },
tsconfigRootDir: import.meta.dirname,
},
},
Expand Down Expand Up @@ -107,43 +99,29 @@ describe("createESLintConfig", () => {

export default tseslint.config(
{
ignores: [
"coverage*",
"lib",
"node_modules",
"pnpm-lock.yaml",
"**/*.snap",
],
},
{
linterOptions: {
reportUnusedDisableDirectives: "error",
},
ignores: ["**/*.snap", "coverage", "lib", "node_modules", "pnpm-lock.yaml"],
},
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
eslint.configs.recommended,
...jsonc.configs["flat/recommended-with-json"],
...markdown.configs.recommended,
...yml.configs["flat/recommended"],
...yml.configs["flat/prettier"],
comments.recommended,
jsdoc.configs["flat/contents-typescript-error"],
jsdoc.configs["flat/logical-typescript-error"],
jsdoc.configs["flat/stylistic-typescript-error"],
jsonc.configs["flat/recommended-with-json"],
markdown.configs.recommended,
n.configs["flat/recommended"],
packageJson,
perfectionist.configs["recommended-natural"],
regexp.configs["flat/recommended"],
{
extends: [
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
],
files: ["**/*.js", "**/*.ts"],
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ["*.config.*s"],
},
projectService: { allowDefaultProject: ["*.config.*s"] },
tsconfigRootDir: import.meta.dirname,
},
},
Expand All @@ -152,18 +130,15 @@ describe("createESLintConfig", () => {
"logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
{
enforceForIfStatements: true,
},
],
"no-useless-rename": "error",
"object-shorthand": "error",
"operator-assignment": "error",
},
settings: {
perfectionist: {
partitionByComment: true,
type: "natural",
},
},
settings: { perfectionist: { partitionByComment: true, type: "natural" } },
},
{
extends: [tseslint.configs.disableTypeChecked],
Expand All @@ -173,31 +148,25 @@ describe("createESLintConfig", () => {
},
},
{
files: ["**/*.test.*"],
extends: [vitest.configs.recommended],
files: ["**/*.test.*"],
rules: {
// These on-by-default rules aren't useful in test files.
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
},
},
{
extends: [yml.configs["flat/recommended"], yml.configs["flat/prettier"]],
files: ["**/*.{yml,yaml}"],
rules: {
"yml/file-extension": ["error", { extension: "yml" }],
"yml/sort-keys": [
"error",
{
order: { type: "asc" },
pathPattern: "^.*$",
},
{ order: { type: "asc" }, pathPattern: "^.*$" },
],
"yml/sort-sequence-values": [
"error",
{
order: { type: "asc" },
pathPattern: "^.*$",
},
{ order: { type: "asc" }, pathPattern: "^.*$" },
],
},
},
Expand Down
77 changes: 26 additions & 51 deletions src/steps/writing/creation/createESLintConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,39 @@ export async function createESLintConfig(options: Options) {

const elements = [
`eslint.configs.recommended,`,
!options.excludeLintJson &&
` ...jsonc.configs["flat/recommended-with-json"],`,
!options.excludeLintMd && ` ...markdown.configs.recommended,`,
!options.excludeLintYml && ` ...yml.configs["flat/recommended"],`,
!options.excludeLintYml && ` ...yml.configs["flat/prettier"],`,
!options.excludeLintESLint && ` comments.recommended,`,
!options.excludeLintJSDoc &&
` jsdoc.configs["flat/contents-typescript-error"],
jsdoc.configs["flat/logical-typescript-error"],
jsdoc.configs["flat/stylistic-typescript-error"],`,
jsdoc.configs["flat/logical-typescript-error"],
jsdoc.configs["flat/stylistic-typescript-error"],`,
!options.excludeLintJson && ` jsonc.configs["flat/recommended-with-json"],`,
!options.excludeLintMd && ` markdown.configs.recommended,`,
` n.configs["flat/recommended"],`,
!options.excludeLintPackageJson && ` packageJson,`,
!options.excludeLintPerfectionist &&
` perfectionist.configs["recommended-natural"],`,
!options.excludeLintRegex && ` regexp.configs["flat/recommended"],`,
].filter(Boolean);

const ignores = [
...(options.excludeTests ? [] : ["**/*.snap", "coverage"]),
"lib",
"node_modules",
"pnpm-lock.yaml",
]
.map((ignore) => JSON.stringify(ignore))
.sort();

const rules =
!options.excludeLintStylistic &&
`{
// Stylistic concerns that don't interfere with Prettier
"logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
{
enforceForIfStatements: true,
},
],
"no-useless-rename": "error",
"object-shorthand": "error",
Expand All @@ -59,44 +67,22 @@ export async function createESLintConfig(options: Options) {
return await formatTypeScript(`${imports.join("\n")}

export default tseslint.config(
{
ignores: [${
options.excludeTests
? ""
: `
"coverage*",`
}
"lib",
"node_modules",
"pnpm-lock.yaml",${
options.excludeTests
? ""
: `
"**/*.snap",`
}
],
},
{
linterOptions: {
reportUnusedDisableDirectives: "error",
},
},
{ ignores: [${ignores.join(", ")}], },
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
${elements.join("\n")}
{
extends: ${
options.excludeLintStylistic
? `tseslint.configs.${tseslintBase}TypeChecked`
: `[
...tseslint.configs.${tseslintBase}TypeChecked,
...tseslint.configs.stylisticTypeChecked,
tseslint.configs.${tseslintBase}TypeChecked,
tseslint.configs.stylisticTypeChecked,
]`
},
files: ["**/*.js", "**/*.ts"],
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ["*.config.*s"],
},
projectService: { allowDefaultProject: ["*.config.*s"] },
tsconfigRootDir: import.meta.dirname
},
},${
Expand All @@ -108,12 +94,7 @@ export default tseslint.config(
options.excludeLintPerfectionist
? ""
: `
settings: {
perfectionist: {
partitionByComment: true,
type: "natural",
},
},`
settings: { perfectionist: { partitionByComment: true, type: "natural" } },`
}
},
{
Expand All @@ -130,10 +111,9 @@ export default tseslint.config(
? ""
: `
{
files: ["**/*.test.*"],
extends: [vitest.configs.recommended],
files: ["**/*.test.*"],
rules: {
// These on-by-default rules aren't useful in test files.
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
},
Expand All @@ -143,22 +123,17 @@ export default tseslint.config(
? ""
: `
{
extends: [yml.configs["flat/recommended"], yml.configs["flat/prettier"]],
files: ["**/*.{yml,yaml}"],
rules: {
"yml/file-extension": ["error", { extension: "yml" }],
"yml/sort-keys": [
"error",
{
order: { type: "asc" },
pathPattern: "^.*$",
},
{ order: { type: "asc" }, pathPattern: "^.*$" },
],
"yml/sort-sequence-values": [
"error",
{
order: { type: "asc" },
pathPattern: "^.*$",
},
{ order: { type: "asc" }, pathPattern: "^.*$" },
],
},
},`
Expand Down
Loading