Skip to content

Commit d2f7271

Browse files
authoredApr 26, 2024··
feat: use ESLint Flat Config (#1457)
## PR Checklist - [x] Addresses an existing open issue: fixes #1212 - [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 Migrates the `.eslintrc.cjs` file to the new "flat" config format `eslint.config.js`. This has the added benefit of removing the last "dot" file (`.*`) that was being linted. So that's a bit simpler of an ESLint config.
1 parent 8a228d9 commit d2f7271

22 files changed

+803
-779
lines changed
 

‎.eslintrc.cjs

-166
This file was deleted.

‎.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
"yaml"
1515
],
1616
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
17+
"eslint.useFlatConfig": true,
1718
"typescript.tsdk": "node_modules/typescript/lib"
1819
}

‎cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"precommit",
2828
"quickstart",
2929
"tada",
30+
"tseslint",
3031
"tsup",
3132
"vitest"
3233
]

‎eslint.config.js

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
👋 Hi! This ESLint configuration contains a lot more stuff than many repos'!
3+
You can read from it to see all sorts of linting goodness, but don't worry -
4+
it's not something you need to exhaustively understand immediately. 💙
5+
6+
If you're interested in learning more, see the 'getting started' docs on:
7+
- ESLint: https://eslint.org
8+
- typescript-eslint: https://typescript-eslint.io
9+
*/
10+
11+
import eslint from "@eslint/js";
12+
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs";
13+
import jsdoc from "eslint-plugin-jsdoc";
14+
import jsonc from "eslint-plugin-jsonc";
15+
import markdown from "eslint-plugin-markdown";
16+
import n from "eslint-plugin-n";
17+
import packageJson from "eslint-plugin-package-json/configs/recommended";
18+
import perfectionistNatural from "eslint-plugin-perfectionist/configs/recommended-natural";
19+
import * as regexp from "eslint-plugin-regexp";
20+
import vitest from "eslint-plugin-vitest";
21+
import yml from "eslint-plugin-yml";
22+
import tseslint from "typescript-eslint";
23+
24+
export default tseslint.config(
25+
{
26+
ignores: [
27+
"coverage*",
28+
"lib",
29+
"node_modules",
30+
"pnpm-lock.yaml",
31+
"**/*.snap",
32+
],
33+
},
34+
{
35+
linterOptions: {
36+
reportUnusedDisableDirectives: "error",
37+
},
38+
},
39+
eslint.configs.recommended,
40+
...jsonc.configs["flat/recommended-with-json"],
41+
...markdown.configs.recommended,
42+
...yml.configs["flat/recommended"],
43+
...yml.configs["flat/prettier"],
44+
comments.recommended,
45+
jsdoc.configs["flat/recommended-typescript-error"],
46+
n.configs["flat/recommended"],
47+
packageJson,
48+
perfectionistNatural,
49+
regexp.configs["flat/recommended"],
50+
...tseslint.config({
51+
extends: [
52+
...tseslint.configs.strictTypeChecked,
53+
...tseslint.configs.stylisticTypeChecked,
54+
],
55+
files: ["**/*.js", "**/*.ts"],
56+
languageOptions: {
57+
parserOptions: {
58+
EXPERIMENTAL_useProjectService: {
59+
allowDefaultProjectForFiles: ["./*.*s", "eslint.config.js"],
60+
defaultProject: "./tsconfig.json",
61+
},
62+
},
63+
},
64+
rules: {
65+
// These off-by-default rules work well for this repo and we like them on.
66+
"jsdoc/informative-docs": "error",
67+
"logical-assignment-operators": [
68+
"error",
69+
"always",
70+
{ enforceForIfStatements: true },
71+
],
72+
"operator-assignment": "error",
73+
74+
// These on-by-default rules don't work well for this repo and we like them off.
75+
"jsdoc/require-jsdoc": "off",
76+
"jsdoc/require-param": "off",
77+
"jsdoc/require-property": "off",
78+
"jsdoc/require-returns": "off",
79+
"no-constant-condition": "off",
80+
81+
// These on-by-default rules work well for this repo if configured
82+
"@typescript-eslint/no-unnecessary-condition": [
83+
"error",
84+
{
85+
allowConstantLoopConditions: true,
86+
},
87+
],
88+
"@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }],
89+
"@typescript-eslint/prefer-nullish-coalescing": [
90+
"error",
91+
{ ignorePrimitives: true },
92+
],
93+
"@typescript-eslint/restrict-template-expressions": [
94+
"error",
95+
{ allowBoolean: true, allowNullish: true, allowNumber: true },
96+
],
97+
"perfectionist/sort-objects": [
98+
"error",
99+
{
100+
order: "asc",
101+
"partition-by-comment": true,
102+
type: "natural",
103+
},
104+
],
105+
106+
// Stylistic concerns that don't interfere with Prettier
107+
"no-useless-rename": "error",
108+
"object-shorthand": "error",
109+
},
110+
}),
111+
{
112+
files: ["*.jsonc"],
113+
rules: {
114+
"jsonc/comma-dangle": "off",
115+
"jsonc/no-comments": "off",
116+
"jsonc/sort-keys": "error",
117+
},
118+
},
119+
{
120+
extends: [tseslint.configs.disableTypeChecked],
121+
files: ["**/*.md/*.ts"],
122+
rules: {
123+
"n/no-missing-import": [
124+
"error",
125+
{ allowModules: ["create-typescript-app"] },
126+
],
127+
},
128+
},
129+
{
130+
files: ["**/*.test.*"],
131+
languageOptions: {
132+
globals: vitest.environments.env.globals,
133+
},
134+
plugins: { vitest },
135+
rules: {
136+
...vitest.configs.recommended.rules,
137+
138+
// These on-by-default rules aren't useful in test files.
139+
"@typescript-eslint/no-unsafe-assignment": "off",
140+
"@typescript-eslint/no-unsafe-call": "off",
141+
},
142+
},
143+
{
144+
files: ["**/*.{yml,yaml}"],
145+
rules: {
146+
"yml/file-extension": ["error", { extension: "yml" }],
147+
"yml/sort-keys": [
148+
"error",
149+
{
150+
order: { type: "asc" },
151+
pathPattern: "^.*$",
152+
},
153+
],
154+
"yml/sort-sequence-values": [
155+
"error",
156+
{
157+
order: { type: "asc" },
158+
pathPattern: "^.*$",
159+
},
160+
],
161+
},
162+
},
163+
);

0 commit comments

Comments
 (0)
Please sign in to comment.