From 042360894a7d4d749684bb44e88ce4a06a9aa8a1 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sun, 25 Apr 2021 13:34:25 +0200 Subject: [PATCH] chore: use recommended lint (#3072) --- .eslintrc.js | 36 ++++++++++++++----- package.json | 1 + packages/plugin-vue/src/main.ts | 1 + packages/plugin-vue/src/style.ts | 1 + packages/plugin-vue/src/template.ts | 3 ++ packages/vite/src/client/client.ts | 4 ++- .../src/node/server/middlewares/indexHtml.ts | 3 ++ yarn.lock | 33 ++++++++++++++++- 8 files changed, 72 insertions(+), 10 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f19c57faa15bbc..85fa023b15354c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,11 @@ const { defineConfig } = require('eslint-define-config') module.exports = defineConfig({ root: true, - extends: ['plugin:node/recommended'], + extends: [ + 'eslint:recommended', + 'plugin:node/recommended', + 'plugin:@typescript-eslint/recommended' + ], parser: '@typescript-eslint/parser', parserOptions: { sourceType: 'module', @@ -11,6 +15,16 @@ module.exports = defineConfig({ }, rules: { 'no-debugger': ['error'], + 'no-empty': ['warn', { allowEmptyCatch: true }], + 'no-process-exit': 'off', + 'no-useless-escape': 'off', + 'prefer-const': [ + 'warn', + { + destructuring: 'all' + } + ], + 'node/no-missing-import': [ 'error', { @@ -54,13 +68,19 @@ module.exports = defineConfig({ 'node/no-unpublished-import': 'off', 'node/no-unpublished-require': 'off', 'node/no-unsupported-features/es-syntax': 'off', - 'no-process-exit': 'off', - 'prefer-const': [ - 'warn', - { - destructuring: 'all' - } - ] + + '@typescript-eslint/ban-ts-comment': 'off', // TODO: we should turn this on in a new PR + '@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR + '@typescript-eslint/no-empty-function': [ + 'error', + { allow: ['arrowFunctions'] } + ], + '@typescript-eslint/no-explicit-any': 'off', // maybe we should turn this on in a new PR + '@typescript-eslint/no-extra-semi': 'off', // conflicts with prettier + '@typescript-eslint/no-inferrable-types': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', // maybe we should turn this on in a new PR + '@typescript-eslint/no-unused-vars': 'off', // maybe we should turn this on in a new PR + '@typescript-eslint/no-var-requires': 'off' }, overrides: [ { diff --git a/package.json b/package.json index 109a4997a91295..662d263c28188c 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@types/jest": "^26.0.19", "@types/node": "^14.14.10", "@types/semver": "^7.3.4", + "@typescript-eslint/eslint-plugin": "^4.22.0", "@typescript-eslint/parser": "^4.22.0", "chalk": "^4.1.0", "conventional-changelog-cli": "^2.1.1", diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index cec1ac67f54f6e..d9c9b2ff9b3f71 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -14,6 +14,7 @@ import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate' import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map' import { createRollupError } from './utils/error' +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function transformMain( code: string, filename: string, diff --git a/packages/plugin-vue/src/style.ts b/packages/plugin-vue/src/style.ts index c14866600953aa..961c9b3878c866 100644 --- a/packages/plugin-vue/src/style.ts +++ b/packages/plugin-vue/src/style.ts @@ -2,6 +2,7 @@ import { compileStyleAsync, SFCDescriptor } from '@vue/compiler-sfc' import { TransformPluginContext } from 'rollup' import { ResolvedOptions } from '.' +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function transformStyle( code: string, descriptor: SFCDescriptor, diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index e84010d4126edd..3e9f2afcf48517 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -10,6 +10,7 @@ import { ResolvedOptions } from '.' import { getResolvedScript } from './script' import { createRollupError } from './utils/error' +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function transformTemplateAsModule( code: string, descriptor: SFCDescriptor, @@ -40,6 +41,7 @@ export function transformTemplateAsModule( /** * transform the template directly in the main SFC module */ +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function transformTemplateInMain( code: string, descriptor: SFCDescriptor, @@ -57,6 +59,7 @@ export function transformTemplateInMain( } } +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function compile( code: string, descriptor: SFCDescriptor, diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index 6a089e10f45d5a..80c4d920dde968 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -172,6 +172,7 @@ async function queueUpdate(p: Promise<(() => void) | undefined>) { } async function waitForSuccessfulPing(ms = 1000) { + // eslint-disable-next-line no-constant-condition while (true) { try { await fetch(`${base}__vite_ping`) @@ -335,7 +336,7 @@ const ctxToListenersMap = new Map< >() // Just infer the return type for now -// _This would have to be activated when used `plugin:@typescript-eslint/recommended`_ eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const createHotContext = (ownerPath: string) => { if (!dataMap.has(ownerPath)) { dataMap.set(ownerPath, {}) @@ -412,6 +413,7 @@ export const createHotContext = (ownerPath: string) => { }, // TODO + // eslint-disable-next-line @typescript-eslint/no-empty-function decline() {}, invalidate() { diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 36a29769aeb37a..200a951bcabe80 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -45,6 +45,9 @@ const devHtmlHook: IndexHtmlTransformHook = async ( html, { path: htmlPath, server } ) => { + // TODO: solve this design issue + // Optional chain expressions can return undefined by design + // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain const config = server?.config! const base = config.base || '/' diff --git a/yarn.lock b/yarn.lock index a10bcfb3d4d945..5b58daa8cff9f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1032,6 +1032,11 @@ jest-diff "^26.0.0" pretty-format "^26.0.0" +"@types/json-schema@^7.0.3": + version "7.0.7" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" + integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA== + "@types/less@^3.0.2": version "3.0.2" resolved "https://registry.yarnpkg.com/@types/less/-/less-3.0.2.tgz#2761d477678c8374cb9897666871662eb1d1115e" @@ -1134,6 +1139,32 @@ dependencies: "@types/node" "*" +"@typescript-eslint/eslint-plugin@^4.22.0": + version "4.22.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.22.0.tgz#3d5f29bb59e61a9dba1513d491b059e536e16dbc" + integrity sha512-U8SP9VOs275iDXaL08Ln1Fa/wLXfj5aTr/1c0t0j6CdbOnxh+TruXu1p4I0NAvdPBQgoPjHsgKn28mOi0FzfoA== + dependencies: + "@typescript-eslint/experimental-utils" "4.22.0" + "@typescript-eslint/scope-manager" "4.22.0" + debug "^4.1.1" + functional-red-black-tree "^1.0.1" + lodash "^4.17.15" + regexpp "^3.0.0" + semver "^7.3.2" + tsutils "^3.17.1" + +"@typescript-eslint/experimental-utils@4.22.0": + version "4.22.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.22.0.tgz#68765167cca531178e7b650a53456e6e0bef3b1f" + integrity sha512-xJXHHl6TuAxB5AWiVrGhvbGL8/hbiCQ8FiWwObO3r0fnvBdrbWEDy1hlvGQOAWc6qsCWuWMKdVWlLAEMpxnddg== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/scope-manager" "4.22.0" + "@typescript-eslint/types" "4.22.0" + "@typescript-eslint/typescript-estree" "4.22.0" + eslint-scope "^5.0.0" + eslint-utils "^2.0.0" + "@typescript-eslint/parser@^4.22.0": version "4.22.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.22.0.tgz#e1637327fcf796c641fe55f73530e90b16ac8fe8" @@ -2935,7 +2966,7 @@ eslint-plugin-node@^11.1.0: resolve "^1.10.1" semver "^6.1.0" -eslint-scope@^5.1.1: +eslint-scope@^5.0.0, eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==