-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
eslint.config.mjs
129 lines (119 loc) · 3.21 KB
/
eslint.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import js from "@eslint/js";
import ts from "@typescript-eslint/eslint-plugin";
import typescriptParser from "@typescript-eslint/parser";
import eslintPluginAstro from "eslint-plugin-astro";
import preferArrow from "eslint-plugin-prefer-arrow";
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
import fastGlob from "fast-glob";
import globals from "globals";
import { dirname } from "path";
import { fileURLToPath } from "url";
const astroRecommended = eslintPluginAstro.configs["flat/recommended"];
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const appWww = "apps/www";
const packageReact = "packages/react";
const packageMarkdown = "packages/markdown";
const packageCodeBlocks = "packages/code";
const packageButtons = "packages/buttons";
const packageShared = "packages/shared";
const packageJson = "packages/json";
const packageCsv = "packages/csv";
const packageCli = "packages/create-llm-ui";
const toolingGen = "tooling/gen";
const toolingExamples = "tooling/examples";
const reactProjects = [
appWww,
packageReact,
packageMarkdown,
packageCodeBlocks,
packageButtons,
packageShared,
packageJson,
packageCsv,
];
const reactProjectsGlob = `{${reactProjects.join(",")}}`;
const typescriptProjects = [
...reactProjects,
toolingGen,
packageCli,
toolingExamples,
];
const foldersToLint = fastGlob.sync([`apps/*`, `packages/*`, `tooling/*`], {
onlyDirectories: true,
ignore: ["tooling/tsconfig"],
});
const missingInConfig = foldersToLint.filter(
(f) => !typescriptProjects.includes(f),
);
if (missingInConfig.length > 0) {
throw new Error(`Missing in eslint config: ${missingInConfig.join(",")}`);
}
export default [
{
ignores: [
`${appWww}/{public,dist,.vercel,.astro}/**/*`,
`${appWww}/src/components/Posthog.astro`,
`packages/*/dist/**/*`,
],
},
...typescriptProjects.map((project) => ({
files: [`${project}/**/*.{ts,tsx}`],
plugins: {
"@typescript-eslint": ts,
},
languageOptions: {
parser: typescriptParser,
parserOptions: {
project: `${project}/tsconfig.json`,
sourceType: "module",
ecmaVersion: 2020,
},
},
rules: {
...ts.configs["eslint-recommended"].rules,
...ts.configs["recommended"].rules,
},
})),
{
files: [`${reactProjectsGlob}/**/*.{jsx,tsx}`],
...reactRecommended,
languageOptions: {
...reactRecommended.languageOptions,
globals: {
...globals.browser,
},
},
rules: {
...reactRecommended.rules,
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
},
},
{
files: [`${reactProjectsGlob}/**/*.{js,jsx,mjs,cjs,ts,tsx}`],
...js.configs.recommended,
plugins: {
"prefer-arrow": preferArrow,
...js.configs.recommended.plugins,
},
rules: {
"prefer-arrow-callback": "error",
"prefer-arrow/prefer-arrow-functions": [
"error",
{
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false,
},
],
},
},
{
...astroRecommended,
files: [`${appWww}/**/*.{astro}`],
rules: {
...astroRecommended.rules,
},
},
];