Skip to content

Commit ed82698

Browse files
authored
fix: check is eslint-plugin-react available (#299)
1 parent b825393 commit ed82698

File tree

18 files changed

+315
-306
lines changed

18 files changed

+315
-306
lines changed

.eslintrc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ module.exports = {
2424
{
2525
files: '**/*.{md,mdx}/**',
2626
rules: {
27-
'prettier/prettier': 0,
2827
'unicorn/filename-case': 0,
2928
},
3029
},
3130
{
3231
files: '*.{md,mdx}',
33-
// related to https://github.com/eslint/eslint/issues/14207
3432
rules: {
35-
'prettier/prettier': 0,
3633
'react/no-unescaped-entities': 1,
34+
// related to https://github.com/eslint/eslint/issues/14207
3735
'unicorn/filename-case': 0,
3836
},
3937
settings: {

.huskyrc.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

.simple-git-hooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@1stg/simple-git-hooks')

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922
133133
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:
134134
135135
```js
136-
const { configs } = require('eslint-plugin-mdx')
136+
const configs = require('eslint-plugin-mdx/lib/configs')
137137
138138
module.exports = {
139139
extends: ['plugin:mdx/recommended'],
@@ -251,7 +251,6 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
251251
[1stg.me]: https://www.1stg.me
252252
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
253253
[eslint]: https://eslint.org
254-
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
255254
[jounqin]: https://GitHub.com/JounQin
256255
[lerna]: https://github.com/lerna/lerna
257256
[mdx]: https://github.com/mdx-js/mdx

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@
1717
"lint": "run-p lint:*",
1818
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache --ext js,md,ts -f friendly",
1919
"lint:ts": "tslint -p . -t stylish",
20-
"postinstall": "yarn-deduplicate --strategy fewer || exit 0",
20+
"postinstall": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
2121
"prerelease": "yarn build",
2222
"release": "lerna publish --conventional-commits --create-release github --yes",
2323
"test": "jest",
2424
"typecov": "type-coverage"
2525
},
2626
"devDependencies": {
27-
"@1stg/lib-config": "^1.2.0",
27+
"@1stg/lib-config": "^1.2.4",
2828
"@1stg/tslint-config": "^1.2.0",
2929
"@types/eslint": "^7.2.7",
30-
"@types/jest": "^26.0.20",
30+
"@types/jest": "^26.0.21",
3131
"@types/node": "^14.14.35",
3232
"@types/react": "^17.0.3",
3333
"@types/unist": "^2.0.3",
3434
"eslint-mdx": "link:packages/eslint-mdx/src",
3535
"eslint-plugin-mdx": "link:packages/eslint-plugin-mdx/src",
3636
"lerna": "^4.0.0",
3737
"npm-run-all": "^4.1.5",
38-
"react": "^17.0.1",
39-
"ts-jest": "^26.5.3",
38+
"react": "^17.0.2",
39+
"ts-jest": "^26.5.4",
4040
"ts-node": "^9.1.1",
4141
"tslint": "^6.1.3",
4242
"type-coverage": "^2.17.0",

packages/eslint-mdx/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922
133133
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:
134134
135135
```js
136-
const { configs } = require('eslint-plugin-mdx')
136+
const configs = require('eslint-plugin-mdx/lib/configs')
137137
138138
module.exports = {
139139
extends: ['plugin:mdx/recommended'],
@@ -251,7 +251,6 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
251251
[1stg.me]: https://www.1stg.me
252252
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
253253
[eslint]: https://eslint.org
254-
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
255254
[jounqin]: https://GitHub.com/JounQin
256255
[lerna]: https://github.com/lerna/lerna
257256
[mdx]: https://github.com/mdx-js/mdx

packages/eslint-mdx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"author": "JounQin <[email protected]>",
1212
"license": "MIT",
1313
"engines": {
14-
"node": ">=7.0.0"
14+
"node": ">=10.0.0"
1515
},
1616
"main": "lib/cjs",
1717
"module": "lib",

packages/eslint-plugin-mdx/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922
133133
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:
134134
135135
```js
136-
const { configs } = require('eslint-plugin-mdx')
136+
const configs = require('eslint-plugin-mdx/lib/configs')
137137
138138
module.exports = {
139139
extends: ['plugin:mdx/recommended'],
@@ -251,7 +251,6 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
251251
[1stg.me]: https://www.1stg.me
252252
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
253253
[eslint]: https://eslint.org
254-
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
255254
[jounqin]: https://GitHub.com/JounQin
256255
[lerna]: https://github.com/lerna/lerna
257256
[mdx]: https://github.com/mdx-js/mdx

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { codeBlocks } from './code-blocks'
55
import { overrides } from './overrides'
66
import { recommended } from './recommended'
77

8-
export * from './helpers'
9-
108
export { base, codeBlocks, overrides, recommended }
119

1210
export const configs = {
Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
import type { Linter } from 'eslint'
2+
import { arrayify } from 'eslint-mdx'
23

34
import { base } from './base'
45

6+
let isReactPluginAvailable = false
7+
8+
try {
9+
// eslint-disable-next-line node/no-extraneous-require
10+
require.resolve('eslint-plugin-react')
11+
isReactPluginAvailable = true
12+
} catch {}
13+
514
export const overrides: Linter.Config = {
615
...base,
716
globals: {
8-
React: 'readonly',
17+
React: false,
918
},
19+
plugins: arrayify<string[] | string | null>(
20+
base.plugins,
21+
/* istanbul ignore next */
22+
isReactPluginAvailable ? 'react' : null,
23+
),
1024
rules: {
1125
'lines-between-class-members': 0, // See https://github.com/mdx-js/mdx/issues/195
12-
'react/jsx-no-undef': [
13-
2,
14-
{
15-
allowGlobals: true,
16-
},
17-
],
26+
'react/jsx-no-undef':
27+
/* istanbul ignore next */
28+
isReactPluginAvailable
29+
? [
30+
2,
31+
{
32+
allowGlobals: true,
33+
},
34+
]
35+
: 0,
1836
'react/react-in-jsx-scope': 0,
1937
},
2038
}

0 commit comments

Comments
 (0)