Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: experimentally support remark-mdx@2 #284

Merged
merged 6 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module.exports = {
rules: {
// `strictNullChecks` is required
'@typescript-eslint/no-unnecessary-condition': 0,
'unicorn/prefer-export-from': [
2,
{
ignoreUsedVariables: true,
},
],
},
overrides: [
{
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ This project is a [lerna][] monorepo, so packages releasing is controlled by [le
2. You need a GitHub token with a `public_repo` scope as `GH_TOKEN` in the environment to publish
3. Run `yarn release` simply, or `GH_TOKEN=xxx yarn release` to export `GH_TOKEN` at one time.

### Release a bete next version

Run `yarn release-next`

[contributing]: https://mdxjs.com/contributing
[lerna]: https://github.com/lerna/lerna
118 changes: 14 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
- [Usage](#usage)
- [Parser Options](#parser-options)
- [Rules](#rules)
- [mdx/no-jsx-html-comments](#mdxno-jsx-html-comments)
- [mdx/no-unused-expressions](#mdxno-unused-expressions)
- [mdx/remark](#mdxremark)
- [Prettier Integration](#prettier-integration)
- [Changelog](#changelog)
Expand Down Expand Up @@ -74,98 +72,20 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922

## Usage

1. In your ESLint config file:

1. If you're using `eslint >= 6.4.0`, just add:

```jsonc
{
"extends": ["plugin:mdx/recommended"],
// optional, if you want to lint code blocks at the same time
"settings": {
"mdx/code-blocks": true,
// optional, if you want to disable language mapper, set it to `false`
// if you want to override the default language mapper inside, you can provide your own
"mdx/language-mapper": {}
}
}
```

2. If you're using `eslint >=6.0.0 and <6.4.0`, add as following because it does not support overrides from npm pkg:

```jsonc
{
"extends": ["plugin:mdx/recommended"],
// optional, if you want to lint code blocks at the same time
"settings": {
"mdx/code-blocks": true,
// optional, if you want to disable language mapper, set it to `false`
// if you want to override the default language mapper inside, you can provide your own
"mdx/language-mapper": {}
},
"overrides": [
{
"files": ["*.md"],
"rules": {
"prettier/prettier": [
2,
{
// unnecessary if you're not using `eslint-plugin-prettier`, but required if you are
"parser": "markdown"
}
]
}
},
{
"files": ["*.mdx"],
"extends": ["plugin:mdx/overrides"]
},
{
"files": "**/*.{md,mdx}/**",
"extends": "plugin:mdx/code-blocks"
}
]
}
```

3. If you're using `eslint@^5.0.0`, you need to enable this parser/plugin manually, because `eslint@5` does not support `extends` for `overrides` property in its configuration:

```js
const configs = require('eslint-plugin-mdx/lib/configs')

module.exports = {
extends: ['plugin:mdx/recommended'],
// optional, if you want to lint code blocks at the same time
settings: {
'mdx/code-blocks': true,
// optional, if you want to disable language mapper, set it to `false`
// if you want to override the default language mapper inside, you can provide your own
'mdx/language-mapper': {},
},
overrides: [
{
files: ['*.md'],
rules: {
'prettier/prettier': [
2,
{
// unnecessary if you're not using `eslint-plugin-prettier`, but required if you are
parser: 'markdown',
},
],
},
},
{
files: ['*.mdx'],
...configs.overrides,
},
{
files: '**/*.{md,mdx}/**',
...configs.codeBlocks,
},
],
}
```
1. In your ESLint 8+ config file, just add:

```jsonc
{
"extends": ["plugin:mdx/recommended"],
// optional, if you want to lint code blocks at the same time
"settings": {
"mdx/code-blocks": true,
// optional, if you want to disable language mapper, set it to `false`
// if you want to override the default language mapper inside, you can provide your own
"mdx/language-mapper": {}
}
}
```

2. Make sure ESLint knows to run on `.md` or `.mdx` files:

Expand Down Expand Up @@ -194,14 +114,6 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922

## Rules

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

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

### mdx/no-unused-expressions

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

### mdx/remark

_possible fixable depends on your remark plugins_:
Expand All @@ -225,8 +137,6 @@ If you want to disable or change severity of some related rules, it won't work b
}
```

Some plugins are ESM and eslint don't supports them. So, a workaround is to set `ignoreRemarkConfig` to `true` and execute `remark-lint` through the terminal before running eslint. For example: `remark **/*.mdx --no-stdout && eslint . --fix --ext .mdx`.

## Prettier Integration

If you're using [remark-lint][] feature with [Prettier][] both together, you can try [remark-preset-prettier][] which helps you to _turn off all rules that are unnecessary or might conflict with [Prettier][]_.
Expand Down
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"command": {
"version": {
"allowBranch": [
"develop",
"master"
"master",
"next"
]
},
"publish": {
Expand Down
61 changes: 29 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,34 @@
"prelint": "yarn build",
"prerelease": "yarn build",
"release": "lerna publish --conventional-commits --create-release github --yes",
"release-next": "lerna publish --conventional-prerelease --preid next --pre-dist-tag next --yes",
"test": "jest",
"typecov": "type-coverage"
},
"devDependencies": {
"@1stg/lib-config": "^4.1.2",
"@types/eslint": "^7.29.0",
"@1stg/lib-config": "^5.2.0",
"@types/eslint": "^8.4.1",
"@types/eslint-plugin-markdown": "^2.0.0",
"@types/jest": "^27.4.1",
"@types/node": "^16.10.9",
"@types/react": "^17.0.39",
"@types/node": "^17.0.23",
"@types/react": "^17.0.43",
"@types/unist": "^2.0.6",
"lerna": "^4.0.0",
"npm-run-all": "^4.1.5",
"react": "^17.0.2",
"remark-frontmatter": "2",
"remark-validate-links": "^10.0.4",
"ts-jest": "^27.1.3",
"ts-node": "^10.4.0",
"type-coverage": "^2.18.2",
"typescript": "^4.4.4",
"yarn-deduplicate": "^3.1.0"
"remark-frontmatter": "4.0.1",
"remark-lint": "^9.1.1",
"remark-preset-lint-consistent": "^5.1.1",
"remark-preset-lint-markdown-style-guide": "^5.1.2",
"remark-preset-lint-recommended": "^6.1.2",
"remark-preset-prettier": "^1.0.0",
"remark-validate-links": "^11.0.2",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0",
"type-coverage": "^2.21.1",
"typescript": "^4.6.3"
},
"resolutions": {
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.0.0",
"@typescript-eslint/experimental-utils": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-plugin-unicorn": "^37.0.1",
"prettier": "^2.5.1"
"prettier": "^2.6.1"
},
"commitlint": {
"extends": [
Expand Down Expand Up @@ -86,19 +84,18 @@
},
"prettier": "@1stg/prettier-config",
"remarkConfig": {
"settings": {
"emphasis": "_",
"strong": "*"
},
"plugins": [
"remark-frontmatter",
"@1stg/remark-config",
[
"lint-no-duplicate-headings",
[
2
]
],
[
"validate-links",
true
]
"frontmatter",
"lint",
"preset-lint-consistent",
"preset-lint-markdown-style-guide",
"preset-lint-recommended",
"preset-prettier",
"validate-links"
]
},
"renovate": {
Expand All @@ -107,7 +104,7 @@
]
},
"typeCoverage": {
"atLeast": 99.92,
"atLeast": 99.93,
"cache": true,
"detail": true,
"ignoreAsAssertion": true,
Expand Down
Loading