From 0281fb3e26612af0d52af5525dd94bfa64edec1a Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 23 Sep 2019 17:02:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20react=20could=20be=20unavailable,=20add?= =?UTF-8?q?=20hardcoded=20component=20names=20to=E2=80=A6=20(#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .travis.yml | 6 +-- package.json | 2 +- packages/eslint-mdx/package.json | 14 ++--- packages/eslint-mdx/tsconfig.json | 2 +- packages/eslint-plugin-mdx/package.json | 22 ++++---- .../src/configs/overrides.ts | 13 ++++- .../src/configs/recommended.ts | 5 +- packages/eslint-plugin-mdx/tsconfig.json | 3 +- packages/eslint-plugin-mdx/typings.d.ts | 6 +++ tsconfig.json | 2 +- tslint.json | 5 +- yarn.lock | 53 +++++++++---------- 13 files changed, 77 insertions(+), 59 deletions(-) diff --git a/.gitignore b/.gitignore index aa98c13f..770ed253 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ *.log +*.tsbuildinfo .changelog .type-coverage coverage lib node_modules -tsconfig.tsbuildinfo -test.* diff --git a/.travis.yml b/.travis.yml index f571ae0b..316064fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,9 @@ script: - yarn test after_success: - - yarn global add codecov + - yarn global add codecov codacy-coverage - codecov + - cat ./coverage/lcov.info | codacy-coverage before_deploy: - npm set //registry.npmjs.org/:_authToken $NPM_TOKEN @@ -49,6 +50,5 @@ deploy: branch: develop after_script: - - yarn add -D @codechecks/client @codechecks/build-size-watcher @codechecks/type-coverage-watcher codacy-coverage -W + - yarn add -D @codechecks/client @codechecks/build-size-watcher @codechecks/type-coverage-watcher -W - yarn codechecks - - cat ./coverage/lcov.info | yarn codacy-coverage diff --git a/package.json b/package.json index 73167a68..0c131b96 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "jest": "^24.9.0", "lerna": "^3.16.4", "lerna-changelog": "^0.8.2", - "lint-staged": "^9.2.5", + "lint-staged": "^9.3.0", "npm-run-all": "^4.1.5", "prettier": "1.18.2", "react": "^16.9.0", diff --git a/packages/eslint-mdx/package.json b/packages/eslint-mdx/package.json index fb12c6ee..28a0a5ab 100644 --- a/packages/eslint-mdx/package.json +++ b/packages/eslint-mdx/package.json @@ -2,13 +2,13 @@ "name": "eslint-mdx", "version": "1.5.2", "description": "ESLint Parser for MDX", - "repository": { - "type": "git", - "url": "https://github.com/rx-ts/eslint-mdx.git", - "directory": "packages/eslint-mdx" - }, + "repository": "git+https://github.com/rx-ts/eslint-mdx.git", + "homepage": "https://github.com/rx-ts/eslint-mdx/blob/master/packages/eslint-mdx", "author": "JounQin ", "license": "MIT", + "engines": { + "node": ">=7.0.0" + }, "main": "lib", "files": [ "lib", @@ -26,8 +26,8 @@ }, "dependencies": { "espree": "^6.1.1", - "remark-mdx": "^1.4.4", + "remark-mdx": "^1.4.5", "remark-parse": "^7.0.1", - "unified": "^8.3.2" + "unified": "^8.4.0" } } diff --git a/packages/eslint-mdx/tsconfig.json b/packages/eslint-mdx/tsconfig.json index dc8fb03d..abb61bbb 100644 --- a/packages/eslint-mdx/tsconfig.json +++ b/packages/eslint-mdx/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.base.json", + "extends": "../../tsconfig.base", "compilerOptions": { "composite": true, "rootDir": "src", diff --git a/packages/eslint-plugin-mdx/package.json b/packages/eslint-plugin-mdx/package.json index 7ab4ceef..b2bbaaab 100644 --- a/packages/eslint-plugin-mdx/package.json +++ b/packages/eslint-plugin-mdx/package.json @@ -2,13 +2,13 @@ "name": "eslint-plugin-mdx", "version": "1.5.2", "description": "ESLint Plugin for MDX", - "repository": { - "type": "git", - "url": "https://github.com/rx-ts/eslint-mdx.git", - "directory": "packages/eslint-plugin-mdx" - }, + "repository": "git+https://github.com/rx-ts/eslint-mdx.git", + "homepage": "https://github.com/rx-ts/eslint-mdx/blob/master/packages/eslint-plugin-mdx", "author": "JounQin ", "license": "MIT", + "engines": { + "node": ">=7.0.0" + }, "main": "lib", "files": [ "lib", @@ -22,17 +22,19 @@ "eslint-mdx" ], "peerDependencies": { - "eslint": ">=5.0.0", - "eslint-plugin-react": ">=7.0.0" + "eslint": ">=5.0.0" }, "dependencies": { "cosmiconfig": "^5.2.1", "eslint-mdx": "^1.5.2", - "rebass": "^4.0.5", - "remark-mdx": "^1.4.4", + "eslint-plugin-react": ">=7.0.0", + "remark-mdx": "^1.4.5", "remark-parse": "^7.0.1", "remark-stringify": "^7.0.3", - "unified": "^8.3.2", + "unified": "^8.4.0", "vfile": "^4.0.1" + }, + "optionalDependencies": { + "rebass": "^4.0.6" } } diff --git a/packages/eslint-plugin-mdx/src/configs/overrides.ts b/packages/eslint-plugin-mdx/src/configs/overrides.ts index 3c0a5caf..971c5472 100644 --- a/packages/eslint-plugin-mdx/src/configs/overrides.ts +++ b/packages/eslint-plugin-mdx/src/configs/overrides.ts @@ -1,8 +1,17 @@ -import * as rebass from 'rebass' - import { base } from './base' import { getGlobals } from './helper' +let rebass: typeof import('rebass') | string[] + +try { + // eslint-disable-next-line @typescript-eslint/no-require-imports + rebass = require('rebass') +} catch { + // `rebass`(or `reflexbox` actually) requires `react` as peerDependency, but not all projects using `mdx` are `React` based, so we fallback to hardcoded `rebass` Components here + /* istanbul ignore next */ + rebass = ['Box', 'Flex', 'Text', 'Heading', 'Link', 'Button', 'Image', 'Card'] +} + export const overrides = { ...base, globals: getGlobals(rebass, { diff --git a/packages/eslint-plugin-mdx/src/configs/recommended.ts b/packages/eslint-plugin-mdx/src/configs/recommended.ts index df55d4c9..2aac3aa9 100644 --- a/packages/eslint-plugin-mdx/src/configs/recommended.ts +++ b/packages/eslint-plugin-mdx/src/configs/recommended.ts @@ -19,10 +19,11 @@ export const recommended = { }, } +const OVERRIDES_AVAILABLE_VERSION = 6.4 + // overrides in npm pkg is supported after v6.4.0 // istanbul ignore else -// eslint-disable-next-line @typescript-eslint/no-magic-numbers -if (minorVersion >= 6.4) { +if (minorVersion >= OVERRIDES_AVAILABLE_VERSION) { const overrides: Array<{ files: string | string[] extends?: string | string[] diff --git a/packages/eslint-plugin-mdx/tsconfig.json b/packages/eslint-plugin-mdx/tsconfig.json index dc8fb03d..5c32854e 100644 --- a/packages/eslint-plugin-mdx/tsconfig.json +++ b/packages/eslint-plugin-mdx/tsconfig.json @@ -1,6 +1,7 @@ { - "extends": "../../tsconfig.base.json", + "extends": "../../tsconfig.base", "compilerOptions": { + "baseUrl": ".", "composite": true, "rootDir": "src", "outDir": "lib" diff --git a/packages/eslint-plugin-mdx/typings.d.ts b/packages/eslint-plugin-mdx/typings.d.ts index 606a7fec..f6160f6d 100644 --- a/packages/eslint-plugin-mdx/typings.d.ts +++ b/packages/eslint-plugin-mdx/typings.d.ts @@ -9,3 +9,9 @@ declare module 'eslint-plugin-react/lib/rules/no-unescaped-entities' { const reactNoUnescapedEntities: Rule.RuleModule export = reactNoUnescapedEntities } + +declare module 'remark-mdx' { + import * as unified from 'unified' + const mdx: unified.Attacher + export = mdx +} diff --git a/tsconfig.json b/tsconfig.json index 4f9d00e3..05c1f614 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.base.json", + "extends": "./tsconfig.base", "references": [ { "path": "packages/eslint-mdx" diff --git a/tslint.json b/tslint.json index 59a8d6a0..eb66ff81 100644 --- a/tslint.json +++ b/tslint.json @@ -1,9 +1,10 @@ { "extends": "@1stg/tslint-config", "rules": { - "no-reference": false + "no-reference": false, + "no-var-requires": false }, "linterOptions": { - "exclude": ["node_modules/**", "**/lib/**"] + "exclude": ["node_modules/**", "**/lib/**", "**/*.d.ts"] } } diff --git a/yarn.lock b/yarn.lock index df94837d..6697f05a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4479,7 +4479,7 @@ eslint-plugin-react-hooks@^2.0.1: resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-2.0.1.tgz#e898ec26a0a335af6f7b0ad1f0bedda7143ed756" integrity sha512-xir+3KHKo86AasxlCV8AHRtIZPHljqCRRUYgASkbatmt0fad4+5GgC7zkT7o/06hdKM6MIwp8giHVXqBPaarHQ== -eslint-plugin-react@^7.14.3: +eslint-plugin-react@>=7.0.0, eslint-plugin-react@^7.14.3: version "7.14.3" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.14.3.tgz#911030dd7e98ba49e1b2208599571846a66bdf13" integrity sha512-EzdyyBWC4Uz2hPYBiEJrKCUi2Fn+BJ9B/pJQcjw5X+x/H2Nm59S4MJIvL4O5NEE0+WbnQwEBxWY03oUk+Bc3FA== @@ -5212,9 +5212,9 @@ glob-parent@^3.1.0: path-dirname "^1.0.0" glob-parent@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.0.0.tgz#1dc99f0f39b006d3e92c2c284068382f0c20e954" - integrity sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg== + version "5.1.0" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.0.tgz#5f4c1d1e748d30cd73ad2944b3577a81b081e8c2" + integrity sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw== dependencies: is-glob "^4.0.1" @@ -6596,10 +6596,10 @@ lines-and-columns@^1.1.6: resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= -lint-staged@^9.2.5: - version "9.2.5" - resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.2.5.tgz#5a3e1e0a539a403bd7f88542bc3d34ce52efdbb3" - integrity sha512-d99gTBFMJ29159+9iRvaMEQstmNcPAbQbhHSYw6D/1FncvFdIj8lWHztaq3Uq+tbZPABHXQ/fyN7Rp1QwF8HIw== +lint-staged@^9.3.0: + version "9.3.0" + resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-9.3.0.tgz#522a79f166050ab5777887348f2cbdb03f71acac" + integrity sha512-OuL3xo6XpBErl16+3W9PdnFmgeGp12lM8I1Ii/B56S8Edy1kyrf4W8VD4IBn9v17QlutRQEWUJ54YF/VVQ7J2A== dependencies: chalk "^2.4.2" commander "^2.20.0" @@ -7149,9 +7149,9 @@ minimist@~0.0.1: integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8= minipass@^2.2.1, minipass@^2.3.5, minipass@^2.6.0, minipass@^2.6.4: - version "2.6.5" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.6.5.tgz#1c245f9f2897f70fd4a219066261ce6c29f80b18" - integrity sha512-ewSKOPFH9blOLXx0YSE+mbrNMBFPS+11a2b03QZ+P4LVrUHW/GAlqeYC7DBknDyMWkHzrzTpDhUvy7MUxqyrPA== + version "2.8.1" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.8.1.tgz#a73bdc84cad62e8e6c8d56eba1302a5fe04c5910" + integrity sha512-QCG523ParRcE2+9A6wYh9UI3uy2FFLw4DQaVYQrY5HPfszc5M6VDD+j0QCwHm19LI2imes4RB+NBD8cOJccyCg== dependencies: safe-buffer "^5.1.2" yallist "^3.0.0" @@ -8278,7 +8278,7 @@ react-is@^16.8.1, react-is@^16.8.4: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb" integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw== -react@^16.8.6, react@^16.9.0: +react@^16.9.0: version "16.9.0" resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa" integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w== @@ -8430,12 +8430,12 @@ realpath-native@^1.1.0: dependencies: util.promisify "^1.0.0" -rebass@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/rebass/-/rebass-4.0.5.tgz#87bf5b0cc53e530ce0939611637d01aeb989df57" - integrity sha512-8MZngk/AmbC8u8pGmI1WelbsKYjmN9Z91C11G4ESB9QZnoppWsI+OAqio1/4/l6dxHmwZ/hR8Q4UApF+IVEprA== +rebass@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/rebass/-/rebass-4.0.6.tgz#eaded5d0d99f68e69cd6b1e9e645f391c15d90dd" + integrity sha512-O4eSG4vhboiI00R5YmrRTuKiehpLkB3gDBWp00qymEbPxJPjkXoQVkOEhbWaRNRqBv/bMlvLczqarvCno1JORw== dependencies: - reflexbox "^4.0.5" + reflexbox "^4.0.6" redent@^1.0.0: version "1.0.0" @@ -8453,16 +8453,15 @@ redent@^2.0.0: indent-string "^3.0.0" strip-indent "^2.0.0" -reflexbox@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/reflexbox/-/reflexbox-4.0.5.tgz#63a53702a111d16df6b1f0d6363b86be8ebc1fc6" - integrity sha512-SFWlrlKusgQVqjEimlLGNls3khjMlaTLrrF1H7YY7FfXv/mKK5mREDOW4l95D6Qa1kGoyM3hF+H5RLb3N6bCCA== +reflexbox@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/reflexbox/-/reflexbox-4.0.6.tgz#fc756d2cc1ca493baf9b96bb27dd640ad8154cf1" + integrity sha512-UNUL4YoJEXAPjRKHuty1tuOk+LV1nDJ2KYViDcH7lYm5yU3AQ+EKNXxPU3E14bQNK/pE09b1hYl+ZKdA94tWLQ== dependencies: "@emotion/core" "^10.0.0" "@emotion/styled" "^10.0.0" "@styled-system/css" "^5.0.0" "@styled-system/should-forward-prop" "^5.0.0" - react "^16.8.6" styled-system "^5.0.0" regenerate-unicode-properties@^8.1.0: @@ -9074,7 +9073,7 @@ remark-lint@^6.0.0, remark-lint@^6.0.5: dependencies: remark-message-control "^4.0.0" -remark-mdx@^1.4.4: +remark-mdx@^1.4.5: version "1.4.5" resolved "https://registry.yarnpkg.com/remark-mdx/-/remark-mdx-1.4.5.tgz#4701cad33c6a4a0465514f39a7dbe9ee7715139f" integrity sha512-Njjly0I6l7WAe+ob2qQ3K393rtkyJLjbaZOn84CE2P6nQRzei5PlNRn6DH5SfCzdzP7llHZbW+CVsj989kd/Wg== @@ -9211,9 +9210,9 @@ remark-preset-lint-recommended@^3.0.3: remark-lint-ordered-list-marker-style "^1.0.0" remark-preset-prettier@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/remark-preset-prettier/-/remark-preset-prettier-0.2.0.tgz#cb369b86ce7d7980e90879fe468bae501fc06969" - integrity sha512-JC79MERKMoOrokjCsnMe1RXxH5KrZ2veg5eGRDzUbfKliXSTVMMvvw3PoZ5Gng8MhPrpOd+DkE+jpu937aS/wQ== + version "0.2.1" + resolved "https://registry.yarnpkg.com/remark-preset-prettier/-/remark-preset-prettier-0.2.1.tgz#00de65b8f3817428ba79aa535ee230530d0afd70" + integrity sha512-CH3CQi9sU1vrJGGmW4/+JlazpRsXJMaZYjmNmKyk58e7TUfKjE2VNVLJI8AIhA3G5sKZhEgD7FgmdIdp9Bxrsw== remark-stringify@^7.0.3: version "7.0.3" @@ -10502,7 +10501,7 @@ unified@8.3.2: trough "^1.0.0" vfile "^4.0.0" -unified@^8.3.2: +unified@^8.4.0: version "8.4.0" resolved "https://registry.yarnpkg.com/unified/-/unified-8.4.0.tgz#5bb8a05c2a0b9dcc56152312ad8e4578a0d90af7" integrity sha512-hQqeCrzqqS3vk8WbvbjYgaxe9WqmZF32Y3lz/kY5A8/5RdJbxoa4yOIAYpSEvqii9n2MTI2OL1+ByoVJYLhlUg==