From 4edf39ea1c759ecdd8970ed453d9b10d13181809 Mon Sep 17 00:00:00 2001 From: yikai <15270421125@163.com> Date: Mon, 8 May 2023 22:55:23 +0800 Subject: [PATCH] husky --- hippo4j-ui-new/.eslintignore | 5 ++ hippo4j-ui-new/.eslintrc.js | 34 ++++++------- hippo4j-ui-new/.husky | 5 ++ hippo4j-ui-new/.prettierignore | 4 ++ hippo4j-ui-new/.prettierrc.js | 72 ++++++++++++--------------- hippo4j-ui-new/package-lock.json | 68 ++++++++++++++++++++++++- hippo4j-ui-new/package.json | 19 ++++--- hippo4j-ui-new/src/index.tsx | 6 +-- hippo4j-ui-new/src/react-app-env.d.ts | 4 +- 9 files changed, 145 insertions(+), 72 deletions(-) create mode 100644 hippo4j-ui-new/.eslintignore create mode 100644 hippo4j-ui-new/.husky create mode 100644 hippo4j-ui-new/.prettierignore diff --git a/hippo4j-ui-new/.eslintignore b/hippo4j-ui-new/.eslintignore new file mode 100644 index 00000000..4fa47a37 --- /dev/null +++ b/hippo4j-ui-new/.eslintignore @@ -0,0 +1,5 @@ +/.git +/.vscode +node_modules +build +public diff --git a/hippo4j-ui-new/.eslintrc.js b/hippo4j-ui-new/.eslintrc.js index 3d64b436..1977fd37 100644 --- a/hippo4j-ui-new/.eslintrc.js +++ b/hippo4j-ui-new/.eslintrc.js @@ -1,31 +1,29 @@ module.exports = { env: { browser: true, - es6: true, + es2021: true, node: true, }, - extends: ["airbnb", "prettier"], - parser: "babel-eslint", + root: true, + extends: ['eslint:recommended', 'react-app', 'plugin:prettier/recommended', 'plugin:@typescript-eslint/recommended'], + overrides: [], + parser: '@typescript-eslint/parser', parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', ecmaFeatures: { jsx: true, }, }, - plugins: ["react"], + plugins: ['react', '@typescript-eslint'], rules: { - "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", - "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", - "react/prefer-stateless-function": 0, // 关闭react默认的props-type验证 - "react/prop-types": [0], - "react/jsx-closing-bracket-location": "off", - "consistent-return": "off", - // 关闭使用解构赋值的检测 - "react/destructuring-assignment": [0, "always"], - // 解决require报错问题 - "import/no-extraneous-dependencies": ["error", { devDependencies: true }], - "react/jsx-wrap-multilines": "off", - "global-require": 0, - "jsx-a11y/no-static-element-interactions": 0, - "jsx-a11y/click-events-have-key-events": 0, + eqeqeq: 2, + 'no-alert': 2, + 'no-undef': 2, + 'no-use-before-define': 2, + 'react-hooks/exhaustive-deps': 2, + '@typescript-eslint/no-explicit-any': 0, + '@typescript-eslint/no-non-null-assertion': 0, + '@typescript-eslint/no-var-requires': 0, }, }; diff --git a/hippo4j-ui-new/.husky b/hippo4j-ui-new/.husky new file mode 100644 index 00000000..2d9a4ab3 --- /dev/null +++ b/hippo4j-ui-new/.husky @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +echo "pre-commit"; +npx lint-staged; \ No newline at end of file diff --git a/hippo4j-ui-new/.prettierignore b/hippo4j-ui-new/.prettierignore new file mode 100644 index 00000000..58c64d85 --- /dev/null +++ b/hippo4j-ui-new/.prettierignore @@ -0,0 +1,4 @@ + /.git +/.vscode +node_modules +build \ No newline at end of file diff --git a/hippo4j-ui-new/.prettierrc.js b/hippo4j-ui-new/.prettierrc.js index c95e826c..f9d533a1 100644 --- a/hippo4j-ui-new/.prettierrc.js +++ b/hippo4j-ui-new/.prettierrc.js @@ -1,39 +1,33 @@ -module.exports = { - // 使能每一种语言默认格式化规则 - '[html]': { - 'editor.defaultFormatter': 'esbenp.prettier-vscode' - }, - '[css]': { - 'editor.defaultFormatter': 'esbenp.prettier-vscode' - }, - '[less]': { - 'editor.defaultFormatter': 'esbenp.prettier-vscode' - }, - '[javascript]': { - 'editor.defaultFormatter': 'esbenp.prettier-vscode' - }, - printWidth: 120, - trailingComma: 'none', - jsxBracketSameLine: true, - /* prettier的配置 */ - printWidth: 100, // 超过最大值换行 - tabWidth: 2, // 缩进字节数 - useTabs: false, // 缩进不使用tab,使用空格 - semi: true, // 句尾添加分号 - singleQuote: true, // 使用单引号代替双引号 - proseWrap: 'preserve', // 默认值。因为使用了一些折行敏感型的渲染器(如GitHub comment)而按照markdown文本样式进行折行 - arrowParens: 'avoid', // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号 - bracketSpacing: true, // 在对象,数组括号与文字之间加空格 "{ foo: bar }" - //'prettier.disableLanguages': ['vue'], // 不格式化vue文件,vue文件的格式化单独设置 - endOfLine: 'auto', // 结尾是 \n \r \n\r auto - // eslintIntegration: false, //不让prettier使用eslint的代码格式进行校验 - 'prettier.htmlWhitespaceSensitivity': 'ignore', - 'prettier.ignorePath': '.prettierignore', // 不使用prettier格式化的文件填写在项目的.prettierignore文件中 - jsxBracketSameLine: false, // 在jsx中把'>' 是否单独放一行 - jsxSingleQuote: false // 在jsx中使用单引号代替双引号 - //parser: 'babylon', // 格式化的解析器,默认是babylon - //requireConfig: false, // Require a 'prettierconfig' to format prettier - //stylelintIntegration: false, //不让prettier使用stylelint的代码格式进行校验 - //trailingComma: 'es5', // 在对象或数组最后一个元素后面是否加逗号(在ES5中加尾逗号) - //tslintIntegration: false, // 不让prettier使用tslint的代码格式进行校验 - }; \ No newline at end of file +module.exports = { + // 1.一行代码的最大字符数,默认是80(printWidth: ) + printWidth: 120, + // 2.tab宽度为2空格(tabWidth: ) + tabWidth: 2, + // 3.是否使用tab来缩进,我们使用空格(useTabs: ) + useTabs: false, + // 4.结尾是否添加分号,false的情况下只会在一些导致ASI错误的其工况下在开头加分号,我选择无分号结尾的风格(semi: ) + semi: true, + // 5.使用单引号(singleQuote: ) + singleQuote: true, + // 6.object对象中key值是否加引号(quoteProps: "")as-needed只有在需求要的情况下加引号,consistent是有一个需要引号就统一加,preserve是保留用户输入的引号 + quoteProps: 'as-needed', + // 7.在jsx文件中的引号需要单独设置(jsxSingleQuote: ) + jsxSingleQuote: false, + // 8.尾部逗号设置,es5是尾部逗号兼容es5,none就是没有尾部逗号,all是指所有可能的情况,需要node8和es2017以上的环境。(trailingComma: "") + trailingComma: 'es5', + // 9.object对象里面的key和value值和括号间的空格(bracketSpacing: ) + bracketSpacing: true, + // 10.jsx标签多行属性写法时,尖括号是否另起一行(jsxBracketSameLine: ) + jsxBracketSameLine: false, + // 11.箭头函数单个参数的情况是否省略括号,默认always是总是带括号(arrowParens: "") + arrowParens: 'avoid', + // 12.range是format执行的范围,可以选执行一个文件的一部分,默认的设置是整个文件(rangeStart: rangeEnd: ) + rangeStart: 0, + rangeEnd: Infinity, + // 18. vue script和style标签中是否缩进,开启可能会破坏编辑器的代码折叠 + vueIndentScriptAndStyle: false, + // 19. endOfLine: "" 行尾换行符,默认是lf, + endOfLine: 'auto', + // 20.embeddedLanguageFormatting: "off",默认是auto,控制被引号包裹的代码是否进行格式化 + embeddedLanguageFormatting: 'off', +}; diff --git a/hippo4j-ui-new/package-lock.json b/hippo4j-ui-new/package-lock.json index c6bb4dd4..4d5880f0 100644 --- a/hippo4j-ui-new/package-lock.json +++ b/hippo4j-ui-new/package-lock.json @@ -23,6 +23,8 @@ }, "devDependencies": { "@craco/craco": "^7.1.0", + "@typescript-eslint/eslint-plugin": "^5.59.2", + "@typescript-eslint/parser": "^5.59.2", "babel-eslint": "^10.1.0", "craco-css-modules": "^1.0.5", "craco-less": "^2.0.0", @@ -31,8 +33,9 @@ "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.8.0", "eslint-plugin-jsx-a11y": "^6.7.1", + "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-react": "^7.32.2", - "husky": "^8.0.3", + "husky": "^8.0.0", "less-loader": "^11.1.0", "lint-staged": "^13.2.2", "prettier": "^2.8.8" @@ -7071,6 +7074,27 @@ "semver": "bin/semver.js" } }, + "node_modules/eslint-plugin-prettier": { + "version": "4.2.1", + "resolved": "https://registry.npmmirror.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz", + "integrity": "sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==", + "dev": true, + "dependencies": { + "prettier-linter-helpers": "^1.0.0" + }, + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "eslint": ">=7.28.0", + "prettier": ">=2.0.0" + }, + "peerDependenciesMeta": { + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-plugin-react": { "version": "7.32.2", "resolved": "https://registry.npmmirror.com/eslint-plugin-react/-/eslint-plugin-react-7.32.2.tgz", @@ -7564,6 +7588,12 @@ "resolved": "https://registry.npmmirror.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "node_modules/fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmmirror.com/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "node_modules/fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmmirror.com/fast-glob/-/fast-glob-3.2.12.tgz", @@ -13687,6 +13717,18 @@ "node": ">=10.13.0" } }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmmirror.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz", @@ -22415,6 +22457,15 @@ } } }, + "eslint-plugin-prettier": { + "version": "4.2.1", + "resolved": "https://registry.npmmirror.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz", + "integrity": "sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-plugin-react": { "version": "7.32.2", "resolved": "https://registry.npmmirror.com/eslint-plugin-react/-/eslint-plugin-react-7.32.2.tgz", @@ -22717,6 +22768,12 @@ "resolved": "https://registry.npmmirror.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmmirror.com/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmmirror.com/fast-glob/-/fast-glob-3.2.12.tgz", @@ -27265,6 +27322,15 @@ "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmmirror.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz", diff --git a/hippo4j-ui-new/package.json b/hippo4j-ui-new/package.json index 9196098d..bc580d41 100644 --- a/hippo4j-ui-new/package.json +++ b/hippo4j-ui-new/package.json @@ -21,11 +21,8 @@ "build": "craco build", "test": "react-scripts test", "eject": "react-scripts eject", - "lint": "eslint --ext .js src", - "lint:fix": "eslint --fix --ext .js src", - "lint-staged": "lint-staged", - "lint-staged:js": "eslint --ext .js src", - "format": "prettier --write ./src/**/**/**/*.js" + "lint": "eslint -c .eslintrc.js src --ext .ts,.tsx,.js,.jsx --fix", + "prepare": "husky install" }, "eslintConfig": { "extends": [ @@ -47,6 +44,8 @@ }, "devDependencies": { "@craco/craco": "^7.1.0", + "@typescript-eslint/eslint-plugin": "^5.59.2", + "@typescript-eslint/parser": "^5.59.2", "babel-eslint": "^10.1.0", "craco-css-modules": "^1.0.5", "craco-less": "^2.0.0", @@ -55,11 +54,17 @@ "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.8.0", "eslint-plugin-jsx-a11y": "^6.7.1", + "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-react": "^7.32.2", - "husky": "^8.0.3", + "husky": "^8.0.0", "less-loader": "^11.1.0", "lint-staged": "^13.2.2", "prettier": "^2.8.8" }, - "cracoConfig": "./build/craco.config.js" + "cracoConfig": "./build/craco.config.js", + "lint-staged": { + "src/**/*.{ts,tsx,js,jsx}": [ + "eslint -c .eslintrc.js --fix" + ] + } } diff --git a/hippo4j-ui-new/src/index.tsx b/hippo4j-ui-new/src/index.tsx index 7d5e8f70..b221b6ed 100644 --- a/hippo4j-ui-new/src/index.tsx +++ b/hippo4j-ui-new/src/index.tsx @@ -2,14 +2,10 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App'; - -const root = ReactDOM.createRoot( - document.getElementById('root') as HTMLElement -); +const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); root.render( ); - diff --git a/hippo4j-ui-new/src/react-app-env.d.ts b/hippo4j-ui-new/src/react-app-env.d.ts index b9edd2a2..bb172a71 100644 --- a/hippo4j-ui-new/src/react-app-env.d.ts +++ b/hippo4j-ui-new/src/react-app-env.d.ts @@ -1,2 +1,2 @@ -/// -declare module '*.less' \ No newline at end of file +/// +declare module '*.less';