Skip to content

Commit

Permalink
Modernize codebase Sept 2023
Browse files Browse the repository at this point in the history
- Update tsconfig
- Update eslint
- Replace ajv with typebox
- Replace babel/jest with vitest
  • Loading branch information
Trinovantes committed Sep 26, 2023
1 parent ca8bdd9 commit 6f7fff6
Show file tree
Hide file tree
Showing 28 changed files with 1,805 additions and 3,786 deletions.
162 changes: 63 additions & 99 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/* eslint-disable quote-props */

// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path')

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
const INLINE_ELEMENTS = require('eslint-plugin-vue/lib/utils/inline-non-void-elements.json')

module.exports = {
Expand All @@ -12,10 +7,10 @@ module.exports = {
parserOptions: {
extraFileExtensions: ['.vue'],
parser: '@typescript-eslint/parser',
project: path.resolve(__dirname, './tsconfig.json'),
project: './tsconfig.json',
tsconfigRootDir: __dirname,
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaVersion: 'latest',
sourceType: 'module',
},

// Predefines global variables (e.g. browser env predefines 'window' variable)
Expand All @@ -25,89 +20,68 @@ module.exports = {
'vue/setup-compiler-macros': true,
},

// Disable warnings for variables that are accessed but not defined in same file
globals: {
'DEFINE': 'readonly',
},

// Rules order is important, please avoid shuffling them
extends: [
'standard',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:vue/vue3-recommended',
],

plugins: [
'@typescript-eslint',
'import',
'vue',
],

settings: {
'import/resolver': {
'typescript': {
'alwaysTryTypes': true,
},
},
},

rules: {
'generator-star-spacing': ['error', 'before'],
semi: 'off',
'comma-dangle': 'off',

'arrow-parens': ['error', 'always'],
'one-var': ['error', 'never'],
'no-void': ['error', {
allowAsStatement: true,
}],
'eol-last': ['error', 'always'],
'generator-star-spacing': ['error', 'before'],
'no-trailing-spaces': 'error',
'space-before-blocks': ['error', 'always'],

'import/first': 'off',
'import/named': 'error',
'import/namespace': 'error',
'import/default': 'error',
'import/export': 'error',
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',
'import/order': ['error', {
warnOnUnassignedImports: true,
alphabetize: {
order: 'asc',
caseInsensitive: false,
'space-before-function-paren': ['error', 'never'],
indent: ['error', 4, {
SwitchCase: 1,
}],
'no-multi-spaces': ['error', {
exceptions: {
Property: true,
VariableDeclarator: true,
ImportDeclaration: false,
},
pathGroups: [
{
'pattern': '@/**',
'group': 'parent',
},
],
groups: [
'builtin', 'external', 'parent', 'sibling', 'index', 'object', 'type',
],
ignoreEOLComments: true,
}],

'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],

'space-before-function-paren': ['error', 'never'],
'indent': ['error', 4, {
'SwitchCase': 1,
'no-empty-pattern': ['error', {
allowObjectPatternsAsParameters: true,
}],
'no-void': ['error', {
allowAsStatement: true,
}],
quotes: ['error', 'single', {
avoidEscape: true,
allowTemplateLiterals: false,
}],

'vue/html-indent': ['error', 4],
'vue/max-attributes-per-line': ['error', {
singleline: 999,
multiline: 1,
}],

'vue/singleline-html-element-content-newline': ['error', {
'ignores': ['ExternalLink', 'pre', 'router-link', ...INLINE_ELEMENTS],
}],

'vue/component-tags-order': ['error', {
'order': ['script', 'template', 'style'],
order: ['script', 'template', 'style'],
}],
'vue/singleline-html-element-content-newline': ['error', {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
ignores: ['ExternalLink', 'router-link', 'pre', ...INLINE_ELEMENTS],
}],

'@typescript-eslint/prefer-literal-enum-member': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/restrict-template-expressions': ['error', {
allowNumber: true,
Expand All @@ -119,14 +93,14 @@ module.exports = {
ignoreParameters: false,
ignoreProperties: true,
}],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/consistent-type-assertions': ['error', {
assertionStyle: 'as',
objectLiteralTypeAssertions: 'never',
}],
'@typescript-eslint/array-type': ['error', {
default: 'generic',
}],

'@typescript-eslint/member-delimiter-style': ['error', {
multiline: {
delimiter: 'none',
Expand All @@ -137,52 +111,42 @@ module.exports = {
requireLast: false,
},
}],

'semi': 'off',
'@typescript-eslint/semi': ['error', 'never'],

'no-debugger': 'error',

'@typescript-eslint/naming-convention': [
'error',
'@typescript-eslint/strict-boolean-expressions': ['error', {
allowNullableBoolean: true,
allowNullableString: true,
}],
'@typescript-eslint/naming-convention': ['error',
{
'selector': 'default',
'format': null,
'modifiers': ['requiresQuotes'],
selector: 'default',
format: null,
modifiers: ['requiresQuotes'],
},
{
'selector': 'typeLike',
'format': ['PascalCase'],
selector: 'typeLike',
format: ['PascalCase'],
},
{
'selector': 'parameter',
'format': ['strictCamelCase'],
'leadingUnderscore': 'allow',
selector: 'parameter',
format: ['strictCamelCase'],
leadingUnderscore: 'allow',
},
{
'selector': 'memberLike',
'modifiers': ['private'],
'format': ['strictCamelCase'],
'leadingUnderscore': 'require',
selector: 'memberLike',
modifiers: ['private'],
format: ['strictCamelCase'],
leadingUnderscore: 'require',
},
{
'selector': [
selector: [
'variableLike',
'method',
],
'filter': {
'regex': '^update:',
'match': false,
filter: {
regex: '^update:',
match: false,
},
'format': ['strictCamelCase', 'UPPER_CASE'],
format: ['strictCamelCase', 'UPPER_CASE'],
},
],

'@typescript-eslint/strict-boolean-expressions': ['error', {
allowNullableBoolean: true,
allowNullableString: true,
}],

'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
},
}
13 changes: 5 additions & 8 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ on:
tags:
- v*
paths-ignore:
- .github/**
- .vscode/**
- README.md
- .vscode
- .editorconfig
- .gitignore
- README.md

jobs:
release-build:
Expand All @@ -20,18 +19,16 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Save yarn cache location to env
run: echo "YARN_CACHE=$(yarn cache dir)" >> $GITHUB_ENV

- name: Cache node_modules
uses: actions/cache@v2
env:
CACHE_NAME: cache-node-modules
uses: actions/cache@v3
with:
path: ${{ env.YARN_CACHE }}
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('**/yarn.lock', '**/package-lock.json') }}
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock', '**/package-lock.json') }}

- name: Install dependencies
run: yarn install
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ dist*
.tern-port

# Playwright
tests/e2e/results/
/test-results/
/playwright-report/
/playwright/.cache/
29 changes: 0 additions & 29 deletions babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion example/@types/vue-shims.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module '*.vue' {
import type { ComponentOptions } from 'vue'
import { ComponentOptions } from 'vue'
const component: ComponentOptions
export default component
}
4 changes: 2 additions & 2 deletions example/src/AppContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SSRContext } from '@vue/server-renderer'
import type express from 'express'
import { SSRContext } from '@vue/server-renderer'
import express from 'express'

type QuasarSsrContext = {
req: express.Request
Expand Down
12 changes: 6 additions & 6 deletions example/src/createVueApp.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Quasar } from 'quasar'
import { Quasar, QuasarPluginOptions } from 'quasar'
import { createSSRApp } from 'vue'
import App from './components/App.vue'
import { createAppRouter } from './router'
import type { AppContext } from './AppContext'
import type { createRouter } from 'vue-router'
import { AppContext } from './AppContext'
import { createRouter } from 'vue-router'

type VueApp = {
app: ReturnType<typeof createSSRApp>
router: ReturnType<typeof createRouter>
}

export async function createVueApp(ssrContext?: AppContext): Promise<VueApp> {
export async function createVueApp(appContext?: AppContext): Promise<VueApp> {
// Vue
const app = createSSRApp(App)

// Vue Router
const router = await createAppRouter(ssrContext)
const router = await createAppRouter(appContext)
app.use(router)
await router.isReady()

// Quasar
app.use(Quasar, {}, ssrContext)
app.use<[Partial<QuasarPluginOptions>, AppContext?]>(Quasar, {}, appContext)

return {
app,
Expand Down
6 changes: 3 additions & 3 deletions example/src/entryServer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import assert from 'assert'
import assert from 'node:assert'
import http from 'http'
import path from 'path'
import path from 'node:path'
import { renderToString } from '@vue/server-renderer'
import express from 'express'
import { VueSsrAssetRenderer } from 'vue-ssr-assets-plugin/dist/utils/VueSsrAssetsRenderer'
import { createVueApp } from './createVueApp'
import type { AppContext } from './AppContext'
import { AppContext } from './AppContext'

// -----------------------------------------------------------------------------
// Express
Expand Down
2 changes: 1 addition & 1 deletion example/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createMemoryHistory, createRouter, createWebHistory, type Router } from 'vue-router'
import type { AppContext } from './AppContext'
import { AppContext } from './AppContext'

// ----------------------------------------------------------------------------
// Router
Expand Down
Loading

0 comments on commit 6f7fff6

Please sign in to comment.