Skip to content

Commit

Permalink
chore: update eslint config and fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Apr 3, 2024
1 parent 0c0bfc8 commit d7c9b42
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 318 deletions.
9 changes: 3 additions & 6 deletions e2e/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { JSDOM } from 'jsdom'

import type { Page } from 'playwright'

export async function sleep(delay: number) {
export function sleep(delay: number) {
return new Promise(resolve => setTimeout(resolve, delay))
}

Expand Down Expand Up @@ -43,7 +43,7 @@ export async function assetLocaleHead(page: Page, headSelector: string) {
},
[headHandle, localeHeadValue]
)
headHandle?.dispose()
await headHandle?.dispose()
}

export function getDom(html: string) {
Expand All @@ -57,10 +57,7 @@ export function getDataFromDom(dom: Document, selector: string) {
)
}

export async function assertLocaleHeadWithDom(
dom: Document,
headSelector: string
) {
export function assertLocaleHeadWithDom(dom: Document, headSelector: string) {
const localeHead = getDataFromDom(dom, headSelector)
const headData = [...localeHead.link, ...localeHead.meta]
for (const head of headData) {
Expand Down
81 changes: 40 additions & 41 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import globals from 'globals'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'
import ts from 'typescript-eslint'
import eslintConfigPrettier from 'eslint-config-prettier'
import pritter from 'eslint-config-prettier'
import vue from 'eslint-plugin-vue'

const vue = extendVuePlugin('plugin:vue/vue3-recommended', ts.parser)

/** @type { import("eslint").Linter.FlatConfig[] } */
export default [
// ignore globally
{
Expand All @@ -24,11 +21,6 @@ export default [
]
},

js.configs.recommended,
...ts.configs.recommended,
eslintConfigPrettier,
...vue,

// globals
{
// files: ['**/*.js', '**/*.ts', '**/*.vue', '**/*.json'],
Expand All @@ -45,6 +37,44 @@ export default [
}
},

js.configs.recommended,

//...ts.configs.recommended,
...ts.configs.recommendedTypeChecked,
{
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts', '**/*.vue'],
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
parser: ts.parser,
extraFileExtensions: ['.vue']
}
},
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-implied-eval': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-base-to-string': 'off'
}
},
{
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
...ts.configs.disableTypeChecked
},

...vue.configs['flat/recommended'],

pritter,

// custom rules
{
rules: {
Expand All @@ -64,34 +94,3 @@ export default [
}
}
]

/**
* extend eslint-plugin-vue with @typescript-eslint/parser
* (NOTE: eslint-plugin-vue flat config WIP currently https://github.com/vuejs/eslint-plugin-vue/issues/1291)
*
* @param { 'plugin:vue/vue3-essential' | 'plugin:vue/vue3-strongly-recommended' | 'plugin:vue/vue3-recommended' } vueConfigPattern
* @param { import("typescript-eslint").Config.parser } tsParser
*
* @return { import("eslint").Linter.FlatConfig[] }
*/
function extendVuePlugin(vueConfigPattern, tsParser) {
const compat = new FlatCompat()
const vuePlugin = compat.extends(vueConfigPattern)
const vueLangOptions = vuePlugin[2]
vueLangOptions.files = [
'**/*.vue',
'**/*.ts',
'**/*.tsx',
'**/*.mts',
'**/*.cts'
]
vueLangOptions.languageOptions = {
// NOTE:
// https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
parserOptions: {
parser: tsParser
},
ecmaVersion: 'latest'
}
return vuePlugin
}
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"docs:dev": "vitepress dev docs",
"docs:serve": "vitepress serve docs",
"docs:setup": "pnpm build:typed && pnpm docs:apigen",
"eslint:inspector": "npx @eslint/config-inspector",
"example:ssr": "cd examples/ssr/vite && pnpm dev",
"fix": "run-p lint:fix format:fix",
"format:fix": "run-p \"format:prettier --write\" format:package",
Expand All @@ -69,7 +70,6 @@
"test:unit": "cross-env TZ=UTC vitest run -c ./vitest.unit.config.ts"
},
"devDependencies": {
"@eslint/eslintrc": "^3.0.0",
"@eslint/js": "^8.57.0",
"@intlify/core-base": "workspace:*",
"@intlify/message-compiler": "workspace:*",
Expand All @@ -81,11 +81,13 @@
"@rollup/plugin-terser": "^0.4.3",
"@secretlint/secretlint-rule-preset-recommend": "^3.1.0",
"@textlint-rule/textlint-rule-no-unmatched-pair": "^2.0.0",
"@types/brotli": "^1.3.4",
"@types/eslint": "^8.56.7",
"@types/js-yaml": "^4.0.5",
"@types/jsdom": "^21.1.1",
"@types/minimist": "^1.2.5",
"@types/node": "^20.11.21",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"@types/rc": "^1.2.4",
"@vitest/coverage-v8": "^1.3.0",
"api-docs-gen": "^0.4.0",
"benchmark": "^2.1.4",
Expand All @@ -95,7 +97,7 @@
"esbuild-register": "^3.5.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-vue": "^9.22.0",
"eslint-plugin-vue": "^9.24.0",
"execa": "^5.0.0",
"fixpack": "^4.0.0",
"globals": "^15.0.0",
Expand All @@ -114,7 +116,7 @@
"playwright": "^1.34.0",
"prettier": "^3.2.5",
"rc": "^1.2.8",
"rimraf": "^3.0.2",
"rimraf": "^5.0.5",
"rollup": "^3.29.2",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
Expand All @@ -141,7 +143,7 @@
"trash-cli": "^5.0.0",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"typescript-eslint": "^7.1.0",
"typescript-eslint": "^7.5.0",
"vitepress": "1.0.2",
"vitest": "^1.3.0",
"vue": "3.4.21",
Expand Down
7 changes: 2 additions & 5 deletions packages/format-explorer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async function compile(
lastSuccessCode =
evalCode.toString() + `\n\n// Check the console for the AST`
lastSuccessfulMap =
// eslint-disable-next-line @typescript-eslint/await-thenable
options.sourceMap && map ? await new SourceMapConsumer(map) : null
lastSuccessfulMap?.computeColumnSpans()
} catch (e: unknown) {
Expand Down Expand Up @@ -222,11 +223,7 @@ const onChangeOptions = async (options: CompileOptions) => {
@change-model="onChangeModel"
@ready="onReadyInput"
/>
<Editor
class="output"
:code="genCodes"
@ready="onReadyOutput"
/>
<Editor class="output" :code="genCodes" @ready="onReadyOutput" />
</div>
</div>
</template>
Expand Down
Loading

0 comments on commit d7c9b42

Please sign in to comment.