Skip to content

Commit

Permalink
Migrate eslint to flat config.
Browse files Browse the repository at this point in the history
  • Loading branch information
logue committed Apr 23, 2024
1 parent 1ce6efa commit ad5d7e9
Show file tree
Hide file tree
Showing 9 changed files with 453 additions and 416 deletions.
102 changes: 0 additions & 102 deletions .eslintrc.yml

This file was deleted.

1 change: 0 additions & 1 deletion env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface ImportMetaEnv {
readonly VITE_APP_WEBSTORAGE_NAMESPACE: string;
}

// eslint-disable-next-line no-unused-vars
interface ImportMeta {
readonly env: ImportMetaEnv;
}
171 changes: 171 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintConfigPrettier from 'eslint-config-prettier';

import pluginImport from 'eslint-plugin-import';
import pluginTsdoc from 'eslint-plugin-tsdoc';
// import pluginVue from 'eslint-plugin-vue';
import pluginVuetify from 'eslint-plugin-vuetify';
import pluginYaml from 'eslint-plugin-yaml';

/**
* ESLint Config
*/
// @ts-check
export default tseslint.config(
{
ignores: [
'.vscode/',
'.yarn/',
'dist/',
'public/',
'src/** /*.generated.*',
'eslint.config.js',
],
},
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
{
languageOptions: {
parserOptions: {
project: [
'tsconfig.app.json',
'tsconfig.node.json',
'tsconfig.vitest.json',
],
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.vue'],
ecmaVersion: 'latest',
sourceType: 'module',
},
},
plugins: {
import: pluginImport,
tsdoc: pluginTsdoc,
// vue: pluginVue,
vuetify: pluginVuetify,
yaml: pluginYaml,
},
settings: {
// This will do the trick
'import/parsers': {
espree: ['.js', '.cjs', '.mjs', '.jsx'],
'@typescript-eslint/parser': ['.ts', '.tsx'],
'vue-eslint-parser': ['.vue'],
},
'import/resolver': {
typescript: true,
node: true,
alias: {
map: [
['@', './src'],
['~', './node_modules'],
],
extensions: ['.js', '.ts', '.jsx', '.tsx', '.vue'],
},
},
vite: {
configPath: './vite.config.ts',
},
},
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-import-type-side-effects': 'error',
// ...importPlugin.configs["recommended"].rules,
'no-unused-vars': 'warn',
// const lines: string[] = []; style
'@typescript-eslint/array-type': [
'error',
{
default: 'array',
},
],
// Enable @ts-ignore etc.
'@typescript-eslint/ban-ts-comment': 'off',
// Left-hand side style
'@typescript-eslint/consistent-generic-constructors': [
'error',
'type-annotation',
],
// Enable import sort order, see bellow.
'@typescript-eslint/consistent-type-imports': [
'off',
{
prefer: 'type-imports',
},
],
// Fix for pinia
'@typescript-eslint/explicit-function-return-type': 'off',
// Allow short land for pretter
'@typescript-eslint/no-confusing-void-expression': [
'error',
{
ignoreArrowShorthand: true,
},
],
// Fix for vite import.meta.env
'@typescript-eslint/strict-boolean-expressions': 'off',
// Fix for vite env.d.ts.
'@typescript-eslint/triple-slash-reference': 'off',
// Fix for Vue setup style
'import/default': 'off',
// Fix for Vue setup style
'import/no-default-export': 'off',
// Sort Import Order.
// see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#importorder-enforce-a-convention-in-module-import-order
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'parent',
'sibling',
'index',
'object',
'type',
],
pathGroups: [
// Vue Core
{
pattern:
'{vue,vue-router,vuex,@/stores,vue-i18n,pinia,vite,vitest,vitest/**,@vitejs/**,@vue/**}',
group: 'external',
position: 'before',
},
// Internal Codes
{
pattern: '{@/**}',
group: 'internal',
position: 'before',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
alphabetize: {
order: 'asc',
},
'newlines-between': 'always',
},
],
'tsdoc/syntax': 'warn',
/*
// A tag with no content should be written like <br />.
'vue/html-self-closing': [
'error',
{
html: {
void: 'always',
},
},
],
// Mitigate non-multiword component name errors to warnings.
'vue/multi-word-component-names': 'warn',
// for Vuetify Labs Fix (v-data-tables etc.)
'vuetify/no-deprecated-components': 'warn',
*/
},
},
// ...pluginVue.configs['flat/recommended'],
eslintConfigPrettier
);
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/package.json",
"name": "vite-vuetify-ts-starter",
"description": "Vue3 Vuetify TypeScript Startar project for Vite.",
"version": "1.9.3",
"version": "1.10.0",
"license": "MIT",
"type": "module",
"private": true,
Expand Down Expand Up @@ -30,7 +30,7 @@
"build": "run-p type-check \"build-only {@}\" --",
"build:analyze": "vite build --mode analyze",
"build:clean": "rimraf dist",
"lint": "eslint -c .eslintrc.yml . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
"lint:style": "stylelint \"./**/*.{css,sass,scss,htm,html,vue}\" --fix --cache-location ./node_modules/.vite/vite-plugin-stylelint && prettier \"./**/*.{css,sass,scss,htm,html,vue}\" -w -u",
"preview": "vite preview",
"test:unit": "vitest",
Expand All @@ -44,26 +44,26 @@
"core-js": "^3.37.0",
"pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.1",
"vue": "^3.4.23",
"vue": "^3.4.24",
"vue-router": "^4.3.2",
"vuetify": "^3.5.16",
"webfontloader": "^1.6.28"
},
"devDependencies": {
"@babel/types": "^7.24.0",
"@eslint/js": "^9.1.1",
"@rushstack/eslint-patch": "^1.10.2",
"@tsconfig/node-lts": "^20.1.3",
"@types/jsdom": "^21.1.6",
"@types/node": "^20.12.7",
"@types/webfontloader": "^1.6.38",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@vitejs/plugin-vue": "^5.0.4",
"@vitest/coverage-c8": "^0.33.0",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/test-utils": "^2.4.5",
"@vue/tsconfig": "^0.5.1",
"eslint": "^8.57.0",
"eslint": "^9.1.1",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
Expand All @@ -90,12 +90,13 @@
"stylelint-config-recommended-scss": "^14.0.0",
"stylelint-config-recommended-vue": "^1.5.0",
"stylelint-order": "^6.0.4",
"typescript": "*",
"vite": "^5.2.9",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.1",
"vite": "^5.2.10",
"vite-plugin-checker": "0.6.4",
"vite-plugin-vuetify": "^2.0.3",
"vitest": "^1.5.0",
"vue-tsc": "^2.0.13"
"vue-tsc": "^2.0.14"
},
"husky": {
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*/

// Load vue core
import store from '@/store';
import { createApp } from 'vue';

import App from '@/App.vue';
import vuetify from '@/plugins/vuetify';
import router from '@/router';
import store from '@/store';

/** Register Vue */
const vue = createApp(App);
Expand Down
2 changes: 1 addition & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useGlobal } from '@/store';
import {
createRouter,
createWebHistory,
Expand All @@ -8,6 +7,7 @@ import {
type RouteRecordRaw,
} from 'vue-router';

import { useGlobal } from '@/store';
// Components
import HomeView from '@/views/HomeView.vue';

Expand Down
2 changes: 1 addition & 1 deletion src/store/GlobalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default defineStore('global', () => {
*
* @param msg - snackbar message
*/
function setMessage(msg: string = ''): void {
function setMessage(msg = ''): void {
// put snackbar text
message.value = msg;
}
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default defineConfig(({ command, mode }): UserConfig => {
// Write meta data.
writeFileSync(
fileURLToPath(new URL('./src/Meta.ts', import.meta.url)),
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions

`import type MetaInterface from '@/interfaces/MetaInterface';
// This file is auto-generated by the build system.
Expand Down
Loading

0 comments on commit ad5d7e9

Please sign in to comment.