refactor: ♻️ 代码风格提交校验重构

1、移除 eslint prettier stylelint 使用 antfu/eslint-config 替代代码风格检查
2、移除 husky git hooks插件,使用 simple-git-hooks 替代
This commit is contained in:
xiangshu233 2024-02-17 13:48:51 +08:00
parent 9a9d4d21e4
commit 147022076f
12 changed files with 1436 additions and 562 deletions

View File

@ -1,16 +0,0 @@
*.sh
node_modules
*.md
*.woff
*.ttf
.vscode
.idea
dist
/public
/docs
.husky
.local
/bin
Dockerfile
components.d.ts
components.d.ts

View File

@ -1,78 +0,0 @@
// @ts-check
const { defineConfig } = require('eslint-define-config');
module.exports = defineConfig({
root: true,
env: {
browser: true,
node: true,
es6: true,
},
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
ecmaVersion: 2020,
sourceType: 'module',
jsxPragma: 'React',
ecmaFeatures: {
jsx: true,
},
},
extends: [
'plugin:vue/vue3-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended',
],
rules: {
'vue/script-setup-uses-vars': 'error',
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-empty-function': 'off',
'vue/custom-event-name-casing': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'space-before-function-paren': 'off',
'vue/attributes-order': 'off',
'vue/one-component-per-file': 'off',
'vue/html-closing-bracket-newline': 'off',
'vue/max-attributes-per-line': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/singleline-html-element-content-newline': 'off',
'vue/attribute-hyphenation': 'off',
'vue/require-default-prop': 'off',
'vue/multi-word-component-names': 'off',
'vue/html-self-closing': [
'error',
{
html: {
void: 'always',
normal: 'never',
component: 'always',
},
svg: 'always',
math: 'always',
},
],
},
});

View File

@ -1,4 +0,0 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no-install commitlint --edit "$1"

View File

@ -1,4 +0,0 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run lint:lint-staged

View File

@ -1,9 +0,0 @@
/dist/*
.local
.output.js
/node_modules/**
**/*.svg
**/*.sh
/public/*

View File

@ -1,3 +0,0 @@
/dist/*
/public/*
public/*

View File

@ -117,7 +117,7 @@ pnpm dev
pnpm build
```
## Git 贡献提交规范
## Git 提交规范
### 提交规范

61
eslint.config.js Normal file
View File

@ -0,0 +1,61 @@
// eslint.config.js
import antfu from '@antfu/eslint-config'
export default antfu({
unocss: true,
stylistic: {
indent: 2, // 4, or 'tab'
quotes: 'single', // or 'double'
},
// 使用外部格式化程序来格式化 ESLint 无法处理的文件( .css 、 .html 等)
formatters: {
css: true,
html: true,
markdown: 'prettier',
},
// https://alloyteam.github.io/eslint-config-alloy/?language=zh-CN&rule=base
// https://eslint.vuejs.org/rules/
rules: {
'no-console': 'off',
// 强制组件顶级元素的顺序
'vue/block-order': [
'error',
{
order: ['template', 'script', 'style'],
},
],
'max-params': ['error', 4],
// 代码块嵌套的深度禁止超过 4 层
'max-depth': ['error', 4],
// 回调函数嵌套禁止超过 3 层,多了请用 async await 替代
'max-nested-callbacks': ['error', 4],
// 禁止使用 Array 构造函数时传入的参数超过一个
// 参数为多个时表示创建一个指定内容的数组,此时可以用数组字面量实现,不必使用构造函数
'no-array-constructor': 'error',
// 禁止 if else 的条件判断中出现重复的条件
'no-dupe-else-if': 'error',
// 禁止出现空代码块,允许 catch 为空代码块
'no-empty': [
'error',
{
allowEmptyCatch: true,
},
],
// 禁止出现没必要的字符串连接
'no-useless-concat': 'error',
// 禁止使用 var
'no-var': 'error',
// 禁止变量申明时用逗号一次申明多个
'one-var': ['error', 'never'],
// 必须使用 ... 而不是 Object.assign除非 Object.assign 的第一个参数是一个变量
'prefer-object-spread': 'error',
// 回调函数必须使用箭头函数
'prefer-arrow-callback': 'error',
// "stroustrup":强制一致的大括号风格,左括号必须与控制语句在同一行开始,右括号必须独占一行。
'brace-style': ['error', 'stroustrup'],
// 强制使用 node 全局变量 process 而不是 require("process") 。
'node/prefer-global/process': 'off',
// 对所有控制语句强制执行一致的大括号样式只有一行的时候eslint默认是不需要大括号的这样会降低代码清晰度
'curly': ['error', 'all'],
},
})

View File

@ -1,13 +1,18 @@
{
"name": "vue3-vant4-mobile",
"private": true,
"version": "0.0.2",
"type": "module",
"version": "1.0.0",
"private": true,
"packageManager": "pnpm@8.6.10",
"author": {
"name": "xiangshu233",
"email": "xiangshu233@outlook.com",
"url": "https://github.com/xiangshu233"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0",
"pnpm": ">=8.6.10"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"bootstrap": "pnpm install",
@ -20,11 +25,9 @@
"preview": "vite preview",
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
"clean:lib": "rimraf node_modules",
"lint:lint-staged": "lint-staged",
"lint:eslint": "eslint \"{src}/**/*.{vue,ts,tsx}\" --fix",
"lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"",
"lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
"prepare": "husky install"
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:lint-staged": "lint-staged"
},
"dependencies": {
"@types/lodash-es": "^4.17.12",
@ -46,30 +49,25 @@
"vue-router": "4.2.5"
},
"devDependencies": {
"@antfu/eslint-config": "^2.6.3",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@types/fs-extra": "^11.0.4",
"@types/mockjs": "^1.0.10",
"@types/node": "^20.10.5",
"@types/qs": "^6.9.11",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"@unocss/eslint-plugin": "^0.58.4",
"@unocss/transformer-directives": "^0.58.4",
"@unocss/transformer-variant-group": "^0.58.4",
"@vitejs/plugin-vue": "^5.0.0",
"@vue/eslint-config-typescript": "^12.0.0",
"autoprefixer": "^10.4.16",
"cross-env": "^7.0.3",
"cz-git": "^1.8.0",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.10.0",
"eslint-define-config": "^1.24.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.19.2",
"eslint-plugin-format": "^0.1.0",
"esno": "^0.16.3",
"fs-extra": "^11.2.0",
"husky": "^8.0.3",
"less": "^4.2.0",
"lint-staged": "^15.2.0",
"only-allow": "^1.2.1",
@ -78,16 +76,18 @@
"postcss-html": "^1.5.0",
"postcss-less": "^6.0.0",
"postcss-mobile-forever": "^4.0.0",
"prettier": "^2.8.8",
"prettier": "^3.2.4",
"rimraf": "^3.0.2",
"rollup": "^4.9.1",
"rollup-plugin-visualizer": "^5.11.0",
"stylelint": "^14.16.1",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recommended": "^9.0.0",
"simple-git-hooks": "^2.9.0",
"stylelint": "^16.2.0",
"stylelint-config-recommended": "^14.0.0",
"stylelint-config-recommended-vue": "^1.5.0",
"stylelint-config-standard": "^27.0.0",
"stylelint-order": "^5.0.0",
"stylelint-config-standard": "^36.0.0",
"stylelint-config-standard-less": "^3.0.1",
"stylelint-order": "^6.0.4",
"stylelint-prettier": "^5.0.0",
"typescript": "^5.3.3",
"unocss": "^0.58.5",
"unplugin-vue-components": "^0.26.0",
@ -96,36 +96,16 @@
"vite-plugin-html": "^3.2.1",
"vite-plugin-mock": "^2.9.8",
"vite-plugin-svg-icons": "^2.0.1",
"vue-eslint-parser": "^9.3.2",
"vue-tsc": "^1.8.27"
},
"engines": {
"node": ">=15",
"pnpm": ">=7"
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged",
"commit-msg": "npx --no-install commitlint --edit $1"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"prettier --write"
],
"{!(package)*.json,*.code-snippets,.!(browserslist)*rc}": [
"prettier --write--parser json"
],
"package.json": [
"prettier --write"
],
"*.vue": [
"eslint --fix",
"prettier --write",
"stylelint --fix"
],
"*.{scss,less,styl,html}": [
"stylelint --fix",
"prettier --write"
],
"*.md": [
"prettier --write"
]
"*": "eslint --fix"
},
"config": {
"commitizen": {

1627
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +0,0 @@
module.exports = {
printWidth: 100,
tabWidth: 2,
useTabs: false,
semi: true,
vueIndentScriptAndStyle: true,
singleQuote: true,
quoteProps: 'as-needed',
bracketSpacing: true,
trailingComma: 'es5',
jsxBracketSameLine: false,
jsxSingleQuote: false,
arrowParens: 'always',
insertPragma: false,
requirePragma: false,
proseWrap: 'never',
htmlWhitespaceSensitivity: 'strict',
endOfLine: 'auto',
rangeStart: 0,
};

View File

@ -1,100 +0,0 @@
module.exports = {
root: true,
plugins: ['stylelint-order'],
extends: ['stylelint-config-standard', 'stylelint-config-prettier'],
customSyntax: 'postcss-html',
rules: {
'function-no-unknown': null,
'selector-class-pattern': null,
'selector-pseudo-class-no-unknown': [
true,
{
ignorePseudoClasses: ['global'],
},
],
'selector-pseudo-element-no-unknown': [
true,
{
ignorePseudoElements: ['v-deep'],
},
],
'at-rule-no-unknown': [
true,
{
ignoreAtRules: [
'tailwind',
'apply',
'variants',
'responsive',
'screen',
'function',
'if',
'each',
'include',
'mixin',
],
},
],
'no-empty-source': null,
'string-quotes': null,
'named-grid-areas-no-invalid': null,
'unicode-bom': 'never',
'no-descending-specificity': null,
'font-family-no-missing-generic-family-keyword': null,
'declaration-colon-space-after': 'always-single-line',
'declaration-colon-space-before': 'never',
// 'declaration-block-trailing-semicolon': 'always',
'rule-empty-line-before': [
'always',
{
ignore: ['after-comment', 'first-nested'],
},
],
'unit-no-unknown': [true, { ignoreUnits: ['rpx'] }],
'order/order': [
[
'dollar-variables',
'custom-properties',
'at-rules',
'declarations',
{
type: 'at-rule',
name: 'supports',
},
{
type: 'at-rule',
name: 'media',
},
'rules',
],
{ severity: 'warning' },
],
},
ignoreFiles: ['**/*.js', '**/*.jsx', '**/*.tsx', '**/*.ts'],
overrides: [
{
files: ['*.vue', '**/*.vue', '*.html', '**/*.html'],
extends: ['stylelint-config-recommended'],
rules: {
'keyframes-name-pattern': null,
'selector-pseudo-class-no-unknown': [
true,
{
ignorePseudoClasses: ['deep', 'global'],
},
],
'selector-pseudo-element-no-unknown': [
true,
{
ignorePseudoElements: ['v-deep', 'v-global', 'v-slotted'],
},
],
},
},
{
files: ['*.less', '**/*.less'],
customSyntax: 'postcss-less',
extends: ['stylelint-config-standard', 'stylelint-config-recommended-vue'],
},
],
};