Skip to content

Commit

Permalink
feat: add stylelistic rules
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Jan 12, 2024
1 parent dc88a13 commit 2763565
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 48 deletions.
3 changes: 3 additions & 0 deletions babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
'@babel',
],
rules: {
// 禁止使用未定义的变量
'no-undef': 'off',
'@babel/no-undef': 'error',
// 禁止使用某些表达式代替对应语句
'no-unused-expressions': 'off',
'@babel/no-unused-expressions': config.rules['no-unused-expressions'],
Expand Down
3 changes: 3 additions & 0 deletions flat/babel/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default [
'@babel': babelPlugin,
},
rules: {
// 禁止使用未定义的变量
'no-undef': 'off',
'@babel/no-undef': 'error',
// 禁止使用某些表达式代替对应语句
'no-unused-expressions': 'off',
'@babel/no-unused-expressions': jsConfig[jsConfig.length - 1].rules['no-unused-expressions'],
Expand Down
6 changes: 4 additions & 2 deletions flat/stylistic.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import stylisticJsPlugin from '@stylistic/eslint-plugin-js'
import stylisticPlusPlugin from '@stylistic/eslint-plugin-plus'
import { PATTERN_ALL } from './pattern.mjs'

export default [
{
files: [PATTERN_ALL],
plugins: {
'@stylistic/js': stylisticJsPlugin,
'@stylistic/plus': stylisticPlusPlugin,
},
rules: {
// 自动优化数组的两侧括号换行(前括号和后括号保持一致)
Expand All @@ -30,10 +32,10 @@ export default [
'@stylistic/js/dot-location': ['error', 'property'],
// 自动为文件末尾保留一行空行
'@stylistic/js/eol-last': ['warn', 'always'],
// 自动删除函数调用的括号前的空格
'@stylistic/js/func-call-spacing': 'warn',
// 自动优化函数调用的参数列表换行(所有元素保持一致)
'@stylistic/js/function-call-argument-newline': ['warn', 'consistent'],
// 自动删除函数调用的括号前的空格
'@stylistic/js/function-call-spacing': 'warn',
// 自动优化函数声明的参数列表换行(所有元素保持一致)
'@stylistic/js/function-paren-newline': ['warn', 'multiline-arguments'],
// 自动优化缩进为两个空格
Expand Down
15 changes: 13 additions & 2 deletions flat/typescript/stylistic.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import stylisticPlusPlugin from '@stylistic/eslint-plugin-plus'
import stylisticTsPlugin from '@stylistic/eslint-plugin-ts'
import { PATTERN_ALL } from '../pattern.mjs'
import jsConfig from '../stylistic.mjs'

export default [
{
files: [PATTERN_ALL],
plugins: {
'@stylistic/plus': stylisticPlusPlugin,
'@stylistic/ts': stylisticTsPlugin,
},
rules: {
// 自动优化花括号为 one true 风格(左侧花括号前不换行,else 前也不换行)
'@stylistic/js/brace-style': 'off',
Expand All @@ -15,8 +21,8 @@ export default [
'@stylistic/js/comma-spacing': 'off',
'@stylistic/ts/comma-spacing': jsConfig[0].rules['@stylistic/js/comma-spacing'],
// 自动删除函数调用的括号前的空格
'@stylistic/js/func-call-spacing': 'off',
'@stylistic/ts/func-call-spacing': jsConfig[0].rules['@stylistic/js/func-call-spacing'],
'@stylistic/js/function-call-spacing': 'off',
'@stylistic/ts/function-call-spacing': jsConfig[0].rules['@stylistic/js/function-call-spacing'],
// 自动优化缩进为两个空格
'@stylistic/js/indent': 'off',
'@stylistic/ts/indent': jsConfig[0].rules['@stylistic/js/indent'],
Expand Down Expand Up @@ -47,6 +53,11 @@ export default [
// 自动在多元操作符前后添加空格
'@stylistic/js/space-infix-ops': 'off',
'@stylistic/ts/space-infix-ops': jsConfig[0].rules['@stylistic/js/space-infix-ops'],

// 自动优化类型参数间的空格
'@stylistic/plus/type-generic-spacing': 'warn',
// 自动优化命名类型元组间的空格
'@stylistic/plus/type-named-tuple-spacing': 'warn',
},
},
]
2 changes: 1 addition & 1 deletion flat/vue/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default [
// 禁止使用 == 隐式类型转换
'vue/eqeqeq': jsConfig[jsConfig.length - 1].rules['eqeqeq'],
// 自动删除函数调用的括号前的空格
'vue/func-call-spacing': stylisticJsConfig[0].rules['@stylistic/js/func-call-spacing'],
'vue/func-call-spacing': stylisticJsConfig[0].rules['@stylistic/js/function-call-spacing'],
// 自动优化对象字面量冒号的空格使用(冒号前禁止使用空格,冒号后必须使用空格)
'vue/key-spacing': stylisticJsConfig[0].rules['@stylistic/js/key-spacing'],
// 自动在关键字前后添加空格
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
"license": "ISC",
"peerDependencies": {
"@babel/eslint-parser": ">=7.15.7",
"@babel/eslint-plugin": ">=7.14.5",
"@stylistic/eslint-plugin-js": ">=1.0.0",
"@stylistic/eslint-plugin-ts": ">=1.0.0",
"@babel/eslint-plugin": ">=7.13.5",
"@stylistic/eslint-plugin-js": ">=1.2.0",
"@stylistic/eslint-plugin-plus": ">=1.5.0",
"@stylistic/eslint-plugin-ts": ">=1.2.0",
"@typescript-eslint/eslint-plugin": ">=6.9.1",
"@typescript-eslint/parser": ">=6.9.1",
"eslint": ">=8.50.0",
Expand Down Expand Up @@ -88,8 +89,8 @@
},
"devDependencies": {
"@release-it/conventional-changelog": "^8.0.1",
"@stylistic/eslint-plugin-js": "^1.0.0",
"eslint": "^8.50.0",
"release-it": "^17.0.0"
"@stylistic/eslint-plugin-js": "^1.5.3",
"eslint": "^8.56.0",
"release-it": "^17.0.1"
}
}
Loading

0 comments on commit 2763565

Please sign in to comment.