Skip to content

Commit 4539e7f

Browse files
committed
chore: add support for markdown files in project eslint config
1 parent c1efc68 commit 4539e7f

File tree

11 files changed

+119
-52
lines changed

11 files changed

+119
-52
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"typescript",
3333
"typescriptreact",
3434
"yaml",
35+
"markdown",
36+
"mdx",
3537
"github-actions-workflow" // for GitHub Actions workflow files
3638
],
3739
"editor.codeActionsOnSave": {

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,3 @@ function useAuth() {
12791279

12801280
- Update Options of rule `jsx/no-useless-fragment`.
12811281
- Optimize bundle size.
1282-
1283-
```
1284-
```

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- eslint-disable markdown/no-html -->
2+
13
<p align="center"><img src="https://eslint-react.xyz/logo.svg" alt="logo" width="150" /></p>
24

35
<h1 align="center" alt="title">ESLint React</h1>

eslint.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import url from "node:url";
33

44
import { Record } from "effect";
55
import eslintJs from "@eslint/js";
6+
import eslintMarkdown from "@eslint/markdown";
67
import eslintPluginImport from "eslint-plugin-import-x";
78
import eslintPluginJsdoc from "eslint-plugin-jsdoc";
89
import eslintPluginLocal from "@workspace/eslint-plugin-local";
@@ -23,6 +24,7 @@ const dirname = url.fileURLToPath(new URL(".", import.meta.url));
2324

2425
const GLOB_JS = ["*.{js,jsx,cjs,mjs}", "**/*.{js,jsx,cjs,mjs}"];
2526
const GLOB_TS = ["*.{ts,tsx,cts,mts}", "**/*.{ts,tsx,cts,mts}"];
27+
const GLOB_MD = ["*.md", "**/*.md"];
2628
const GLOB_TEST = [
2729
"**/*.spec.{ts,tsx,cts,mts}",
2830
"**/*.test.{ts,tsx,cts,mts}",
@@ -94,6 +96,21 @@ const typeCheckedRules = {
9496

9597
export default tseslint.config(
9698
eslintConfigFlatGitignore(),
99+
{
100+
extends: [
101+
// @ts-expect-error - TODO: make types compatible
102+
eslintMarkdown.configs.recommended,
103+
],
104+
files: GLOB_MD,
105+
ignores: [
106+
"packages/**/docs/**/*.md",
107+
],
108+
language: "markdown/gfm",
109+
rules: {
110+
"markdown/no-html": "error",
111+
"markdown/no-missing-label-refs": "off",
112+
},
113+
},
97114
{
98115
name: "global-ignores",
99116
ignores: [

examples/next-app/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "ES2021",
44
"lib": [
55
"dom",
66
"dom.iterable",

packages/plugins/eslint-plugin/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- eslint-disable markdown/no-html -->
2+
13
<p align="center"><img src="https://eslint-react.xyz/logo.svg" alt="logo" width="150" /></p>
24

35
<h1 align="center" alt="title">ESLint React</h1>
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
/* eslint-disable @susisu/safe-typescript/no-type-assertion, better-mutation/no-mutation */
1+
/* eslint-disable @typescript-eslint/no-unsafe-type-assertion, @susisu/safe-typescript/no-type-assertion, better-mutation/no-mutation */
22
// Copied from https://github.com/gustavoguichard/string-ts/blob/9dd444f03fdfa225f1643e6f1f8c18f9480224bb/src/utils/object-keys/transform-keys.ts#L12
33

44
import { typeOf } from "@eslint-react/types";
55

6+
/**
7+
* This function is used to shallowly transform the keys of an object.
8+
* It will only be transformed at runtime, so it's not type safe.
9+
* @param obj the object to transform.
10+
* @param transform the function to transform the keys from string to string.
11+
* @returns the transformed object.
12+
* @example transformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase)
13+
* // { fooBar: { 'fizz-buzz': true } }
14+
*/
615
export function transformKeys<T>(obj: T, transform: (s: string) => string): T {
716
if (typeOf(obj) !== "object") return obj;
8-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
17+
918
const res = {} as T;
1019
for (const key in obj) {
1120
res[transform(key) as keyof T] = obj[key];
1221
}
13-
1422
return res;
1523
}

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/eslint.config.mjs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
1-
// ts-check
2-
31
import eslintJs from "@eslint/js";
42
import eslintReact from "@eslint-react/eslint-plugin";
3+
import eslintMarkdown from "@eslint/markdown";
54
import eslintPluginMdx from "eslint-plugin-mdx";
65
import eslintPluginNext from "@next/eslint-plugin-next";
76
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
7+
import eslintPluginReactRefresh from "eslint-plugin-react-refresh";
88
import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort";
99
import tseslint from "typescript-eslint";
1010
import gitignore from "eslint-config-flat-gitignore";
1111

12-
const GLOB_TS = ["**/*.{ts,tsx}"];
13-
const GLOB_JS = ["**/*.{js,cjs,mjs}"];
12+
import TSCONFIG from "./tsconfig.json" with { type: "json" };
13+
14+
const GLOB_TS = ["**/*.ts", "**/*.tsx"];
15+
const GLOB_JS = ["**/*.js", "**/*.jsx"];
16+
const GLOB_MD = ["**/*.md"];
1417
const GLOB_MDX = ["**/*.mdx"];
1518
const GLOB_APP = ["app/**/*.{js,ts,jsx,tsx}"];
16-
const GLOB_CONFIG = ["**/*.config.{js,mjs,cjs,ts,tsx}"];
19+
const GLOB_CONFIG = ["**/*.config.{js,mjs,ts,tsx}"];
1720

1821
export default tseslint.config(
19-
eslintJs.configs.recommended,
22+
{
23+
files: GLOB_MD,
24+
extends: [
25+
eslintMarkdown.configs.recommended,
26+
],
27+
language: "markdown/gfm",
28+
rules: {
29+
"markdown/no-html": "error",
30+
"markdown/no-missing-label-refs": "off",
31+
},
32+
},
2033
{
2134
...eslintPluginMdx.flat,
2235
files: GLOB_MDX,
@@ -26,30 +39,47 @@ export default tseslint.config(
2639
},
2740
{
2841
files: GLOB_TS,
42+
extends: [
43+
eslintJs.configs.recommended,
44+
tseslint.configs.recommended,
45+
],
46+
},
47+
{
48+
files: TSCONFIG.include,
2949
extends: [
3050
tseslint.configs.recommendedTypeChecked,
3151
],
3252
languageOptions: {
3353
parser: tseslint.parser,
3454
parserOptions: {
3555
project: "./tsconfig.json",
56+
projectService: true,
3657
tsconfigRootDir: import.meta.dirname,
3758
},
3859
},
3960
},
4061
{
41-
files: [...GLOB_TS, ...GLOB_MDX],
42-
...eslintReact.configs.recommended,
62+
files: TSCONFIG.include,
63+
...eslintReact.configs["recommended-type-checked"],
4364
},
4465
{
45-
files: GLOB_TS,
66+
files: TSCONFIG.include,
4667
plugins: {
4768
"react-hooks": eslintPluginReactHooks,
4869
},
4970
rules: eslintPluginReactHooks.configs.recommended.rules,
5071
},
5172
{
52-
files: GLOB_TS,
73+
files: TSCONFIG.include,
74+
plugins: {
75+
"react-refresh": eslintPluginReactRefresh,
76+
},
77+
rules: {
78+
"react-refresh/only-export-components": "warn",
79+
},
80+
},
81+
{
82+
files: TSCONFIG.include,
5383
plugins: {
5484
"@next/next": eslintPluginNext,
5585
},
@@ -59,13 +89,13 @@ export default tseslint.config(
5989
},
6090
},
6191
{
62-
files: [...GLOB_TS, ...GLOB_MDX],
92+
files: GLOB_JS,
6393
plugins: {
6494
"simple-import-sort": eslintPluginSimpleImportSort,
6595
},
6696
rules: {
67-
"simple-import-sort/exports": "warn",
6897
"simple-import-sort/imports": "warn",
98+
"simple-import-sort/exports": "warn",
6999
},
70100
},
71101
{
@@ -75,18 +105,12 @@ export default tseslint.config(
75105
},
76106
},
77107
{
78-
files: [...GLOB_JS, ...GLOB_MDX],
79-
...tseslint.configs.disableTypeChecked,
80-
},
81-
{
82-
files: GLOB_JS,
108+
files: [...GLOB_JS, ...GLOB_CONFIG],
83109
rules: {
110+
...tseslint.configs.disableTypeChecked.rules,
84111
"no-undef": "off",
85-
"@typescript-eslint/no-require-imports": "off",
112+
"no-console": "off",
86113
},
87114
},
88115
gitignore(),
89-
{
90-
ignores: GLOB_CONFIG,
91-
},
92116
);

website/tsconfig.json

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,23 @@
44
"@tsconfig/node22/tsconfig.json"
55
],
66
"compilerOptions": {
7+
"target": "ES2021",
78
"lib": [
8-
"DOM",
9-
"DOM.Iterable",
10-
"ESNext"
9+
"dom",
10+
"dom.iterable",
11+
"esnext"
1112
],
12-
"noEmit": true,
13-
"module": "ESNext",
14-
"moduleResolution": "bundler",
13+
"allowJs": true,
1514
"skipLibCheck": true,
16-
"moduleDetection": "force",
17-
"isolatedModules": true,
18-
"verbatimModuleSyntax": true,
19-
"allowJs": false,
20-
"checkJs": false,
2115
"strict": true,
22-
"noImplicitAny": true,
23-
"noImplicitThis": true,
24-
"noUnusedLocals": false,
25-
"noUnusedParameters": false,
26-
"exactOptionalPropertyTypes": true,
27-
"composite": false,
28-
"stripInternal": false,
16+
"forceConsistentCasingInFileNames": true,
17+
"noEmit": true,
18+
"incremental": true,
19+
"esModuleInterop": true,
20+
"module": "esnext",
21+
"moduleResolution": "node",
22+
"resolveJsonModule": true,
23+
"isolatedModules": true,
2924
"jsx": "preserve",
3025
"paths": {
3126
"#": [
@@ -35,15 +30,18 @@
3530
"./*"
3631
]
3732
},
38-
"resolveJsonModule": true,
39-
"incremental": true
33+
"plugins": [
34+
{
35+
"name": "next"
36+
}
37+
]
4038
},
4139
"include": [
42-
"*.d.ts",
43-
"*.config.js",
44-
"*.config.mjs",
4540
"**/*.ts",
46-
"**/*.tsx"
41+
"**/*.tsx",
42+
"*.d.ts",
43+
"next-env.d.ts",
44+
".next/types/**/*.ts"
4745
],
4846
"exclude": [
4947
"node_modules"

0 commit comments

Comments
 (0)