feat: add eslint vue
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
{
|
{
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"useTabs": false
|
"useTabs": false,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": false,
|
||||||
|
"trailingComma": "all",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"objectWrap": "preserve",
|
||||||
|
"bracketSameLine": false,
|
||||||
|
"arrowParens": "always"
|
||||||
}
|
}
|
||||||
|
|||||||
167
eslint.config.js
167
eslint.config.js
@@ -1,155 +1,28 @@
|
|||||||
import js from '@eslint/js';
|
import eslint from "@eslint/js";
|
||||||
import { default as tsEslint } from 'typescript-eslint';
|
import eslintPluginVue from "eslint-plugin-vue";
|
||||||
import react from 'eslint-plugin-react';
|
import globals from "globals";
|
||||||
import reactHooks from 'eslint-plugin-react-hooks';
|
import typescriptEslint from "typescript-eslint";
|
||||||
import vue from 'eslint-plugin-vue';
|
|
||||||
import globals from 'globals';
|
|
||||||
|
|
||||||
const tsConfig = tsEslint.config(
|
export default typescriptEslint.config(
|
||||||
...tsEslint.configs.recommended,
|
{ ignores: ["*.d.ts", "**/coverage", "**/dist"] },
|
||||||
{
|
{
|
||||||
languageOptions: {
|
extends: [
|
||||||
parserOptions: {
|
eslint.configs.recommended,
|
||||||
ecmaFeatures: {
|
...typescriptEslint.configs.recommended,
|
||||||
jsx: false
|
...eslintPluginVue.configs["flat/recommended"],
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const tsxConfig = tsEslint.config(
|
|
||||||
...tsEslint.configs.recommended,
|
|
||||||
{
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
ecmaFeatures: {
|
|
||||||
jsx: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
react,
|
|
||||||
'react-hooks': reactHooks
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
...react.configs.recommended.rules,
|
|
||||||
...reactHooks.configs.recommended.rules,
|
|
||||||
'react/react-in-jsx-scope': 'off',
|
|
||||||
'react/prop-types': 'off'
|
|
||||||
},
|
|
||||||
settings: {
|
|
||||||
react: {
|
|
||||||
version: 'detect'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export default [
|
|
||||||
// 通用配置,适用于所有文件
|
|
||||||
{
|
|
||||||
ignores: [
|
|
||||||
'node_modules/**',
|
|
||||||
'dist/**',
|
|
||||||
'build/**',
|
|
||||||
'coverage/**',
|
|
||||||
'*.min.js',
|
|
||||||
'*.d.ts'
|
|
||||||
],
|
],
|
||||||
|
files: ["**/*.{ts,vue}"],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: {
|
ecmaVersion: "latest",
|
||||||
...globals.browser,
|
sourceType: "module",
|
||||||
...globals.node,
|
globals: globals.browser,
|
||||||
...globals.es2025
|
parserOptions: {
|
||||||
|
parser: typescriptEslint.parser,
|
||||||
},
|
},
|
||||||
ecmaVersion: 'latest',
|
|
||||||
sourceType: 'module'
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
// 通用规则
|
"vue/singleline-html-element-content-newline": "off",
|
||||||
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
"vue/max-attributes-per-line": "off",
|
||||||
'no-debugger': 'error',
|
},
|
||||||
'no-unused-vars': ['warn', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],
|
|
||||||
'no-undef': 'error',
|
|
||||||
'eqeqeq': ['error', 'always'],
|
|
||||||
'curly': ['error', 'all'],
|
|
||||||
'quotes': ['error', 'single', { avoidEscape: true }],
|
|
||||||
'semi': ['error', 'always'],
|
|
||||||
'indent': ['error', 2, { SwitchCase: 1 }],
|
|
||||||
'no-trailing-spaces': 'error',
|
|
||||||
'eol-last': ['error', 'always'],
|
|
||||||
'comma-dangle': ['error', 'always-multiline'],
|
|
||||||
'space-infix-ops': 'error',
|
|
||||||
'space-before-blocks': 'error',
|
|
||||||
'keyword-spacing': ['error', { before: true, after: true }],
|
|
||||||
'arrow-spacing': ['error', { before: true, after: true }]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
);
|
||||||
// JavaScript 配置
|
|
||||||
{
|
|
||||||
files: ['**/*.js'],
|
|
||||||
...js.configs.recommended
|
|
||||||
},
|
|
||||||
|
|
||||||
// JSX 配置
|
|
||||||
{
|
|
||||||
files: ['**/*.jsx'],
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
ecmaFeatures: {
|
|
||||||
jsx: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
react,
|
|
||||||
'react-hooks': reactHooks
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
...react.configs.recommended.rules,
|
|
||||||
...reactHooks.configs.recommended.rules,
|
|
||||||
'react/jsx-uses-react': 'error',
|
|
||||||
'react/jsx-uses-vars': 'error',
|
|
||||||
'react/react-in-jsx-scope': 'off', // React 17+ 不需要显式导入React
|
|
||||||
'react/prop-types': 'off'
|
|
||||||
},
|
|
||||||
settings: {
|
|
||||||
react: {
|
|
||||||
version: 'detect'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// TypeScript 配置
|
|
||||||
...tsConfig.map(config => ({
|
|
||||||
...config,
|
|
||||||
files: ['**/*.ts']
|
|
||||||
})),
|
|
||||||
|
|
||||||
// TSX 配置
|
|
||||||
...tsxConfig.map(config => ({
|
|
||||||
...config,
|
|
||||||
files: ['**/*.tsx']
|
|
||||||
})),
|
|
||||||
|
|
||||||
// Vue 配置
|
|
||||||
{
|
|
||||||
files: ['**/*.vue'],
|
|
||||||
...vue.configs['flat/essential'],
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
parser: tsEslint.parser
|
|
||||||
}
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
...vue.configs['flat/essential'].rules,
|
|
||||||
'vue/multi-word-component-names': 'warn',
|
|
||||||
'vue/script-setup-uses-vars': 'error',
|
|
||||||
'vue/no-unused-vars': 'warn',
|
|
||||||
'vue/require-prop-types': 'off'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,22 +10,14 @@ const merchandise = ref([
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const {
|
const { currentPage, changePage, pageNumbers, totalPages, getPaginatedData } =
|
||||||
currentPage,
|
usePagination(() => merchandise.value);
|
||||||
pageSize,
|
|
||||||
nextPage,
|
|
||||||
prevPage,
|
|
||||||
changePage,
|
|
||||||
pageNumbers,
|
|
||||||
totalPages,
|
|
||||||
getPaginatedData,
|
|
||||||
} = usePagination(() => merchandise.value);
|
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
changePage(page);
|
changePage(page);
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await new Promise(async (resolve, reject) => {
|
await new Promise(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
merchandise.value = Array.from(range(1, 50)).map((item) => ({
|
merchandise.value = Array.from(range(1, 50)).map((item) => ({
|
||||||
id: item,
|
id: item,
|
||||||
|
|||||||
Reference in New Issue
Block a user