From 749d5592bac7c6421e901e3446351044c4208985 Mon Sep 17 00:00:00 2001 From: yangfan <18767120422@163.com> Date: Fri, 31 Dec 2021 10:43:33 +0800 Subject: [PATCH 1/3] feat: add prettier --- packages/eslint-plugin-best-practices/CHANGELOG.md | 3 +++ packages/eslint-plugin-best-practices/package.json | 2 +- .../src/configs/common.js | 6 +++++- packages/spec/examples/rax/index.jsx | 12 ++++++++++++ packages/spec/package.json | 9 +++++---- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/eslint-plugin-best-practices/CHANGELOG.md b/packages/eslint-plugin-best-practices/CHANGELOG.md index bdb9a0e..65c5ba4 100644 --- a/packages/eslint-plugin-best-practices/CHANGELOG.md +++ b/packages/eslint-plugin-best-practices/CHANGELOG.md @@ -1,5 +1,8 @@ # changelog +## 0.3.0 +- Add `eslint-plugin-prettier` + ## 0.2.10 - Update stylistic rules `dot-notation` and `@typescript-eslint/dot-notation` from error to off. diff --git a/packages/eslint-plugin-best-practices/package.json b/packages/eslint-plugin-best-practices/package.json index 0152a42..b73ba96 100644 --- a/packages/eslint-plugin-best-practices/package.json +++ b/packages/eslint-plugin-best-practices/package.json @@ -1,6 +1,6 @@ { "name": "@iceworks/eslint-plugin-best-practices", - "version": "0.2.10", + "version": "0.3.0", "description": "Iceworks best practices eslint plugin.", "files": [ "docs/", diff --git a/packages/eslint-plugin-best-practices/src/configs/common.js b/packages/eslint-plugin-best-practices/src/configs/common.js index e3b2314..fc4cbcd 100644 --- a/packages/eslint-plugin-best-practices/src/configs/common.js +++ b/packages/eslint-plugin-best-practices/src/configs/common.js @@ -1,5 +1,8 @@ module.exports = { - plugins: ['@iceworks/best-practices'], + plugins: [ + 'prettier', + '@iceworks/best-practices', + ], overrides: [ { files: ['package.json'], @@ -38,6 +41,7 @@ module.exports = { 'semi': 'warn', 'eol-last': 'warn', 'quote-props': 'warn', + 'prettier/prettier': 'warn', '@iceworks/best-practices/no-http-url': 'warn', '@iceworks/best-practices/no-js-in-ts-project': 'warn', '@iceworks/best-practices/no-lowercase-component-name': 'warn', diff --git a/packages/spec/examples/rax/index.jsx b/packages/spec/examples/rax/index.jsx index f74796e..0fcb20f 100644 --- a/packages/spec/examples/rax/index.jsx +++ b/packages/spec/examples/rax/index.jsx @@ -10,3 +10,15 @@ export default (props) => { const source = { uri }; return ; }; + +// prettier test +const a = 1; const b = 2; +const c = { + a: [ + { + a: 1, + b: + 2, + }, + ], +} diff --git a/packages/spec/package.json b/packages/spec/package.json index 7f3253b..1c6a66b 100644 --- a/packages/spec/package.json +++ b/packages/spec/package.json @@ -1,6 +1,6 @@ { "name": "@iceworks/spec", - "version": "1.5.0", + "version": "1.5.1", "description": "Easy to use eslint/stylelint/prettier/commitlint in rax, ice and react project.", "main": "src/index.js", "files": [ @@ -36,16 +36,17 @@ "stylelint": ">=8.3.0" }, "dependencies": { - "@iceworks/eslint-plugin-best-practices": "^0.2.0", - "@typescript-eslint/eslint-plugin": "^5.0.0", - "@typescript-eslint/parser": "^5.0.0", "@babel/core": "^7.16.0", "@babel/eslint-parser": "^7.16.3", "@babel/preset-react": "^7.16.0", + "@iceworks/eslint-plugin-best-practices": "^0.3.0", + "@typescript-eslint/eslint-plugin": "^5.0.0", + "@typescript-eslint/parser": "^5.0.0", "commitlint-config-ali": "^0.1.0", "eslint-config-ali": "^13.0.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jsx-plus": "^0.1.0", + "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-rax-compile-time-miniapp": "^1.0.0", "eslint-plugin-react": "^7.21.5", "eslint-plugin-react-hooks": "^4.2.0", From a4c8fb6569ed553c7d12abe6c72383ac67d4a63a Mon Sep 17 00:00:00 2001 From: yangfan <18767120422@163.com> Date: Fri, 31 Dec 2021 10:48:54 +0800 Subject: [PATCH 2/3] feat: update change log --- packages/spec/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/spec/CHANGELOG.md b/packages/spec/CHANGELOG.md index 381bc36..cdf91e2 100644 --- a/packages/spec/CHANGELOG.md +++ b/packages/spec/CHANGELOG.md @@ -1,5 +1,9 @@ # changelog +## 1.5.1 + +- Feat add `eslint-plugin-prettier`, and set `"prettier/prettier": "warn"`. + ## 1.5.0 - Feat update eslint-config-ali, babel and typescript dependencies to support ESLint@8.x. From 5634504ada095e123d79a1847e7b6da296cbe042 Mon Sep 17 00:00:00 2001 From: yangfan <18767120422@163.com> Date: Fri, 31 Dec 2021 11:02:14 +0800 Subject: [PATCH 3/3] feat: update prettier --- .../src/configs/common.js | 32 +++++++++---------- .../src/configs/rax-ts.js | 2 +- .../src/configs/react-ts.js | 2 +- .../src/rules/no-broad-semantic-versioning.js | 7 +--- .../src/rules/no-secret-info.js | 1 + .../src/rules/recommend-polyfill.js | 7 +--- packages/spec/src/eslint/common-ts.js | 6 ++-- packages/spec/src/eslint/common.js | 6 ++-- packages/spec/src/eslint/vue-ts.js | 6 ++-- packages/spec/src/eslint/vue.js | 6 ++-- packages/spec/src/getRaxEslintConfig.js | 10 +++--- 11 files changed, 33 insertions(+), 52 deletions(-) diff --git a/packages/eslint-plugin-best-practices/src/configs/common.js b/packages/eslint-plugin-best-practices/src/configs/common.js index fc4cbcd..a983674 100644 --- a/packages/eslint-plugin-best-practices/src/configs/common.js +++ b/packages/eslint-plugin-best-practices/src/configs/common.js @@ -1,8 +1,5 @@ module.exports = { - plugins: [ - 'prettier', - '@iceworks/best-practices', - ], + plugins: ['prettier', '@iceworks/best-practices'], overrides: [ { files: ['package.json'], @@ -21,24 +18,25 @@ module.exports = { }, }, { - files: [ - '**/__tests__/*.{j,t}s?(x)', - '**/tests/*.{j,t}s?(x)', - '**/test/*.{j,t}s?(x)', - ], + files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/*.{j,t}s?(x)', '**/test/*.{j,t}s?(x)'], env: { jest: true }, }, ], rules: { + semi: 'warn', 'dot-notation': 'off', - 'max-len': ['warn', 120, 2, { - ignoreUrls: true, - ignoreComments: false, - ignoreRegExpLiterals: true, - ignoreStrings: true, - ignoreTemplateLiterals: true, - }], - 'semi': 'warn', + 'max-len': [ + 'warn', + 120, + 2, + { + ignoreUrls: true, + ignoreComments: false, + ignoreRegExpLiterals: true, + ignoreStrings: true, + ignoreTemplateLiterals: true, + }, + ], 'eol-last': 'warn', 'quote-props': 'warn', 'prettier/prettier': 'warn', diff --git a/packages/eslint-plugin-best-practices/src/configs/rax-ts.js b/packages/eslint-plugin-best-practices/src/configs/rax-ts.js index d1ecaa5..801d82e 100644 --- a/packages/eslint-plugin-best-practices/src/configs/rax-ts.js +++ b/packages/eslint-plugin-best-practices/src/configs/rax-ts.js @@ -3,10 +3,10 @@ const { deepmerge } = require('@iceworks/spec'); module.exports = deepmerge(commonConfig, { rules: { + semi: 'off', 'max-lines': ['warn', { max: 500 }], 'no-plusplus': 'off', 'no-return-await': 'off', - 'semi': 'off', '@typescript-eslint/dot-notation': 'off', '@typescript-eslint/semi': 'warn', '@typescript-eslint/no-unused-vars': 'warn', diff --git a/packages/eslint-plugin-best-practices/src/configs/react-ts.js b/packages/eslint-plugin-best-practices/src/configs/react-ts.js index caafab7..fec7ac4 100644 --- a/packages/eslint-plugin-best-practices/src/configs/react-ts.js +++ b/packages/eslint-plugin-best-practices/src/configs/react-ts.js @@ -3,12 +3,12 @@ const { deepmerge } = require('@iceworks/spec'); module.exports = deepmerge(commonConfig, { rules: { + semi: 'off', 'max-len': ['error', { code: 150 }], 'max-lines': ['warn', { max: 500 }], 'no-plusplus': 'off', 'no-return-await': 'off', 'react/prop-types': 'off', - 'semi': 'off', '@typescript-eslint/dot-notation': 'off', '@typescript-eslint/semi': 'warn', '@typescript-eslint/no-unused-vars': 'warn', diff --git a/packages/eslint-plugin-best-practices/src/rules/no-broad-semantic-versioning.js b/packages/eslint-plugin-best-practices/src/rules/no-broad-semantic-versioning.js index ec43074..a68f87e 100644 --- a/packages/eslint-plugin-best-practices/src/rules/no-broad-semantic-versioning.js +++ b/packages/eslint-plugin-best-practices/src/rules/no-broad-semantic-versioning.js @@ -47,12 +47,7 @@ module.exports = { dependencyVersion.indexOf('>') > -1 ) { let newVersioning = '^1.0.0'; - const dependencyPackageFile = path.join( - cwd, - 'node_modules', - dependencyName, - 'package.json', - ); + const dependencyPackageFile = path.join(cwd, 'node_modules', dependencyName, 'package.json'); if (fs.existsSync(dependencyPackageFile)) { const dependencyPackage = fs.readJSONSync(dependencyPackageFile); newVersioning = `^${dependencyPackage.version}`; diff --git a/packages/eslint-plugin-best-practices/src/rules/no-secret-info.js b/packages/eslint-plugin-best-practices/src/rules/no-secret-info.js index 667c543..c177b6f 100644 --- a/packages/eslint-plugin-best-practices/src/rules/no-secret-info.js +++ b/packages/eslint-plugin-best-practices/src/rules/no-secret-info.js @@ -1,3 +1,4 @@ +/* eslint-disable prettier/prettier */ const docsUrl = require('../docsUrl'); const RULE_NAME = 'no-secret-info'; diff --git a/packages/eslint-plugin-best-practices/src/rules/recommend-polyfill.js b/packages/eslint-plugin-best-practices/src/rules/recommend-polyfill.js index 0232ff0..fdc9408 100644 --- a/packages/eslint-plugin-best-practices/src/rules/recommend-polyfill.js +++ b/packages/eslint-plugin-best-practices/src/rules/recommend-polyfill.js @@ -72,12 +72,7 @@ module.exports = { const supports = target.__compat.support; for (let i = 0, l = Object.keys(targetBrowsers).length; i < l; i++) { const browser = Object.keys(targetBrowsers)[i]; - if ( - semver.satisfies( - `${targetBrowsers[browser]}.0.0`, - `<${supports[browser].version_added}`, - ) - ) { + if (semver.satisfies(`${targetBrowsers[browser]}.0.0`, `<${supports[browser].version_added}`)) { context.report({ node, messageId: 'recommendPolyfill', diff --git a/packages/spec/src/eslint/common-ts.js b/packages/spec/src/eslint/common-ts.js index 6a9374c..dbd3ff0 100644 --- a/packages/spec/src/eslint/common-ts.js +++ b/packages/spec/src/eslint/common-ts.js @@ -1,12 +1,10 @@ // https://www.npmjs.com/package/eslint-config-ali // ESlint config for common ts project module.exports = { - extends: [ - require.resolve('eslint-config-ali/typescript'), - ], + extends: [require.resolve('eslint-config-ali/typescript')], rules: { // Change error to warn - 'semi': 'off', + semi: 'off', '@typescript-eslint/semi': 'warn', 'eol-last': 'warn', 'quote-props': 'warn', diff --git a/packages/spec/src/eslint/common.js b/packages/spec/src/eslint/common.js index bef7361..515217b 100644 --- a/packages/spec/src/eslint/common.js +++ b/packages/spec/src/eslint/common.js @@ -1,12 +1,10 @@ // https://www.npmjs.com/package/eslint-config-ali // ESlint config for common js project module.exports = { - extends: [ - require.resolve('eslint-config-ali'), - ], + extends: [require.resolve('eslint-config-ali')], rules: { // Change error to warn - 'semi': 'warn', + semi: 'warn', 'eol-last': 'warn', 'quote-props': 'warn', 'no-unused-vars': 'warn', diff --git a/packages/spec/src/eslint/vue-ts.js b/packages/spec/src/eslint/vue-ts.js index ef6bdf3..34d06af 100644 --- a/packages/spec/src/eslint/vue-ts.js +++ b/packages/spec/src/eslint/vue-ts.js @@ -1,12 +1,10 @@ // https://www.npmjs.com/package/eslint-config-ali // ESlint config for Vue TypeScript project module.exports = { - extends: [ - require.resolve('eslint-config-ali/typescript/vue'), - ], + extends: [require.resolve('eslint-config-ali/typescript/vue')], rules: { // Change error to warn - 'semi': 'off', + semi: 'off', '@typescript-eslint/semi': 'warn', 'eol-last': 'warn', 'quote-props': 'warn', diff --git a/packages/spec/src/eslint/vue.js b/packages/spec/src/eslint/vue.js index 67042fd..84c9d17 100644 --- a/packages/spec/src/eslint/vue.js +++ b/packages/spec/src/eslint/vue.js @@ -1,12 +1,10 @@ // https://www.npmjs.com/package/eslint-config-ali // ESlint config for Vue project module.exports = { - extends: [ - require.resolve('eslint-config-ali/vue'), - ], + extends: [require.resolve('eslint-config-ali/vue')], rules: { // Change error to warn - 'semi': 'warn', + semi: 'warn', 'eol-last': 'warn', 'quote-props': 'warn', 'no-unused-vars': 'warn', diff --git a/packages/spec/src/getRaxEslintConfig.js b/packages/spec/src/getRaxEslintConfig.js index 1d91763..c4d5fdb 100644 --- a/packages/spec/src/getRaxEslintConfig.js +++ b/packages/spec/src/getRaxEslintConfig.js @@ -9,13 +9,13 @@ module.exports = function (config) { const buildConfigFilePath = path.join(process.cwd(), 'build.json'); if (fs.existsSync(buildConfigFilePath)) { - const buildConfig = JSON5.parse(fs.readFileSync(buildConfigFilePath, 'utf8')); - const isCompileTime = (target) => ( - buildConfig.targets && buildConfig.targets.find((t) => t === target) && - buildConfig[target] && buildConfig[target].buildType === 'compile' - ); + const isCompileTime = (target) => + buildConfig.targets && + buildConfig.targets.find((t) => t === target) && + buildConfig[target] && + buildConfig[target].buildType === 'compile'; // At present, only miniapp and wechat-miniprogram support build for compile-time if (isCompileTime('miniapp') || isCompileTime('wechat-miniprogram')) {