forked from alchemyplatform/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.ts
More file actions
103 lines (97 loc) · 2.78 KB
/
eslint.config.ts
File metadata and controls
103 lines (97 loc) · 2.78 KB
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
// Using .ts config setup requires jiti to be installed
// @see https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files
import { type ConfigWithExtends } from "@eslint/config-helpers";
import eslint from "@eslint/js";
import parser from "@typescript-eslint/parser";
import eslintPrettier from "eslint-config-prettier";
import * as mdx from "eslint-plugin-mdx";
import { defineConfig } from "eslint/config";
import globals from "globals";
import tseslint from "typescript-eslint";
const globalRules: ConfigWithExtends["rules"] = {
eqeqeq: ["error", "smart"],
"no-console": ["warn", { allow: ["warn", "error", "info"] }],
"no-lonely-if": "error",
"no-nested-ternary": "error",
};
const jsConfig: ConfigWithExtends = {
name: "JS Eslint Config",
files: ["**/*.{js,mjs,cjs,jsx,mjsx}"],
ignores: ["**/dist/**", "**/*.{md,mdx}/**/*.{js,jsx}"], // js blocks in md/mdx files handled by jsSnippetConfig
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
globals: {
...globals.browser,
...globals.node,
},
},
extends: [eslint.configs.recommended, eslintPrettier],
rules: {
...globalRules,
"no-shadow": "error",
},
};
const tslintConfigs = tseslint.config({
name: "TS Eslint Config",
files: ["**/*.{ts,tsx,mts}"],
ignores: ["**/*.{md,mdx}/**/*.{ts,tsx}"], // ts blocks in md/mdx files handled by tsSnippetConfig
languageOptions: {
parser,
parserOptions: {
project: ["./tsconfig.json"],
ecmaVersion: "latest",
sourceType: "module",
},
},
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
eslintPrettier,
],
rules: {
...globalRules,
"@typescript-eslint/no-shadow": ["error", { builtinGlobals: false }],
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
},
],
"@typescript-eslint/no-unused-expressions": [
"error",
{
allowTaggedTemplates: true,
},
],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-non-null-assertion": "error",
},
}) as ConfigWithExtends[];
const mdxConfig: ConfigWithExtends = {
name: "MDX Eslint Config",
...mdx.flat,
processor: mdx.createRemarkProcessor({
lintCodeBlocks: true,
}),
};
const mdxCodeBlocksConfig: ConfigWithExtends = {
name: "MDX Code Blocks Eslint Config",
...mdx.flatCodeBlocks,
rules: {
...globalRules,
...eslint.configs.recommended.rules,
...mdx.flatCodeBlocks.rules,
"no-useless-catch": "off",
"no-console": "off",
},
};
export default defineConfig(
jsConfig,
...tslintConfigs,
mdxConfig,
mdxCodeBlocksConfig,
);