Skip to content

Commit 4b50e27

Browse files
authored
feat: integrate with remark plugins without remark-lint, close #19 (#48)
1 parent f0b3465 commit 4b50e27

File tree

16 files changed

+958
-33
lines changed

16 files changed

+958
-33
lines changed

README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,26 @@
2424

2525
> [ESLint] Parser/Plugin for [MDX], helps you lint all ES syntaxes excluding `code` block of course.
2626
> Work perfectly with `eslint-plugin-import`, `eslint-plugin-prettier` or any other eslint plugins.
27+
> And also can be integrated with [remark] plugins to lint non ES syntaxes.
2728
28-
## VSCode Extension [![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/JounQin.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx)
29+
## TOC <!-- omit in toc -->
30+
31+
- [VSCode Extension](#vscode-extension)
32+
- [Packages](#packages)
33+
- [Install](#install)
34+
- [Usage](#usage)
35+
- [Parser Options](#parser-options)
36+
- [Rules](#rules)
37+
- [mdx/no-jsx-html-comments](#mdxno-jsx-html-comments)
38+
- [mdx/no-unescaped-entities](#mdxno-unescaped-entities)
39+
- [mdx/no-unused-expressions](#mdxno-unused-expressions)
40+
- [mdx/remark](#mdxremark)
41+
- [Changelog](#changelog)
42+
- [License](#license)
43+
44+
## VSCode Extension
45+
46+
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/JounQin.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx)
2947

3048
[VSCode MDX]\: Integrates with [VSCode ESLint], syntaxes highlighting and error reporting.
3149

@@ -110,7 +128,7 @@ npm i -D eslint-plugin-mdx
110128

111129
### mdx/no-jsx-html-comments
112130

113-
HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.
131+
_Fixable_: HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.
114132

115133
### mdx/no-unescaped-entities
116134

@@ -120,28 +138,30 @@ Inline JSX like `Inline <Component />` is supported by [MDX], but rule `react/no
120138

121139
[MDX] can render `jsx` block automatically without exporting them, but [ESLint] will report `no-unused-expressions` issue which could be unexpected, this rule is a replacement of it, so make sure that you've turned off the original `no-unused-expressions` rule.
122140

123-
## Limitation
141+
### mdx/remark
124142

125-
> This parser/plugin can only handle ES syntaxes for you, markdown related syntaxes will just be ignored, you can use [markdownlint] or [remark-lint] to lint that part.
143+
_possible fixable depends on your remark plugins_:
126144

127-
I have a very preliminary idea to integrate with [remark-lint].
145+
Integration with [remark] plugins without [remark-lint], it will read [remark's configuration](https://github.com/remarkjs/remark/tree/master/packages/remark-cli#remark-cli) automatically via [cosmiconfig]. But `.remarkignore` will not be respected, you should use `.eslintignore` instead.
128146

129147
## Changelog
130148

131149
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
132150

133151
## License
134152

135-
[MIT] © [JounQin]@[1stG]
153+
[MIT] © [JounQin]@[1stG.me]
136154

137-
[1stg]: https://www.1stg.me
155+
[1stg.me]: https://www.1stg.me
156+
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
138157
[eslint]: https://eslint.org
139158
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
140159
[jounqin]: https://GitHub.com/JounQin
141160
[lerna]: https://github.com/lerna/lerna
142161
[mdx]: https://github.com/mdx-js/mdx
143162
[mit]: http://opensource.org/licenses/MIT
144163
[markdownlint]: https://github.com/markdownlint/markdownlint
164+
[remark]: https://github.com/remarkjs/remark
145165
[remark-lint]: https://github.com/remarkjs/remark-lint
146166
[vscode eslint]: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
147167
[vscode mdx]: https://github.com/rx-ts/vscode-mdx

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json.schemastore.org/lerna",
3-
"version": "0.11.2",
3+
"version": "1.1.0",
44
"npmClient": "yarn",
55
"useWorkspaces": true,
66
"changelog": {

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@1stg/tsconfig": "^0.1.0",
2525
"@babel/core": "^7.5.5",
2626
"@commitlint/config-conventional": "^8.1.0",
27+
"@types/cosmiconfig": "^5.0.3",
2728
"@types/eslint": "^6.1.0",
2829
"@types/jest": "^24.0.18",
2930
"@types/node": "^12.7.2",
@@ -44,6 +45,8 @@
4445
"lint-staged": "^9.2.3",
4546
"prettier": "1.18.2",
4647
"react": "^16.9.0",
48+
"remark-preset-lint-markdown-style-guide": "^2.1.3",
49+
"remark-preset-lint-recommended": "^3.0.3",
4750
"ts-jest": "^24.0.2",
4851
"ts-node": "^8.3.0",
4952
"type-coverage": "^2.2.0",
@@ -76,6 +79,16 @@
7679
"preset": "ts-jest"
7780
},
7881
"prettier": "@1stg/prettier-config",
82+
"remarkConfig": {
83+
"settings": {
84+
"emphasis": "*",
85+
"strong": "*"
86+
},
87+
"plugins": [
88+
"remark-preset-lint-recommended",
89+
"remark-preset-lint-markdown-style-guide"
90+
]
91+
},
7992
"renovate": {
8093
"extends": [
8194
"@1stg"

packages/eslint-mdx/README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,26 @@
2424

2525
> [ESLint] Parser/Plugin for [MDX], helps you lint all ES syntaxes excluding `code` block of course.
2626
> Work perfectly with `eslint-plugin-import`, `eslint-plugin-prettier` or any other eslint plugins.
27+
> And also can be integrated with [remark] plugins to lint non ES syntaxes.
2728
28-
## VSCode Extension [![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/JounQin.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx)
29+
## TOC <!-- omit in toc -->
30+
31+
- [VSCode Extension](#vscode-extension)
32+
- [Packages](#packages)
33+
- [Install](#install)
34+
- [Usage](#usage)
35+
- [Parser Options](#parser-options)
36+
- [Rules](#rules)
37+
- [mdx/no-jsx-html-comments](#mdxno-jsx-html-comments)
38+
- [mdx/no-unescaped-entities](#mdxno-unescaped-entities)
39+
- [mdx/no-unused-expressions](#mdxno-unused-expressions)
40+
- [mdx/remark](#mdxremark)
41+
- [Changelog](#changelog)
42+
- [License](#license)
43+
44+
## VSCode Extension
45+
46+
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/JounQin.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx)
2947

3048
[VSCode MDX]\: Integrates with [VSCode ESLint], syntaxes highlighting and error reporting.
3149

@@ -110,7 +128,7 @@ npm i -D eslint-plugin-mdx
110128

111129
### mdx/no-jsx-html-comments
112130

113-
HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.
131+
_Fixable_: HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.
114132

115133
### mdx/no-unescaped-entities
116134

@@ -120,28 +138,30 @@ Inline JSX like `Inline <Component />` is supported by [MDX], but rule `react/no
120138

121139
[MDX] can render `jsx` block automatically without exporting them, but [ESLint] will report `no-unused-expressions` issue which could be unexpected, this rule is a replacement of it, so make sure that you've turned off the original `no-unused-expressions` rule.
122140

123-
## Limitation
141+
### mdx/remark
124142

125-
> This parser/plugin can only handle ES syntaxes for you, markdown related syntaxes will just be ignored, you can use [markdownlint] or [remark-lint] to lint that part.
143+
_possible fixable depends on your remark plugins_:
126144

127-
I have a very preliminary idea to integrate with [remark-lint].
145+
Integration with [remark] plugins without [remark-lint], it will read [remark's configuration](https://github.com/remarkjs/remark/tree/master/packages/remark-cli#remark-cli) automatically via [cosmiconfig]. But `.remarkignore` will not be respected, you should use `.eslintignore` instead.
128146

129147
## Changelog
130148

131149
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
132150

133151
## License
134152

135-
[MIT] © [JounQin]@[1stG]
153+
[MIT] © [JounQin]@[1stG.me]
136154

137-
[1stg]: https://www.1stg.me
155+
[1stg.me]: https://www.1stg.me
156+
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
138157
[eslint]: https://eslint.org
139158
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
140159
[jounqin]: https://GitHub.com/JounQin
141160
[lerna]: https://github.com/lerna/lerna
142161
[mdx]: https://github.com/mdx-js/mdx
143162
[mit]: http://opensource.org/licenses/MIT
144163
[markdownlint]: https://github.com/markdownlint/markdownlint
164+
[remark]: https://github.com/remarkjs/remark
145165
[remark-lint]: https://github.com/remarkjs/remark-lint
146166
[vscode eslint]: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
147167
[vscode mdx]: https://github.com/rx-ts/vscode-mdx

packages/eslint-mdx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-mdx",
3-
"version": "0.11.2",
3+
"version": "1.1.0",
44
"description": "ESLint Parser for MDX",
55
"repository": "[email protected]:rx-ts/eslint-mdx.git",
66
"author": "JounQin <[email protected]>",

packages/eslint-mdx/src/parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class Parser {
108108
const endLineOffset = endLines.length - 1
109109
comments.push({
110110
fixed,
111+
// ! eslint ast column is 0-indexed, but unified is 1-indexed
111112
loc: {
112113
start: {
113114
line: line + startLineOffset,
@@ -157,6 +158,7 @@ export class Parser {
157158
comments: [],
158159
tokens: [],
159160
}
161+
160162
this._services = {
161163
JSXElementsWithHTMLComments: [],
162164
}

packages/eslint-plugin-mdx/README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,26 @@
2424

2525
> [ESLint] Parser/Plugin for [MDX], helps you lint all ES syntaxes excluding `code` block of course.
2626
> Work perfectly with `eslint-plugin-import`, `eslint-plugin-prettier` or any other eslint plugins.
27+
> And also can be integrated with [remark] plugins to lint non ES syntaxes.
2728
28-
## VSCode Extension [![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/JounQin.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx)
29+
## TOC <!-- omit in toc -->
30+
31+
- [VSCode Extension](#vscode-extension)
32+
- [Packages](#packages)
33+
- [Install](#install)
34+
- [Usage](#usage)
35+
- [Parser Options](#parser-options)
36+
- [Rules](#rules)
37+
- [mdx/no-jsx-html-comments](#mdxno-jsx-html-comments)
38+
- [mdx/no-unescaped-entities](#mdxno-unescaped-entities)
39+
- [mdx/no-unused-expressions](#mdxno-unused-expressions)
40+
- [mdx/remark](#mdxremark)
41+
- [Changelog](#changelog)
42+
- [License](#license)
43+
44+
## VSCode Extension
45+
46+
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/JounQin.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx)
2947

3048
[VSCode MDX]\: Integrates with [VSCode ESLint], syntaxes highlighting and error reporting.
3149

@@ -110,7 +128,7 @@ npm i -D eslint-plugin-mdx
110128

111129
### mdx/no-jsx-html-comments
112130

113-
HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.
131+
_Fixable_: HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.
114132

115133
### mdx/no-unescaped-entities
116134

@@ -120,28 +138,30 @@ Inline JSX like `Inline <Component />` is supported by [MDX], but rule `react/no
120138

121139
[MDX] can render `jsx` block automatically without exporting them, but [ESLint] will report `no-unused-expressions` issue which could be unexpected, this rule is a replacement of it, so make sure that you've turned off the original `no-unused-expressions` rule.
122140

123-
## Limitation
141+
### mdx/remark
124142

125-
> This parser/plugin can only handle ES syntaxes for you, markdown related syntaxes will just be ignored, you can use [markdownlint] or [remark-lint] to lint that part.
143+
_possible fixable depends on your remark plugins_:
126144

127-
I have a very preliminary idea to integrate with [remark-lint].
145+
Integration with [remark] plugins without [remark-lint], it will read [remark's configuration](https://github.com/remarkjs/remark/tree/master/packages/remark-cli#remark-cli) automatically via [cosmiconfig]. But `.remarkignore` will not be respected, you should use `.eslintignore` instead.
128146

129147
## Changelog
130148

131149
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
132150

133151
## License
134152

135-
[MIT] © [JounQin]@[1stG]
153+
[MIT] © [JounQin]@[1stG.me]
136154

137-
[1stg]: https://www.1stg.me
155+
[1stg.me]: https://www.1stg.me
156+
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
138157
[eslint]: https://eslint.org
139158
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
140159
[jounqin]: https://GitHub.com/JounQin
141160
[lerna]: https://github.com/lerna/lerna
142161
[mdx]: https://github.com/mdx-js/mdx
143162
[mit]: http://opensource.org/licenses/MIT
144163
[markdownlint]: https://github.com/markdownlint/markdownlint
164+
[remark]: https://github.com/remarkjs/remark
145165
[remark-lint]: https://github.com/remarkjs/remark-lint
146166
[vscode eslint]: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
147167
[vscode mdx]: https://github.com/rx-ts/vscode-mdx

packages/eslint-plugin-mdx/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-mdx",
3-
"version": "0.11.2",
3+
"version": "1.1.0",
44
"description": "ESLint Plugin for MDX",
55
"repository": "[email protected]:rx-ts/eslint-mdx.git",
66
"author": "JounQin <[email protected]>",
@@ -22,7 +22,9 @@
2222
"eslint-plugin-react": ">=7.0.0"
2323
},
2424
"dependencies": {
25-
"eslint-mdx": "^0.11.2",
26-
"rebass": "^4.0.2"
25+
"cosmiconfig": "^5.2.1",
26+
"eslint-mdx": "^1.1.0",
27+
"rebass": "^4.0.2",
28+
"remark-stringify": "^7.0.2"
2729
}
2830
}

packages/eslint-plugin-mdx/src/configs/recommended.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const recommended = {
66
'mdx/no-jsx-html-comments': 2,
77
'mdx/no-unescaped-entities': 1,
88
'mdx/no-unused-expressions': 2,
9+
'mdx/remark': 1,
910
'no-unused-expressions': 0,
1011
'react/no-unescaped-entities': 0,
1112
},
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { noJsxHtmlComments } from './no-jsx-html-comments'
22
import { noUnescapedEntities } from './no-unescaped-entities'
33
import { noUnusedExpressions } from './no-unused-expressions'
4+
import { remark } from './remark'
45

56
export * from './types'
67

7-
export { noJsxHtmlComments, noUnescapedEntities, noUnusedExpressions }
8+
export { noJsxHtmlComments, noUnescapedEntities, noUnusedExpressions, remark }
89

910
export const rules = {
1011
'no-jsx-html-comments': noJsxHtmlComments,
1112
'no-unescaped-entities': noUnescapedEntities,
1213
'no-unused-expressions': noUnusedExpressions,
14+
remark,
1315
}

0 commit comments

Comments
 (0)