Skip to content

Commit fb7209b

Browse files
authored
chore: enable eslint-plugin-mdx for linting Markdown files (#241)
1 parent 9730916 commit fb7209b

20 files changed

+3512
-791
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ test/fixtures/typescript-d-ts/
99
# we want to ignore "test/fixtures" here, but unfortunately doing so would
1010
# interfere with unit test and fail it for some reason.
1111
# test/fixtures
12+
CHANGELOG.md

.eslintrc.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'plugin:eslint-plugin/recommended',
1111
'plugin:import-x/recommended',
1212
'plugin:json/recommended-legacy',
13+
'plugin:mdx/recommended',
1314
'plugin:n/recommended',
1415
'plugin:unicorn/recommended',
1516
'plugin:yml/standard',
@@ -45,6 +46,13 @@ module.exports = {
4546
'n/no-missing-import': 'off',
4647
'n/no-missing-require': 'off',
4748
'n/no-unsupported-features/es-syntax': 'off',
49+
'unicorn/filename-case': [
50+
'error',
51+
{
52+
case: 'kebabCase',
53+
ignore: [String.raw`^(CONTRIBUTING|README)\.md$`],
54+
},
55+
],
4856
'unicorn/no-array-callback-reference': 'off',
4957
'unicorn/no-array-reduce': 'off',
5058
'unicorn/no-null': 'off',
@@ -118,7 +126,14 @@ module.exports = {
118126
{
119127
files: 'global.d.ts',
120128
rules: {
121-
'import-x/no-extraneous-dependencies': 0,
129+
'import-x/no-extraneous-dependencies': 'off',
130+
},
131+
},
132+
{
133+
files: 'README.md',
134+
rules: {
135+
// https://github.com/bmish/eslint-doc-generator/issues/655
136+
'no-irregular-whitespace': 'off',
122137
},
123138
},
124139
],

.remarkrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"plugins": [
3+
"@1stg/preset",
4+
[
5+
"lint-no-shortcut-reference-link",
6+
false
7+
],
8+
[
9+
"lint-no-undefined-references",
10+
{
11+
"allow": [
12+
"!NOTE",
13+
"!TIP",
14+
"!WARNING"
15+
]
16+
}
17+
]
18+
]
19+
}

README.md

+10-12
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ settings:
160160
node: true
161161
```
162162
163-
[`@typescript-eslint/parser`]: https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser
164-
[`eslint-import-resolver-typescript`]: https://github.com/import-js/eslint-import-resolver-typescript
165-
166163
## Configuration (new: `eslint.config.js`)
167164

168165
From [`v8.21.0`](https://github.com/eslint/eslint/releases/tag/v8.21.0), ESLint announced a new config system.
@@ -337,11 +334,6 @@ the process's current working directory if no `package.json` is found.
337334

338335
If you are interesting in writing a resolver, see the [spec](./resolvers/README.md) for more details.
339336

340-
[`resolve`]: https://www.npmjs.com/package/resolve
341-
[`externals`]: https://webpack.github.io/docs/library-and-externals.html
342-
[Node]: https://www.npmjs.com/package/eslint-import-resolver-node
343-
[webpack]: https://www.npmjs.com/package/eslint-import-resolver-webpack
344-
345337
## Settings
346338

347339
You may set the following settings in your `.eslintrc`:
@@ -505,14 +497,11 @@ settings:
505497
lifetime: 5 # 30 is the default
506498
```
507499

508-
[`eslint_d`]: https://www.npmjs.com/package/eslint_d
509-
[`eslint-loader`]: https://www.npmjs.com/package/eslint-loader
510-
511500
### `import-x/internal-regex`
512501

513502
A regex for packages should be treated as internal. Useful when you are utilizing a monorepo setup or developing a set of packages that depend on each other.
514503

515-
By default, any package referenced from [`import-x/external-module-folders`](#importexternal-module-folders) will be considered as "external", including packages in a monorepo like yarn workspace or lerna environment. If you want to mark these packages as "internal" this will be useful.
504+
By default, any package referenced from [`import-x/external-module-folders`](#import-xexternal-module-folders) will be considered as "external", including packages in a monorepo like yarn workspace or lerna environment. If you want to mark these packages as "internal" this will be useful.
516505

517506
For example, if your packages in a monorepo are all in `@scope`, you can configure `import-x/internal-regex` like this
518507

@@ -593,3 +582,12 @@ In Package Settings / SublimeLinter / User Settings:
593582

594583
I believe this defaults to `3`, so you may not need to alter it depending on your
595584
project folder max depth.
585+
586+
[`@typescript-eslint/parser`]: https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser
587+
[`eslint-import-resolver-typescript`]: https://github.com/import-js/eslint-import-resolver-typescript
588+
[`resolve`]: https://www.npmjs.com/package/resolve
589+
[`externals`]: https://webpack.github.io/docs/library-and-externals.html
590+
[Node]: https://www.npmjs.com/package/eslint-import-resolver-node
591+
[webpack]: https://www.npmjs.com/package/eslint-import-resolver-webpack
592+
[`eslint_d`]: https://www.npmjs.com/package/eslint_d
593+
[`eslint-loader`]: https://www.npmjs.com/package/eslint-loader

docs/rules/consistent-type-specifier-style.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ This rule either enforces or bans the use of inline type-only markers for named
3131

3232
This rule includes a fixer that will automatically convert your specifiers to the correct form - however the fixer will not respect your preferences around de-duplicating imports. If this is important to you, consider using the [`import-x/no-duplicates`] rule.
3333

34-
[`import-x/no-duplicates`]: ./no-duplicates.md
35-
3634
## Options
3735

3836
The rule accepts a single string option which may be one of:
@@ -89,3 +87,5 @@ import {typeof Foo} from 'Foo';
8987
If you aren't using Flow or TypeScript 4.5+, then this rule does not apply and need not be used.
9088

9189
If you don't care about, and don't want to standardize how named specifiers are imported then you should not use this rule.
90+
91+
[`import-x/no-duplicates`]: ./no-duplicates.md

docs/rules/default.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ Redux's npm module includes this key, and thereby is lintable, for example.
1616

1717
A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.
1818

19-
[ignored]: ../README.md#importignore
20-
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
21-
2219
## Rule Details
2320

2421
Given:
@@ -78,3 +75,5 @@ either, so such a situation will be reported in the importing module.
7875
[ES7]: https://github.com/leebyron/ecmascript-more-export-from
7976
[`import-x/ignore`]: ../../README.md#importignore
8077
[`jsnext:main`]: https://github.com/rollup/rollup/wiki/jsnext:main
78+
[ignored]: ../../README.md#importignore
79+
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar

docs/rules/dynamic-import-chunkname.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ If you want to allow dynamic imports without a webpackChunkName, you can set `al
103103

104104
Given `{ "allowEmpty": true }`:
105105

106-
<!-- markdownlint-disable-next-line MD024 -- duplicate header -->
106+
<!-- lint disable no-duplicate-headings-in-section -->
107107

108108
### valid
109109

@@ -118,7 +118,7 @@ import(
118118
)
119119
```
120120

121-
<!-- markdownlint-disable-next-line MD024 -- duplicate header -->
121+
<!-- lint disable no-duplicate-headings-in-section -->
122122

123123
### invalid
124124

docs/rules/extensions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ By providing an object you can configure each extension separately.
2222
}]
2323
```
2424

25-
For example `{ "js": "always", "json": "never" }` would always enforce the use of the `.js` extension but never allow the use of the `.json` extension.
25+
For example `{ "js": "always", "json": "never" }` would always enforce the use of the `.js` extension but never allow the use of the `.json` extension.
2626

2727
By providing both a string and an object, the string will set the default setting for all extensions, and the object can be used to set granular overrides for specific extensions.
2828

@@ -66,8 +66,8 @@ For example, given the following folder structure:
6666

6767
```pt
6868
├── foo
69-
   ├── bar.js
70-
   ├── bar.json
69+
├── bar.js
70+
├── bar.json
7171
```
7272

7373
and this import statement:

docs/rules/max-dependencies.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Ignores `type` imports. Type imports are a feature released in TypeScript 3.8, y
4747

4848
Given `{"max": 2, "ignoreTypeImports": true}`:
4949

50-
<!-- markdownlint-disable-next-line MD024 -- duplicate header -->
50+
<!-- lint disable no-duplicate-headings-in-section -->
5151

5252
### Fail
5353

@@ -57,7 +57,7 @@ import b from './b'
5757
import c from './c'
5858
```
5959

60-
<!-- markdownlint-disable-next-line MD024 -- duplicate header -->
60+
<!-- lint disable no-duplicate-headings-in-section -->
6161

6262
### Pass
6363

docs/rules/named.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ Redux's npm module includes this key, and thereby is lintable, for example.
1414

1515
A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported. Note that type imports and exports, as used by [Flow], are always ignored.
1616

17-
[ignored]: ../../README.md#importignore
18-
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
19-
[Flow]: https://flow.org/
20-
2117
## Rule Details
2218

2319
Given:
@@ -100,3 +96,6 @@ runtime, you will likely see false positives with this rule.
10096
[`jsnext:main`]: https://github.com/jsforum/jsforum/issues/5
10197
[`pkg.module`]: https://github.com/rollup/rollup/wiki/pkg.module
10298
[`import-x/ignore`]: ../../README.md#importignore
99+
[ignored]: ../../README.md#importignore
100+
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
101+
[Flow]: https://flow.org/

docs/rules/namespace.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ Redux's npm module includes this key, and thereby is lintable, for example.
1818

1919
A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.
2020

21-
[ignored]: ../README.md#importignore
22-
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
23-
2421
## Rule Details
2522

2623
Currently, this rule does not check for possible
@@ -98,8 +95,10 @@ still can't be statically analyzed any further.
9895

9996
- Lee Byron's [ES7] export proposal
10097
- [`import-x/ignore`] setting
101-
- [`jsnext:main`](Rollup)
98+
- [`jsnext:main`]
10299

103100
[ES7]: https://github.com/leebyron/ecmascript-more-export-from
104101
[`import-x/ignore`]: ../../README.md#importignore
105102
[`jsnext:main`]: https://github.com/rollup/rollup/wiki/jsnext:main
103+
[ignored]: ../../README.md#importignore
104+
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar

docs/rules/no-default-export.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
Prohibit default exports. Mostly an inverse of [`prefer-default-export`].
66

7-
[`prefer-default-export`]: ./prefer-default-export.md
8-
97
## Rule Details
108

119
The following patterns are considered warnings:
@@ -63,3 +61,5 @@ export * from './other-module'
6361
## When Not To Use It
6462

6563
If you don't care if default imports are used, or if you prefer default imports over named imports.
64+
65+
[`prefer-default-export`]: ./prefer-default-export.md

docs/rules/no-mutable-exports.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ want to enable the following core ESLint rules:
4646
- [no-func-assign]
4747
- [no-class-assign]
4848

49-
[no-func-assign]: https://eslint.org/docs/rules/no-func-assign
50-
[no-class-assign]: https://eslint.org/docs/rules/no-class-assign
51-
5249
## When Not To Use It
5350

5451
If your environment correctly implements mutable export bindings.
52+
53+
[no-func-assign]: https://eslint.org/docs/rules/no-func-assign
54+
[no-class-assign]: https://eslint.org/docs/rules/no-class-assign

docs/rules/no-named-as-default-member.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Furthermore, [in Babel 5 this is actually how things worked][blog]. This was
1717
fixed in Babel 6. Before upgrading an existing codebase to Babel 6, it can be
1818
useful to run this lint rule.
1919

20-
[blog]: https://kentcdodds.com/blog/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution
21-
2220
## Rule Details
2321

2422
Given:
@@ -50,3 +48,5 @@ const bar = foo.bar
5048
import foo from './foo.js'
5149
const { bar } = foo
5250
```
51+
52+
[blog]: https://kentcdodds.com/blog/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution

docs/rules/no-named-default.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ Rationale: the syntax exists to import default exports expressively, let's use i
88

99
Note that type imports, as used by [Flow], are always ignored.
1010

11-
[Flow]: https://flow.org/
12-
1311
## Rule Details
1412

1513
Given:
@@ -34,3 +32,5 @@ import foo, { bar } from './foo.js'
3432
import { default as foo } from './foo.js'
3533
import { default as foo, bar } from './foo.js'
3634
```
35+
36+
[Flow]: https://flow.org/

docs/rules/no-named-export.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
Prohibit named exports. Mostly an inverse of [`no-default-export`].
66

7-
[`no-default-export`]: ./no-default-export.md
8-
97
## Rule Details
108

119
The following patterns are considered warnings:
@@ -77,3 +75,5 @@ export default from './other-module'
7775
## When Not To Use It
7876

7977
If you don't care if named imports are used, or if you prefer named imports over default imports.
78+
79+
[`no-default-export`]: ./no-default-export.md

docs/rules/order.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ This rule supports the following options:
102102

103103
### `groups: [array]`
104104

105-
How groups are defined, and the order to respect. `groups` must be an array of `string` or [`string`]. The only allowed `string`s are:
105+
How groups are defined, and the order to respect. `groups` must be an array of `string` or `string[]`. The only allowed `string`s are:
106106
`"builtin"`, `"external"`, `"internal"`, `"unknown"`, `"parent"`, `"sibling"`, `"index"`, `"object"`, `"type"`.
107107
The enforced order is the same as the order of each element in a group. Omitted types are implicitly grouped together as the last element. Example:
108108

@@ -224,6 +224,8 @@ Example:
224224

225225
[Import Type](https://github.com/un-ts/eslint-plugin-import-x/blob/ea7c13eb9b18357432e484b25dfa4451eca69c5b/src/utils/import-type.ts#L145) is resolved as a fixed string in predefined set, it can't be a `patterns` (e.g., `react`, `react-router-dom`, etc).
226226

227+
<!-- lint disable maximum-heading-length -->
228+
227229
### `newlines-between: [ignore|always|always-and-inside-groups|never]`
228230

229231
Enforces or forbids new lines between import groups:
@@ -295,6 +297,8 @@ import index from './'
295297
import sibling from './foo'
296298
```
297299

300+
<!-- lint disable maximum-heading-length -->
301+
298302
### `alphabetize: {order: asc|desc|ignore, orderImportKind: asc|desc|ignore, caseInsensitive: true|false}`
299303

300304
Sort the order within each group in alphabetical manner based on **import path**:

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@1stg/commitlint-config": "^5.0.0",
6565
"@1stg/lint-staged": "^4.0.4",
6666
"@1stg/prettier-config": "^4.0.4",
67+
"@1stg/remark-preset": "^3.0.0",
6768
"@1stg/simple-git-hooks": "^0.2.4",
6869
"@1stg/tsconfig": "^3.0.0",
6970
"@angular-eslint/template-parser": "^19.2.1",
@@ -109,6 +110,7 @@
109110
"eslint-plugin-import-x": "link:.",
110111
"eslint-plugin-jest": "^28.11.0",
111112
"eslint-plugin-json": "^4.0.1",
113+
"eslint-plugin-mdx": "^3.2.0",
112114
"eslint-plugin-n": "^17.16.2",
113115
"eslint-plugin-prettier": "^5.2.3",
114116
"eslint-plugin-unicorn": "^56.0.1",

0 commit comments

Comments
 (0)