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
Changes from all commits
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
42 changes: 14 additions & 28 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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: {
@@ -94,39 +88,31 @@ export default tseslint.config(
"object-shorthand": "error",
"operator-assignment": "error",
},
settings: {
perfectionist: {
partitionByComment: true,
type: "natural",
},
},
settings: { perfectionist: { partitionByComment: true, type: "natural" } },
},
{
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" }],
"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: "^.*$" },
],
},
},
36 changes: 24 additions & 12 deletions script/__snapshots__/migrate-test-e2e.ts.snap
Original file line number Diff line number Diff line change
@@ -124,13 +124,29 @@ exports[`expected file changes > eslint.config.js 1`] = `
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs";
import eslint from "@eslint/js";
import vitest from "@vitest/eslint-plugin";
@@ ... @@ import tseslint from "typescript-eslint";

export default tseslint.config(
{
- ignores: [
- "**/*.snap",
- "coverage*",
- "lib",
- "node_modules",
- "pnpm-lock.yaml",
- ],
+ ignores: ["**/*.snap", "coverage", "lib", "node_modules", "pnpm-lock.yaml"],
},
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
eslint.configs.recommended,
@@ ... @@ export default tseslint.config(
files: ["**/*.js", "**/*.ts"],
languageOptions: {
parserOptions: {
projectService: {
- projectService: {
- allowDefaultProject: ["*.config.*s", "bin/*.js", "script/*.ts"],
+ allowDefaultProject: ["*.config.*s"],
},
- },
+ projectService: { allowDefaultProject: ["*.config.*s"] },
tsconfigRootDir: import.meta.dirname,
},
},
@@ -159,22 +175,18 @@ exports[`expected file changes > eslint.config.js 1`] = `
"logical-assignment-operators": [
"error",
@@ ... @@ export default tseslint.config(
},
},
},
+ {
+ extends: [tseslint.configs.disableTypeChecked],
+ files: ["**/*.md/*.ts"],
{
extends: [tseslint.configs.disableTypeChecked],
files: ["**/*.md/*.ts"],
+ rules: {
+ "n/no-missing-import": [
+ "error",
+ { allowModules: ["create-typescript-app"] },
+ ],
+ },
+ },
},
{
extends: [vitest.configs.recommended],
files: ["**/*.test.*"],"
extends: [vitest.configs.recommended],"
`;

exports[`expected file changes > knip.json 1`] = `
64 changes: 15 additions & 49 deletions src/steps/writing/creation/createESLintConfig.test.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
@@ -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,
},
},
@@ -158,12 +136,7 @@ describe("createESLintConfig", () => {
"object-shorthand": "error",
"operator-assignment": "error",
},
settings: {
perfectionist: {
partitionByComment: true,
type: "natural",
},
},
settings: { perfectionist: { partitionByComment: true, type: "natural" } },
},
{
extends: [tseslint.configs.disableTypeChecked],
@@ -173,31 +146,24 @@ 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: "^.*$" },
],
},
},
Loading