添加eslint

This commit is contained in:
chuan_wuhao 2022-11-10 13:35:34 +08:00
parent db1806e4eb
commit 2e4508dde7
15 changed files with 1579 additions and 50 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
dist/.DS_Store vendored

Binary file not shown.

View File

@ -23,21 +23,35 @@
"vue-router": "^4.1.3" "vue-router": "^4.1.3"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.20.2",
"@babel/eslint-parser": "^7.19.1",
"@intlify/unplugin-vue-i18n": "^0.5.0", "@intlify/unplugin-vue-i18n": "^0.5.0",
"@types/crypto-js": "^4.1.1", "@types/crypto-js": "^4.1.1",
"@types/scrollreveal": "^0.0.8", "@types/scrollreveal": "^0.0.8",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"@vitejs/plugin-vue": "^3.0.0", "@vitejs/plugin-vue": "^3.0.0",
"@vitejs/plugin-vue-jsx": "^2.0.0", "@vitejs/plugin-vue-jsx": "^2.0.0",
"autoprefixer": "^10.4.8", "autoprefixer": "^10.4.8",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-vue": "^9.7.0",
"postcss": "^8.1.0", "postcss": "^8.1.0",
"postcss-pxtorem": "^6.0.0", "postcss-pxtorem": "^6.0.0",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"svg-sprite-loader": "^6.0.11", "svg-sprite-loader": "^6.0.11",
"typescript": "^4.6.4", "typescript": "*",
"unplugin-auto-import": "^0.11.0", "unplugin-auto-import": "^0.11.0",
"unplugin-vue-components": "^0.22.0", "unplugin-vue-components": "^0.22.0",
"vite": "^3.0.0", "vite": "^3.0.0",
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-inspect": "^0.6.0", "vite-plugin-inspect": "^0.6.0",
"vite-plugin-svg-icons": "^2.0.1", "vite-plugin-svg-icons": "^2.0.1",
"vite-svg-loader": "^3.4.0", "vite-svg-loader": "^3.4.0",

BIN
src/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@ -1,16 +1,14 @@
import { createI18n } from 'vue-i18n' import { createI18n } from 'vue-i18n'
import messages from '@intlify/unplugin-vue-i18n/messages' import messages from '@intlify/unplugin-vue-i18n/messages'
import { useGetCache } from '@use-utils/cache' import { getCache } from '@use-utils/cache'
import type { App } from 'vue' import type { App } from 'vue'
export const setupI18n = (app: App<Element>) => { export const setupI18n = (app: App<Element>) => {
const i18n = createI18n({ const i18n = createI18n({
locale: locale:
useGetCache('languageType') !== 'no' getCache('languageType') !== 'no' ? getCache('languageType') : 'zh-CN',
? useGetCache('languageType')
: 'zh-CN',
allowComposition: true, // you need to specify that! allowComposition: true, // you need to specify that!
messages, messages,
}) })

View File

@ -3,7 +3,9 @@ import type { RouteRecordRaw } from 'vue-router'
const route = import.meta.glob('./*.ts', { eager: true }) as IUnknownObjectKey const route = import.meta.glob('./*.ts', { eager: true }) as IUnknownObjectKey
const routes = Object.keys(route).reduce((modules, modulePath) => { const routes = Object.keys(route).reduce((modules, modulePath) => {
modules.push(route[modulePath].default) const _default = route[modulePath]
modules.push(_default as unknown as RouteRecordRaw)
return modules return modules
}, [] as RouteRecordRaw[]) }, [] as RouteRecordRaw[])

View File

@ -4,7 +4,7 @@ import type CryptoJS from 'crypto-js'
export global { export global {
declare interface IUnknownObjectKey { declare interface IUnknownObjectKey {
[propName: string]: any [propName: string]: unknown
} }
declare type EventListenerOrEventListenerObject = declare type EventListenerOrEventListenerObject =

View File

@ -3,16 +3,19 @@
* @param key key * @param key key
* @param value * @param value
*/ */
export const useSetCache = <T>( export const setCache = <T>(
key: string, key: string,
value: T, value: T,
type: CacheType = 'sessionStorage', type: CacheType = 'sessionStorage',
) => { ) => {
const waitCacheValue = JSON.stringify(value) const waitCacheValue = JSON.stringify(value)
const func =
type === 'localStorage' type === 'localStorage'
? window.localStorage.setItem(key, waitCacheValue) ? window.localStorage.setItem
: window.sessionStorage.setItem(key, waitCacheValue) : window.sessionStorage.setItem
func(key, waitCacheValue)
} }
/** /**
@ -21,11 +24,8 @@ export const useSetCache = <T>(
* *
* @returns * @returns
*/ */
export const useGetCache = ( export const getCache = (key: string, type: CacheType = 'sessionStorage') => {
key: string, const data =
type: CacheType = 'sessionStorage',
) => {
let data =
type === 'localStorage' type === 'localStorage'
? window.localStorage.getItem(key) ? window.localStorage.getItem(key)
: window.sessionStorage.getItem(key) : window.sessionStorage.getItem(key)
@ -37,7 +37,7 @@ export const useGetCache = (
* *
* @param key key * @param key key
*/ */
export const useRemoveCache = ( export const removeCache = (
key: string | 'all' | 'all-sessionStorage' | 'all-localStorage', key: string | 'all' | 'all-sessionStorage' | 'all-localStorage',
type: CacheType = 'sessionStorage', type: CacheType = 'sessionStorage',
) => { ) => {
@ -49,8 +49,11 @@ export const useRemoveCache = (
} else if (key === 'all-localStorage') { } else if (key === 'all-localStorage') {
window.localStorage.clear() window.localStorage.clear()
} else { } else {
const func =
type === 'localStorage' type === 'localStorage'
? window.localStorage.removeItem(key) ? window.localStorage.removeItem
: window.sessionStorage.removeItem(key) : window.sessionStorage.removeItem
func(key)
} }
} }

View File

@ -135,10 +135,14 @@ export const addStyle = (
el.style[item] = styles[item] el.style[item] = styles[item]
}) })
} else if (useValidteValueType(styles, 'String')) { } else if (useValidteValueType(styles, 'String')) {
;(styles as string).split(';').forEach((item) => { const _styles = styles as string
_styles.split(';').forEach((item) => {
const [_k, _v] = item.split(':') const [_k, _v] = item.split(':')
_k && _v && (el.style[_k.trim()] = _v.trim()) if (_k && _v) {
el.style[_k.trim()] = _v.trim()
}
}) })
} }
} }

View File

@ -191,20 +191,20 @@ export const useViteServerPlugin = (options?: ServerOptions) => {
} }
export const useEnvBuildOutput = (mode: string) => { export const useEnvBuildOutput = (mode: string) => {
let buildOptions = { const buildOptions: BuildOptions = {
outDir: 'dist/test-dist', outDir: 'dist/test-dist',
sourcemap: false, sourcemap: false,
terserOptions: { terserOptions: {
compress: { compress: {
drop_console: true, // 打包后移除console drop_console: true, // 打包后移除 `console`
drop_debugger: true, // 打包后移除debugger drop_debugger: true, // 打包后移除 `debugger`
}, },
}, },
} }
switch (mode) { switch (mode) {
case 'test': case 'test':
buildOptions = { Object.assign(buildOptions, {
outDir: 'dist/test-dist', outDir: 'dist/test-dist',
sourcemap: true, sourcemap: true,
terserOptions: { terserOptions: {
@ -213,11 +213,12 @@ export const useEnvBuildOutput = (mode: string) => {
drop_debugger: false, drop_debugger: false,
}, },
}, },
} })
break break
case 'development': case 'development':
buildOptions = { Object.assign(buildOptions, {
outDir: 'dist/development-dist', outDir: 'dist/development-dist',
sourcemap: true, sourcemap: true,
terserOptions: { terserOptions: {
@ -226,11 +227,12 @@ export const useEnvBuildOutput = (mode: string) => {
drop_debugger: false, drop_debugger: false,
}, },
}, },
} })
break break
case 'production': case 'production':
buildOptions = { Object.assign(buildOptions, {
outDir: 'dist/production-dist', outDir: 'dist/production-dist',
sourcemap: false, sourcemap: false,
terserOptions: { terserOptions: {
@ -239,7 +241,10 @@ export const useEnvBuildOutput = (mode: string) => {
drop_debugger: true, drop_debugger: true,
}, },
}, },
} })
break
default:
break break
} }

View File

@ -32,7 +32,7 @@ export interface VitePluginCompression {
/** /**
* Compression Options * Compression Options
*/ */
compressionOptions?: {} compressionOptions?: object
/** /**
* Delete the corresponding source file after compressing the file * Delete the corresponding source file after compressing the file
* @default: false * @default: false

View File

@ -17,6 +17,7 @@ import vueJsx from '@vitejs/plugin-vue-jsx'
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite' import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
import ViteInspect from 'vite-plugin-inspect' import ViteInspect from 'vite-plugin-inspect'
import viteSvgLoader from 'vite-svg-loader' import viteSvgLoader from 'vite-svg-loader'
import viteEslintPlugin from 'vite-plugin-eslint'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => { export default defineConfig(async ({ mode }) => {
@ -40,6 +41,17 @@ export default defineConfig(async ({ mode }) => {
defaultImport: 'component', // 默认以 `componetn` 形式导入 `svg` defaultImport: 'component', // 默认以 `componetn` 形式导入 `svg`
}), }),
useSVGIcon(), useSVGIcon(),
viteEslintPlugin,
{
include: [
'src/**/*.ts',
'src/**/*.tsx',
'src/**/*.vue',
'src/*.ts',
'src/*.tsx',
'src/*.vue',
],
},
], ],
optimizeDeps: { optimizeDeps: {
include: ['vue', 'vue-router', 'pinia', 'vue-i18n', '@vueuse/core'], include: ['vue', 'vue-router', 'pinia', 'vue-i18n', '@vueuse/core'],

1527
yarn.lock

File diff suppressed because it is too large Load Diff