Skip to content

Commit 343be34

Browse files
Migrate eslint config to flat format (#3055)
Fixes #2927
1 parent 6039ab8 commit 343be34

File tree

28 files changed

+335
-359
lines changed

28 files changed

+335
-359
lines changed

.eslintrc.json

Lines changed: 0 additions & 120 deletions
This file was deleted.

.github/workflows/pre-commit.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
runs-on: ubuntu-latest
1818
env:
1919
CURSORLESS_REPO_ROOT: ${{ github.workspace }}
20-
ESLINT_USE_FLAT_CONFIG: false
2120

2221
steps:
2322
- name: Checkout repository

eslint.config.mts

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import eslintJs from "@eslint/js";
2+
import prettierConfig from "eslint-config-prettier/flat";
3+
import importPlugin from "eslint-plugin-import";
4+
import mochaPlugin from "eslint-plugin-mocha";
5+
import unicornPlugin from "eslint-plugin-unicorn";
6+
import unusedImportsPlugin from "eslint-plugin-unused-imports";
7+
import eslintTs, { type ConfigWithExtends } from "typescript-eslint";
8+
import { commonConfig } from "./packages/common/eslint.config.mts";
9+
import { cursorlessEngineConfig } from "./packages/cursorless-engine/eslint.config.mts";
10+
import { cursorlessOrgConfig } from "./packages/cursorless-org/eslint.config.mts";
11+
import { cursorlessVscodeConfig } from "./packages/cursorless-vscode/eslint.config.mts";
12+
13+
const ignoresConfig: ConfigWithExtends = {
14+
ignores: [
15+
"**/generated/**/*",
16+
"**/out/**/*",
17+
"**/dist/**/*",
18+
"**/build/**/*",
19+
"**/vendor/**/*",
20+
"**/.next/**/*",
21+
"**/.docusaurus/**/*",
22+
"**/eslint.config.mts",
23+
"data/playground/**/*",
24+
],
25+
};
26+
27+
const rootConfig: ConfigWithExtends = {
28+
plugins: {
29+
"unused-imports": unusedImportsPlugin,
30+
import: importPlugin,
31+
unicorn: unicornPlugin,
32+
mocha: mochaPlugin,
33+
},
34+
35+
languageOptions: {
36+
parser: eslintTs.parser,
37+
ecmaVersion: 6,
38+
sourceType: "module",
39+
parserOptions: {
40+
project: true,
41+
},
42+
},
43+
44+
settings: {
45+
"import/resolver": {
46+
typescript: {
47+
// Always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
48+
alwaysTryTypes: true,
49+
project: ["tsconfig.json", "packages/*/tsconfig.json"],
50+
},
51+
},
52+
},
53+
54+
rules: {
55+
"import/no-relative-packages": "error",
56+
"@typescript-eslint/consistent-type-imports": "error",
57+
"@typescript-eslint/consistent-type-assertions": [
58+
"error",
59+
{
60+
assertionStyle: "as",
61+
},
62+
],
63+
"@typescript-eslint/naming-convention": [
64+
"error",
65+
{
66+
selector: ["objectLiteralProperty"],
67+
format: ["camelCase"],
68+
filter: {
69+
regex: "[.]",
70+
match: false,
71+
},
72+
},
73+
],
74+
"@typescript-eslint/no-floating-promises": "error",
75+
"@typescript-eslint/no-explicit-any": "off",
76+
"@typescript-eslint/no-inferrable-types": "off",
77+
"@typescript-eslint/no-non-null-assertion": "off",
78+
"unused-imports/no-unused-imports": "error",
79+
"@typescript-eslint/no-unused-vars": [
80+
"error",
81+
{
82+
argsIgnorePattern: "^_",
83+
varsIgnorePattern: "^_",
84+
caughtErrorsIgnorePattern: "^_",
85+
ignoreRestSiblings: true,
86+
},
87+
],
88+
curly: "error",
89+
eqeqeq: [
90+
"error",
91+
"always",
92+
{
93+
null: "never",
94+
},
95+
],
96+
"no-constant-condition": [
97+
"error",
98+
{
99+
checkLoops: false,
100+
},
101+
],
102+
"no-restricted-syntax": [
103+
"error",
104+
"MemberExpression[object.property.name='constructor'][property.name='name']",
105+
],
106+
"no-throw-literal": "error",
107+
semi: "off",
108+
"unicorn/prefer-module": "error",
109+
"mocha/no-pending-tests": "error",
110+
"mocha/no-exclusive-tests": "error",
111+
},
112+
};
113+
114+
const tsxConfig: ConfigWithExtends = {
115+
files: ["**/*.tsx"],
116+
rules: {
117+
"@typescript-eslint/naming-convention": [
118+
"error",
119+
{
120+
selector: ["function"],
121+
format: ["PascalCase", "camelCase"],
122+
},
123+
],
124+
},
125+
};
126+
127+
const disabledTypeCheckConfig: ConfigWithExtends = {
128+
files: [
129+
"**/jest.config.ts",
130+
"**/docusaurus.config.mts",
131+
"**/mdx-components.tsx",
132+
"typings/**",
133+
"**/*.js",
134+
"**/*.mjs",
135+
],
136+
137+
extends: [eslintTs.configs.disableTypeChecked],
138+
};
139+
140+
export default eslintTs.config(
141+
ignoresConfig,
142+
eslintJs.configs.recommended,
143+
// We want to enable this in the long run. For now there are a lot of errors that needs to be handled.
144+
// eslintTs.configs.recommendedTypeChecked,
145+
eslintTs.configs.recommended,
146+
prettierConfig,
147+
rootConfig,
148+
tsxConfig,
149+
disabledTypeCheckConfig,
150+
commonConfig,
151+
cursorlessEngineConfig,
152+
cursorlessVscodeConfig,
153+
cursorlessOrgConfig,
154+
);

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"fix:syncpack": "pnpm syncpack fix-mismatches",
1919
"init-vscode-sandbox": "pnpm --filter=@cursorless/cursorless-vscode init-launch-sandbox",
2020
"lint:meta": "pnpm run meta-updater:base --test",
21-
"lint:ts": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint packages --ext ts,tsx,mts",
21+
"lint:ts": "eslint packages --ext ts,tsx,mts",
2222
"lint": "pnpm run lint:meta && syncpack list-mismatches && pnpm run lint:ts",
2323
"meta-updater:base": "pnpm --filter=@cursorless/meta-updater build && meta-updater",
2424
"preinstall": "npx only-allow pnpm",
@@ -31,23 +31,23 @@
3131
"watch:tsc": "tsc --build --watch"
3232
},
3333
"devDependencies": {
34+
"@eslint/eslintrc": "^3.3.1",
35+
"@eslint/js": "^9.31.0",
3436
"@pnpm/meta-updater": "^2.0.6",
3537
"@types/node": "^24.0.15",
36-
"@typescript-eslint/eslint-plugin": "^8.38.0",
37-
"@typescript-eslint/parser": "^8.38.0",
38-
"cross-env": "^7.0.3",
3938
"esbuild": "^0.25.8",
4039
"eslint": "^9.31.0",
4140
"eslint-config-prettier": "^10.1.8",
4241
"eslint-import-resolver-typescript": "^4.4.4",
4342
"eslint-plugin-import": "^2.32.0",
44-
"eslint-plugin-mocha": "^10.5.0",
45-
"eslint-plugin-unicorn": "^56.0.1",
43+
"eslint-plugin-mocha": "^11.1.0",
44+
"eslint-plugin-unicorn": "^60.0.0",
4645
"eslint-plugin-unused-imports": "^4.1.4",
4746
"prettier": "~3.3.3",
4847
"prettier-plugin-tailwindcss": "^0.6.14",
4948
"syncpack": "^13.0.4",
50-
"typescript": "^5.8.3"
49+
"typescript": "^5.8.3",
50+
"typescript-eslint": "^8.38.0"
5151
},
5252
"pnpm": {
5353
"patchedDependencies": {

packages/cheatsheet-local/src/webpack.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Generated using webpack-cli https://github.com/webpack/webpack-cli
2-
/*eslint-env node*/
32

43
import {
54
cheatsheetBodyClasses,

packages/common/.eslintrc.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/common/eslint.config.mts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { ConfigArray } from "typescript-eslint";
2+
3+
export const commonConfig: ConfigArray = [
4+
{
5+
files: ["packages/common/**/*.ts"],
6+
7+
ignores: ["**/*.test.ts"],
8+
9+
rules: {
10+
"import/no-nodejs-modules": "error",
11+
},
12+
},
13+
14+
{
15+
files: ["packages/common/src/types/command/**/*.ts"],
16+
17+
rules: {
18+
"@typescript-eslint/no-restricted-imports": [
19+
"error",
20+
{
21+
patterns: [
22+
{
23+
group: ["@cursorless/*", "../*"],
24+
message: "API types shouldn't have any dependencies",
25+
},
26+
],
27+
paths: [
28+
{
29+
name: "@*",
30+
message: "API types shouldn't have any dependencies",
31+
},
32+
],
33+
},
34+
],
35+
},
36+
},
37+
];

packages/common/scripts/my-ts-node.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env node
22
// @ts-check
3-
/*eslint-env node*/
3+
/* global process, console */
4+
45
// This script runs a TypeScript file using Node.js by first bundling it with
56
// esbuild.
7+
68
import { spawn } from "cross-spawn";
79
import { build } from "esbuild";
810
import { existsSync, mkdirSync, rmdirSync } from "node:fs";

0 commit comments

Comments
 (0)