Skip to content

Commit

Permalink
💄 chore: support stylistic eslint (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdsuwwz authored Apr 29, 2024
1 parent e5488d8 commit 3ef6433
Show file tree
Hide file tree
Showing 20 changed files with 4,104 additions and 4,591 deletions.
7 changes: 7 additions & 0 deletions .stylelintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ module.exports = {
'stylelint-config-recommended-vue',
'stylelint-config-recommended-vue/scss'
],
'plugins': ['@stylistic/stylelint-plugin'],
'ignoreFiles': ['**/*.js', '**/*.ts'],
'defaultSeverity': 'error',
'rules': {
'unit-disallowed-list': [
'rem',
'pt'
],
'@stylistic/indentation': [
2,
{
'baseIndentLevel': 0
}
],
'no-empty-source': null,
'block-no-empty': null,
'declaration-block-no-duplicate-custom-properties': null,
Expand Down
150 changes: 122 additions & 28 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// import antfu from '@antfu/eslint-config'
// export default antfu()

import globals from 'globals'
import { defineFlatConfig } from 'eslint-define-config'

Expand All @@ -11,12 +8,13 @@ import * as parserVue from 'vue-eslint-parser'
import pluginVue from 'eslint-plugin-vue'
import js from '@eslint/js'

import stylistic from '@stylistic/eslint-plugin'

function renameRules(rules, map) {
return Object.fromEntries(
Object.entries(rules).map(([key, value]) => {
for (const [from, to] of Object.entries(map)) {
if (key.startsWith(`${from}/`))
if (key.startsWith(`${ from }/`))
return [to + key.slice(from.length), value]
}
return [key, value]
Expand All @@ -35,6 +33,42 @@ export default defineFlatConfig([
'src/assets/**'
]
},
{
plugins: {
'@stylistic': stylistic
},
rules: {
'@stylistic/semi': ['error', 'never'],
'@stylistic/no-extra-semi': 'error',
'@stylistic/template-curly-spacing': ['error', 'always'],
'@stylistic/space-before-blocks': ['error', 'always'],
'@stylistic/indent': ['error', 2],
'@stylistic/object-curly-newline': ['error', {
'ObjectExpression': {
// 如果对象有属性,则要求换行。空对象则忽略
'minProperties': 1,
// 保持一致性
'consistent': true
}
}],
'@stylistic/object-property-newline': 'error',
'@stylistic/key-spacing': ['error', {
'beforeColon': false,
'afterColon': true
}],
'@stylistic/type-annotation-spacing': ['error', {
'before': true,
'after': true,
'overrides': {
'colon': {
'before': false,
'after': true
}
}
}],
'@stylistic/no-trailing-spaces': ['error']
}
},
{
...js.configs.recommended,
languageOptions: {
Expand All @@ -57,15 +91,27 @@ export default defineFlatConfig([
sourceType: 'module'
},
rules: {
'accessor-pairs': ['error', { enforceForClassMembers: true, setWithoutGet: true }],
'accessor-pairs': ['error', {
enforceForClassMembers: true,
setWithoutGet: true
}],
'array-callback-return': 'error',
'block-scoped-var': 'error',
'comma-spacing': ['error', { after: true, before: false }],
'comma-spacing': ['error', {
after: true,
before: false
}],
'constructor-super': 'error',
'default-case-last': 'error',
'dot-notation': ['error', { allowKeywords: true }],
'dot-notation': ['error', {
allowKeywords: true
}],
'eqeqeq': ['error', 'always'],
'new-cap': ['error', { capIsNew: false, newIsCap: true, properties: true }],
'new-cap': ['error', {
capIsNew: false,
newIsCap: true,
properties: true
}],
'no-alert': 'error',
'no-array-constructor': 'error',
'no-async-promise-executor': 'error',
Expand All @@ -74,7 +120,9 @@ export default defineFlatConfig([
'no-class-assign': 'error',
'no-compare-neg-zero': 'error',
'no-cond-assign': ['error', 'always'],
'no-console': ['error', { allow: ['log', 'warn', 'error'] }],
'no-console': ['error', {
allow: ['log', 'dir', 'warn', 'error']
}],
'no-const-assign': 'error',
'no-control-regex': 'error',
'no-debugger': 'error',
Expand All @@ -83,7 +131,9 @@ export default defineFlatConfig([
'no-dupe-class-members': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-empty': ['error', { allowEmptyCatch: true }],
'no-empty': ['error', {
allowEmptyCatch: true
}],
'no-empty-character-class': 'error',
'no-empty-pattern': 'error',
'no-eval': 'error',
Expand All @@ -99,7 +149,10 @@ export default defineFlatConfig([
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'error',
'no-iterator': 'error',
'no-labels': ['error', { allowLoop: false, allowSwitch: false }],
'no-labels': ['error', {
allowLoop: false,
allowSwitch: false
}],
'no-lone-blocks': 'error',
'no-loss-of-precision': 'error',
'no-misleading-character-class': 'error',
Expand All @@ -113,20 +166,43 @@ export default defineFlatConfig([
'no-octal-escape': 'error',
'no-proto': 'error',
'no-prototype-builtins': 'error',
'no-redeclare': ['error', { builtinGlobals: false }],
'no-redeclare': ['error', {
builtinGlobals: false
}],
'no-regex-spaces': 'error',
'no-restricted-globals': [
'error',
{ message: 'Use `globalThis` instead.', name: 'global' },
{ message: 'Use `globalThis` instead.', name: 'self' }
{
message: 'Use `globalThis` instead.',
name: 'global'
},
{
message: 'Use `globalThis` instead.',
name: 'self'
}
],
'no-restricted-properties': [
'error',
{ message: 'Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.', property: '__proto__' },
{ message: 'Use `Object.defineProperty` instead.', property: '__defineGetter__' },
{ message: 'Use `Object.defineProperty` instead.', property: '__defineSetter__' },
{ message: 'Use `Object.getOwnPropertyDescriptor` instead.', property: '__lookupGetter__' },
{ message: 'Use `Object.getOwnPropertyDescriptor` instead.', property: '__lookupSetter__' }
{
message: 'Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.',
property: '__proto__'
},
{
message: 'Use `Object.defineProperty` instead.',
property: '__defineGetter__'
},
{
message: 'Use `Object.defineProperty` instead.',
property: '__defineSetter__'
},
{
message: 'Use `Object.getOwnPropertyDescriptor` instead.',
property: '__lookupGetter__'
},
{
message: 'Use `Object.getOwnPropertyDescriptor` instead.',
property: '__lookupSetter__'
}
],
'no-restricted-syntax': [
'error',
Expand All @@ -136,7 +212,9 @@ export default defineFlatConfig([
'TSEnumDeclaration[const=true]',
'TSExportAssignment'
],
'no-self-assign': ['error', { props: true }],
'no-self-assign': ['error', {
props: true
}],
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow-restricted-names': 'error',
Expand All @@ -148,7 +226,9 @@ export default defineFlatConfig([
'no-undef-init': 'error',
'no-unexpected-multiline': 'error',
'no-unmodified-loop-condition': 'error',
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
'no-unneeded-ternary': ['error', {
defaultAssignment: false
}],
'no-unreachable': 'error',
'no-unreachable-loop': 'error',
'no-unsafe-finally': 'error',
Expand All @@ -164,7 +244,11 @@ export default defineFlatConfig([
ignoreRestSiblings: true,
vars: 'all'
}],
'no-use-before-define': ['error', { classes: false, functions: false, variables: true }],
'no-use-before-define': ['error', {
classes: false,
functions: false,
variables: true
}],
'no-useless-backreference': 'error',
'no-useless-call': 'error',
'no-useless-catch': 'error',
Expand All @@ -174,7 +258,6 @@ export default defineFlatConfig([
'no-useless-return': 'error',
'no-var': 'error',
'no-with': 'error',
'key-spacing': 'error',
'space-infix-ops': 'error',
'object-curly-spacing': ['error', 'always'],
'object-shorthand': [
Expand All @@ -185,7 +268,9 @@ export default defineFlatConfig([
ignoreConstructors: false
}
],
'one-var': ['error', { initialized: 'never' }],
'one-var': ['error', {
initialized: 'never'
}],
'prefer-arrow-callback': [
'error',
{
Expand All @@ -202,7 +287,9 @@ export default defineFlatConfig([
],
'prefer-exponentiation-operator': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }],
'prefer-regex-literals': ['error', {
disallowRedundantWrapping: true
}],
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
Expand Down Expand Up @@ -263,10 +350,14 @@ export default defineFlatConfig([
rules: {
...renameRules(
pluginTypeScript.configs['eslint-recommended'].overrides[0].rules,
{ '@typescript-eslint': 'ts' }
{
'@typescript-eslint': 'ts'
}
),
...pluginTypeScript.configs.recommended.rules,
'@typescript-eslint/indent': ['error', 2, { SwitchCase: 1 }],
'@typescript-eslint/indent': ['error', 2, {
SwitchCase: 1
}],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 1,
Expand All @@ -285,7 +376,10 @@ export default defineFlatConfig([
],
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/semi': ['error', 'never']
'@typescript-eslint/consistent-type-imports': ['error', {
fixStyle: 'separate-type-imports',
disallowTypeAnnotations: false
}]
}
},
{
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,32 @@
"@vueuse/core": "^10.9.0",
"axios": "1.6.8",
"echarts": "^5.5.0",
"element-plus": "2.7.1",
"element-plus": "2.7.2",
"js-cookie": "^3.0.5",
"nprogress": "^0.2.0",
"pinia": "^2.1.7",
"uuid": "^9.0.1",
"vue": "^3.4.25",
"vue": "^3.4.26",
"vue-i18n": "^9.13.1",
"vue-router": "^4.3.2"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"@eslint/js": "^9.1.1",
"@iconify/json": "^2.2.203",
"@iconify/json": "^2.2.205",
"@iconify/vue": "^4.1.2",
"@stylistic/eslint-plugin": "^1.7.2",
"@stylistic/stylelint-plugin": "^2.1.2",
"@types/js-cookie": "^3.0.6",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.12.7",
"@types/nprogress": "^0.2.3",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"@vitejs/plugin-vue": "^5.0.4",
"@vitest/coverage-v8": "^1.5.1",
"@vue/compiler-sfc": "^3.4.25",
"@vitest/coverage-v8": "^1.5.2",
"@vue/compiler-sfc": "^3.4.26",
"@vue/test-utils": "2.4.5",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"cross-env": "^7.0.3",
Expand All @@ -84,14 +86,14 @@
"eslint-plugin-html": "8.1.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-vue": "^9.25.0",
"globals": "^15.0.0",
"globals": "^15.1.0",
"identity-obj-proxy": "^3.0.0",
"jsdom": "^24.0.0",
"lodash-es": "^4.17.21",
"postcss": "^8.4.38",
"postcss-html": "^1.6.0",
"postcss-scss": "^4.0.9",
"rollup": "^4.16.4",
"rollup": "^4.17.1",
"sass": "^1.75.0",
"stylelint": "^16.4.0",
"stylelint-config-recommended-scss": "14.0.0",
Expand All @@ -105,6 +107,7 @@
"unplugin-icons": "^0.18.5",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.2.10",
"vitest": "^1.5.1"
"vitest": "^1.5.2",
"vue-eslint-parser": "^9.4.2"
}
}
Loading

0 comments on commit 3ef6433

Please sign in to comment.