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

fix: check is eslint-plugin-react available #298

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ module.exports = {
{
files: '**/*.{md,mdx}/**',
rules: {
'prettier/prettier': 0,
'unicorn/filename-case': 0,
},
},
{
files: '*.{md,mdx}',
// related to https://github.com/eslint/eslint/issues/14207
rules: {
'prettier/prettier': 0,
'react/no-unescaped-entities': 1,
// related to https://github.com/eslint/eslint/issues/14207
'unicorn/filename-case': 0,
},
settings: {
Expand Down
1 change: 0 additions & 1 deletion .huskyrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .simple-git-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@1stg/simple-git-hooks')
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922
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')
const configs = require('eslint-plugin-mdx/lib/configs')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not include ESLinter.prototype.verify hack here which will emits error.


module.exports = {
extends: ['plugin:mdx/recommended'],
Expand Down Expand Up @@ -251,7 +251,6 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
[1stg.me]: https://www.1stg.me
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
[eslint]: https://eslint.org
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
[jounqin]: https://github.com/JounQin
[lerna]: https://github.com/lerna/lerna
[mdx]: https://github.com/mdx-js/mdx
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
"lint": "run-p lint:*",
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache --ext js,md,ts -f friendly",
"lint:ts": "tslint -p . -t stylish",
"postinstall": "yarn-deduplicate --strategy fewer || exit 0",
"postinstall": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"prerelease": "yarn build",
"release": "lerna publish --conventional-commits --create-release github --yes",
"test": "jest",
"typecov": "type-coverage"
},
"devDependencies": {
"@1stg/lib-config": "^1.2.0",
"@1stg/lib-config": "^1.2.4",
"@1stg/tslint-config": "^1.2.0",
"@types/eslint": "^7.2.7",
"@types/jest": "^26.0.20",
"@types/jest": "^26.0.21",
"@types/node": "^14.14.35",
"@types/react": "^17.0.3",
"@types/unist": "^2.0.3",
"eslint-mdx": "link:packages/eslint-mdx/src",
"eslint-plugin-mdx": "link:packages/eslint-plugin-mdx/src",
"lerna": "^4.0.0",
"npm-run-all": "^4.1.5",
"react": "^17.0.1",
"ts-jest": "^26.5.3",
"react": "^17.0.2",
"ts-jest": "^26.5.4",
"ts-node": "^9.1.1",
"tslint": "^6.1.3",
"type-coverage": "^2.17.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-mdx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922
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')
const configs = require('eslint-plugin-mdx/lib/configs')

module.exports = {
extends: ['plugin:mdx/recommended'],
Expand Down Expand Up @@ -251,7 +251,6 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
[1stg.me]: https://www.1stg.me
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
[eslint]: https://eslint.org
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
[jounqin]: https://github.com/JounQin
[lerna]: https://github.com/lerna/lerna
[mdx]: https://github.com/mdx-js/mdx
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "JounQin <admin@1stg.me>",
"license": "MIT",
"engines": {
"node": ">=7.0.0"
"node": ">=10.0.0"
},
"main": "lib/cjs",
"module": "lib",
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin-mdx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922
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')
const configs = require('eslint-plugin-mdx/lib/configs')

module.exports = {
extends: ['plugin:mdx/recommended'],
Expand Down Expand Up @@ -251,7 +251,6 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
[1stg.me]: https://www.1stg.me
[cosmiconfig]: https://github.com/davidtheclark/cosmiconfig
[eslint]: https://eslint.org
[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react
[jounqin]: https://github.com/JounQin
[lerna]: https://github.com/lerna/lerna
[mdx]: https://github.com/mdx-js/mdx
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-plugin-mdx/src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { codeBlocks } from './code-blocks'
import { overrides } from './overrides'
import { recommended } from './recommended'

export * from './helpers'

export { base, codeBlocks, overrides, recommended }

export const configs = {
Expand Down
32 changes: 25 additions & 7 deletions packages/eslint-plugin-mdx/src/configs/overrides.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import type { Linter } from 'eslint'
import { arrayify } from 'eslint-mdx'

import { base } from './base'

let isReactPluginAvailable = false

try {
// eslint-disable-next-line node/no-extraneous-require
require.resolve('eslint-plugin-react')
isReactPluginAvailable = true
} catch {}

export const overrides: Linter.Config = {
...base,
globals: {
React: 'readonly',
React: false,
},
plugins: arrayify<string[] | string | null>(
base.plugins,
/* istanbul ignore next */
isReactPluginAvailable ? 'react' : null,
),
rules: {
'lines-between-class-members': 0, // See https://github.com/mdx-js/mdx/issues/195
'react/jsx-no-undef': [
2,
{
allowGlobals: true,
},
],
'react/jsx-no-undef':
/* istanbul ignore next */
isReactPluginAvailable
? [
2,
{
allowGlobals: true,
},
]
: 0,
'react/react-in-jsx-scope': 0,
},
}
33 changes: 23 additions & 10 deletions packages/eslint-plugin-mdx/src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,30 @@ if (minorVersion >= OVERRIDES_AVAILABLE_VERSION) {
require.resolve('prettier')
// eslint-disable-next-line node/no-extraneous-require
require.resolve('eslint-plugin-prettier')
overrides.push({
files: '*.md',
rules: {
'prettier/prettier': [
2,
{
parser: 'markdown',
},
],
overrides.push(
{
files: '*.md',
rules: {
'prettier/prettier': [
2,
{
parser: 'markdown',
},
],
},
},
})
{
files: '*.mdx',
rules: {
'prettier/prettier': [
2,
{
parser: 'mdx',
},
],
},
},
)
} catch {}
Object.assign(recommended, {
overrides,
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-mdx/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './configs'
export * from './helpers'
export * from './processors'
export * from './rules'
16 changes: 12 additions & 4 deletions test/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ Array [
"endLine": 27,
"fix": Object {
"range": Array [
548,
563,
550,
565,
],
"text": "# Hello, world!",
},
Expand All @@ -140,6 +140,7 @@ Array [
"endLine": 31,
"line": 31,
"message": "'Tweet' is not defined.",
"messageId": "undefined",
"nodeType": "JSXIdentifier",
"ruleId": "react/jsx-no-undef",
"severity": 2,
Expand All @@ -150,6 +151,7 @@ Array [
"endLine": 33,
"line": 33,
"message": "'TextGradient' is not defined.",
"messageId": "undefined",
"nodeType": "JSXIdentifier",
"ruleId": "react/jsx-no-undef",
"severity": 2,
Expand All @@ -160,8 +162,8 @@ Array [
"endLine": 35,
"fix": Object {
"range": Array [
651,
686,
653,
688,
],
"text": "# Here's a text gradient shortcode!",
},
Expand All @@ -175,6 +177,7 @@ Array [
"column": 7,
"line": 35,
"message": "\`'\` can be escaped with \`&apos;\`, \`&lsquo;\`, \`&#39;\`, \`&rsquo;\`.",
"messageId": "unescapedEntityAlts",
"nodeType": "JSXText",
"ruleId": "react/no-unescaped-entities",
"severity": 1,
Expand All @@ -185,6 +188,7 @@ Array [
"endLine": 41,
"line": 41,
"message": "'YouTube' is not defined.",
"messageId": "undefined",
"nodeType": "JSXIdentifier",
"ruleId": "react/jsx-no-undef",
"severity": 2,
Expand Down Expand Up @@ -237,6 +241,7 @@ Array [
"column": 290,
"line": 3,
"message": "\`'\` can be escaped with \`&apos;\`, \`&lsquo;\`, \`&#39;\`, \`&rsquo;\`.",
"messageId": "unescapedEntityAlts",
"nodeType": "JSXText",
"ruleId": "react/no-unescaped-entities",
"severity": 1,
Expand All @@ -245,6 +250,7 @@ Array [
"column": 5,
"line": 5,
"message": "\`'\` can be escaped with \`&apos;\`, \`&lsquo;\`, \`&#39;\`, \`&rsquo;\`.",
"messageId": "unescapedEntityAlts",
"nodeType": "JSXText",
"ruleId": "react/no-unescaped-entities",
"severity": 1,
Expand All @@ -266,6 +272,7 @@ Array [
"column": 8,
"line": 2,
"message": "\`>\` can be escaped with \`&gt;\`.",
"messageId": "unescapedEntityAlts",
"nodeType": "JSXText",
"ruleId": "react/no-unescaped-entities",
"severity": 1,
Expand All @@ -274,6 +281,7 @@ Array [
"column": 13,
"line": 5,
"message": "\`>\` can be escaped with \`&gt;\`.",
"messageId": "unescapedEntityAlts",
"nodeType": "JSXText",
"ruleId": "react/no-unescaped-entities",
"severity": 1,
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Helpers', () => {
})

it('should resolve package correctly', () => {
expect(requirePkg('@1stg/config', 'husky')).toBeDefined()
expect(requirePkg('@1stg/config', 'commitlint')).toBeDefined()
expect(requirePkg('lint', 'remark')).toBeDefined()
expect(requirePkg('remark-parse', 'non existed')).toBeDefined()
expect(
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./node_modules/@1stg/tsconfig/lib.json",
"compilerOptions": {
"module": "CommonJS",
"strictFunctionTypes": false,
"strictNullChecks": false
}
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"noEmit": true
},
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
},
"transpileOnly": true
},
"references": [
Expand Down
Loading