Skip to content

Commit acd975b

Browse files
committed
chore: add lint
1 parent 9e53fe9 commit acd975b

17 files changed

+1839
-198
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
/logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
static/
41+
42+
# TypeScript v1 declaration files
43+
typings/
44+
45+
# Optional npm cache directory
46+
.npm
47+
48+
# Optional eslint cache
49+
.eslintcache
50+
51+
# Optional REPL history
52+
.node_repl_history
53+
54+
# Output of 'npm pack'
55+
*.tgz
56+
57+
# Yarn Integrity file
58+
.yarn-integrity
59+
60+
# dotenv environment variables file
61+
.env
62+
63+
# parcel-bundler cache (https://parceljs.org/)
64+
.cache
65+
66+
# next.js build output
67+
.next
68+
69+
# nuxt.js build output
70+
.nuxt
71+
72+
# Nuxt generate
73+
dist
74+
75+
# vuepress build output
76+
.vuepress/dist
77+
78+
# Serverless directories
79+
.serverless
80+
81+
# IDE / Editor
82+
.idea
83+
84+
# Service worker
85+
sw.*
86+
87+
# macOS
88+
.DS_Store
89+
90+
# Vim swap files
91+
*.swp

.eslintrc.js

Lines changed: 23 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,26 @@
11
module.exports = {
2-
env: {
3-
browser: true,
4-
es2021: true,
5-
node: true,
6-
},
7-
extends: [
8-
'eslint:recommended',
9-
'plugin:vue/vue3-recommended', // 使用插件支持vue3
10-
'plugin:vue/essential',
11-
'plugin:@typescript-eslint/recommended',
12-
'plugin:prettier/recommended',
13-
'eslint-config-prettier',
14-
],
15-
parserOptions: {
16-
ecmaVersion: 'latest',
17-
parser: '@typescript-eslint/parser',
18-
sourceType: 'module',
19-
},
20-
plugins: ['vue', 'prettier', '@typescript-eslint'],
21-
rules: {
22-
semi: ['warn', 'never'], // 禁止尾部使用分号
23-
'no-console': 'warn', // 禁止出现console
24-
'no-debugger': 'warn', // 禁止出现debugger
25-
'no-duplicate-case': 'warn', // 禁止出现重复case
26-
'no-empty': 'warn', // 禁止出现空语句块
27-
'no-extra-parens': 'warn', // 禁止不必要的括号
28-
'no-func-assign': 'warn', // 禁止对Function声明重新赋值
29-
'no-unreachable': 'warn', // 禁止出现[return|throw]之后的代码块
30-
'no-else-return': 'warn', // 禁止if语句中return语句之后有else块
31-
'no-empty-function': 'warn', // 禁止出现空的函数块
32-
'no-lone-blocks': 'warn', // 禁用不必要的嵌套块
33-
'no-multi-spaces': 'warn', // 禁止使用多个空格
34-
'no-redeclare': 'warn', // 禁止多次声明同一变量
35-
'no-return-assign': 'warn', // 禁止在return语句中使用赋值语句
36-
'no-return-await': 'warn', // 禁用不必要的[return/await]
37-
'no-self-compare': 'warn', // 禁止自身比较表达式
38-
'no-useless-catch': 'warn', // 禁止不必要的catch子句
39-
'no-useless-return': 'warn', // 禁止不必要的return语句
40-
'no-mixed-spaces-and-tabs': 'warn', // 禁止空格和tab的混合缩进
41-
'no-multiple-empty-lines': 'warn', // 禁止出现多行空行
42-
'no-trailing-spaces': 'warn', // 禁止一行结束后面不要有空格
43-
'no-useless-call': 'warn', // 禁止不必要的.call()和.apply()
44-
'no-var': 'warn', // 禁止出现var用let和const代替
45-
'no-delete-var': 'off', // 允许出现delete变量的使用
46-
'no-shadow': 'off', // 允许变量声明与外层作用域的变量同名
47-
'dot-notation': 'warn', // 要求尽可能地使用点号
48-
'default-case': 'warn', // 要求switch语句中有default分支
49-
eqeqeq: 'warn', // 要求使用 === 和 !==
50-
curly: 'warn', // 要求所有控制语句使用一致的括号风格
51-
'space-before-blocks': 'warn', // 要求在块之前使用一致的空格
52-
'space-in-parens': 'warn', // 要求在圆括号内使用一致的空格
53-
'space-infix-ops': 'warn', // 要求操作符周围有空格
54-
'space-unary-ops': 'warn', // 要求在一元操作符前后使用一致的空格
55-
'switch-colon-spacing': 'warn', // 要求在switch的冒号左右有空格
56-
'arrow-spacing': 'warn', // 要求箭头函数的箭头前后使用一致的空格
57-
'array-bracket-spacing': 'warn', // 要求数组方括号中使用一致的空格
58-
'brace-style': 'warn', // 要求在代码块中使用一致的大括号风格
59-
camelcase: 'warn', // 要求使用骆驼拼写法命名约定
60-
indent: ['warn', 4], // 要求使用JS一致缩进4个空格
61-
'max-depth': ['warn', 4], // 要求可嵌套的块的最大深度4
62-
'max-statements': ['warn', 100], // 要求函数块最多允许的的语句数量20
63-
'max-nested-callbacks': ['warn', 3], // 要求回调函数最大嵌套深度3
64-
'max-statements-per-line': ['warn', { max: 1 }], // 要求每一行中所允许的最大语句数量
65-
quotes: ['warn', 'single', 'avoid-escape'], // 要求统一使用单引号符号
66-
'vue/require-default-prop': 0, // 关闭属性参数必须默认值
67-
'vue/singleline-html-element-content-newline': 0, // 关闭单行元素必须换行符
68-
'vue/multiline-html-element-content-newline': 0, // 关闭多行元素必须换行符
69-
// 要求每一行标签的最大属性不超五个
70-
'vue/max-attributes-per-line': ['warn', { singleline: 5 }],
71-
// 要求html标签的缩进为需要4个空格
72-
'vue/html-indent': [
73-
'warn',
74-
4,
75-
{
76-
attribute: 1,
77-
baseIndent: 1,
78-
closeBracket: 0,
79-
alignAttributesVertically: true,
80-
ignores: [],
81-
},
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
node: true
6+
},
7+
parser: 'vue-eslint-parser',
8+
extends: [
9+
'plugin:vue/base',
10+
'eslint:recommended',
11+
'plugin:vue/vue3-recommended',
12+
'plugin:vue/essential',
13+
'plugin:@typescript-eslint/recommended',
14+
'plugin:prettier/recommended',
15+
'eslint-config-prettier'
8216
],
83-
// 取消关闭标签不能自闭合的限制设置
84-
'vue/html-self-closing': [
85-
'error',
86-
{
87-
html: {
88-
void: 'always',
89-
normal: 'never',
90-
component: 'always',
91-
},
92-
svg: 'always',
93-
math: 'always',
94-
},
95-
],
96-
},
17+
parserOptions: {
18+
ecmaVersion: 'latest',
19+
parser: '@typescript-eslint/parser',
20+
sourceType: 'module'
21+
},
22+
plugins: ['vue', 'prettier', '@typescript-eslint'],
23+
rules: {
24+
'vue/no-v-html': 'off'
25+
}
9726
}

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["johnsoncodehk.volar"]
3+
}

.vscode/settings.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
{
2-
"vetur.experimental.templateInterpolationService": true
3-
}
1+
{
2+
"editor.detectIndentation": false,
3+
"editor.tabSize": 4
4+
}

commitlint.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
'type-case': [2, 'always', 'lower-case'],
5+
'type-empty': [2, 'never'],
6+
'type-enum': [
7+
2,
8+
'always',
9+
[
10+
'build',
11+
'chore',
12+
'ci',
13+
'docs',
14+
'feat',
15+
'fix',
16+
'merge',
17+
'perf',
18+
'refactor',
19+
'revert',
20+
'setup',
21+
'style',
22+
'test'
23+
]
24+
]
25+
}
26+
}

package.json

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
{
22
"name": "blog",
3-
"version": "0.0.0",
3+
"version": "2.0.0",
44
"scripts": {
55
"dev": "vite",
66
"build": "vite build",
7-
"serve": "vite preview"
7+
"serve": "vite preview",
8+
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .eslintignore .",
9+
"lint:style": "stylelint \"**/*.{vue,css}\" --ignore-path .eslintignore",
10+
"lint": "yarn lint:js && yarn lint:style"
11+
},
12+
"lint-staged": {
13+
"*.{js,vue}": "eslint",
14+
"*.{css,vue}": "stylelint"
15+
},
16+
"husky": {
17+
"hooks": {
18+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
19+
"pre-commit": "lint-staged"
20+
}
821
},
922
"dependencies": {
1023
"pinia": "^2.0.14",
@@ -15,6 +28,8 @@
1528
"devDependencies": {
1629
"@babel/core": "^7.18.6",
1730
"@babel/eslint-parser": "^7.18.2",
31+
"@commitlint/cli": "^17.0.3",
32+
"@commitlint/config-conventional": "^17.0.3",
1833
"@typescript-eslint/eslint-plugin": "^5.30.0",
1934
"@typescript-eslint/parser": "^5.30.0",
2035
"@vitejs/plugin-vue": "^1.1.4",
@@ -24,9 +39,15 @@
2439
"eslint-config-prettier": "^8.5.0",
2540
"eslint-plugin-prettier": "^4.2.1",
2641
"eslint-plugin-vue": "^9.1.1",
42+
"husky": "^8.0.1",
43+
"lint-staged": "^13.0.3",
2744
"prettier": "^2.7.1",
45+
"stylelint": "^14.9.1",
46+
"stylelint-config-prettier": "^9.0.3",
47+
"stylelint-config-standard": "^26.0.0",
2848
"typescript": "^4.1.3",
2949
"vite": "^2.0.1",
30-
"vite-plugin-eslint": "^1.6.1"
50+
"vite-plugin-eslint": "^1.6.1",
51+
"vue-eslint-parser": "^9.0.3"
3152
}
3253
}

prettier.config.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// 在项目根目录创建文件 .prettier.js
22
// 以下配置视自己情况而定,并步是每个都需要的
33
module.exports = {
4-
tabWidth: 4, // 使用4个空格缩进
5-
semi: false, // 代码结尾是否加分号
6-
trailingComma: 'none', // 代码末尾不需要逗号
7-
singleQuote: true, // 是否使用单引号
8-
printWidth: 100, // 超过多少字符强制换行
9-
arrowParens: 'avoid', // 单个参数的箭头函数不加括号 x => x
10-
bracketSpacing: true, // 对象大括号内两边是否加空格 { a:0 }
4+
tabWidth: 2, // 使用2个空格缩进
5+
semi: false, // 代码结尾是否加分号
6+
trailingComma: 'none', // 代码末尾不需要逗号
7+
singleQuote: true, // 是否使用单引号
8+
printWidth: 100, // 超过多少字符强制换行
9+
arrowParens: 'avoid', // 单个参数的箭头函数不加括号 x => x
10+
bracketSpacing: true, // 对象大括号内两边是否加空格 { a:0 }
1111

12-
endOfLine: 'auto', // 文件换行格式 LF/CRLF
13-
useTabs: false, // 不使用缩进符,而使用空格
14-
quoteProps: 'as-needed', // 对象的key仅在必要时用引号
15-
jsxSingleQuote: false, // jsx不使用单引号,而使用双引号
16-
jsxBracketSameLine: false, // jsx标签的反尖括号需要换行
17-
rangeStart: 0, // 每个文件格式化的范围是文件的全部内容
18-
rangeEnd: Infinity, // 结尾
19-
requirePragma: false, // 不需要写文件开头的 @prettier
20-
insertPragma: false, // 不需要自动在文件开头插入 @prettier
21-
proseWrap: 'preserve', // 使用默认的折行标准
22-
htmlWhitespaceSensitivity: 'css', // 根据显示样式决定html要不要折行
12+
endOfLine: 'auto', // 文件换行格式 LF/CRLF
13+
useTabs: false, // 不使用缩进符,而使用空格
14+
quoteProps: 'as-needed', // 对象的key仅在必要时用引号
15+
jsxSingleQuote: false, // jsx不使用单引号,而使用双引号
16+
jsxBracketSameLine: false, // jsx标签的反尖括号需要换行
17+
rangeStart: 0, // 每个文件格式化的范围是文件的全部内容
18+
rangeEnd: Infinity, // 结尾
19+
requirePragma: false, // 不需要写文件开头的 @prettier
20+
insertPragma: false, // 不需要自动在文件开头插入 @prettier
21+
proseWrap: 'preserve', // 使用默认的折行标准
22+
htmlWhitespaceSensitivity: 'css' // 根据显示样式决定html要不要折行
2323
}

src/App.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
import { defineComponent } from 'vue'
77
88
export default defineComponent({
9-
name: 'App',
9+
name: 'App'
1010
})
1111
</script>
1212

13-
<style>
14-
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800;900&display=swap');
15-
body {
16-
font-family: 'Poppins', sans-serif;
17-
}
13+
<style scoped lang="scss">
14+
@import './assets/style/font.scss';
15+
@import './assets/style/minireset.scss';
1816
</style>

src/assets/style/font.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800;900&display=swap');
2+
body {
3+
font-family: 'Poppins', sans-serif;
4+
}

0 commit comments

Comments
 (0)