From cff123cc9df227c631cafee4a29f7a4efa46fa70 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Wed, 13 Jan 2021 12:22:49 +0100 Subject: [PATCH] chore(types): lint types (#8630) --- .eslintrc.js | 16 ++++++ package.json | 5 +- packages/config/index.d.ts | 2 +- packages/types/app/index.d.ts | 23 ++++---- packages/types/app/vue.d.ts | 4 +- packages/types/app/vuex.d.ts | 2 +- packages/types/config/build.d.ts | 1 + packages/types/config/generate.d.ts | 1 + packages/types/config/index.d.ts | 2 +- packages/types/config/render.d.ts | 2 +- packages/types/test/vue.ts | 2 + packages/vue-app/index.d.ts | 2 +- yarn.lock | 82 ++++++++++++++++++++++++++++- 13 files changed, 126 insertions(+), 18 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 142e9c0d46..a33862ef37 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -72,5 +72,21 @@ module.exports = { rules: { 'standard/no-callback-literal': 'off' } + }, { + files: ['**/*.ts'], + env: { browser: true, es6: true, node: true }, + extends: [ + '@nuxtjs/eslint-config-typescript' + ], + globals: { Atomics: 'readonly', SharedArrayBuffer: 'readonly' }, + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaFeatures: { jsx: true }, + ecmaVersion: 2018, + sourceType: 'module' + }, + rules: { + '@typescript-eslint/no-explicit-any': 0 + } }] } diff --git a/package.json b/package.json index dd531102f7..92c9942f06 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "clean:test": "rimraf test/fixtures/*/dist test/fixtures/*/.nuxt*/", "dev": "jiti ./scripts/dev.js", "postinstall": "lerna link && yarn dev", - "lint": "eslint --ext .js,.mjs,.vue .", + "lint": "eslint --ext .js,.mjs,.vue,.ts .", "lint:app": "eslint-multiplexer eslint --ignore-path packages/vue-app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b", "ls-lint": "npx @ls-lint/ls-lint", "nuxt": "jiti ./packages/cli/bin/nuxt-cli.js", @@ -37,11 +37,14 @@ "@babel/preset-env": "^7.12.11", "@ls-lint/ls-lint": "^1.9.2", "@nuxtjs/eslint-config": "^5.0.0", + "@nuxtjs/eslint-config-typescript": "^5.0.0", "@rollup/plugin-alias": "^3.1.1", "@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.0.1", "@rollup/plugin-replace": "^2.3.4", + "@typescript-eslint/eslint-plugin": "^4.13.0", + "@typescript-eslint/parser": "^4.13.0", "@vue/server-test-utils": "^1.1.2", "@vue/test-utils": "^1.1.2", "babel-eslint": "^10.1.0", diff --git a/packages/config/index.d.ts b/packages/config/index.d.ts index c8a4f6a3cb..1d3b964d3c 100644 --- a/packages/config/index.d.ts +++ b/packages/config/index.d.ts @@ -1,3 +1,3 @@ // Dummy type definition file to provide backward compatibility // around Nuxt modules extending `@nuxt/config` for Nuxt < 2.9 -declare module "@nuxt/config" +declare module '@nuxt/config' diff --git a/packages/types/app/index.d.ts b/packages/types/app/index.d.ts index 2484383a08..e645df137c 100644 --- a/packages/types/app/index.d.ts +++ b/packages/types/app/index.d.ts @@ -15,6 +15,16 @@ import './vuex' type NuxtState = Record +export interface NuxtAppOptions extends ComponentOptions { + [key: string]: any // TBD +} + +export interface NuxtError { + message?: string + path?: string + statusCode?: number +} + export interface Context { $config: NuxtRuntimeConfig @@ -79,6 +89,7 @@ export interface Context { beforeNuxtRender(fn: (params: { Components: VueRouter['getMatchedComponents'], nuxtState: NuxtState }) => void): void } +// eslint-disable-next-line @typescript-eslint/ban-types export type Middleware = string | ((ctx: Context, cb: Function) => Promise | void) export type Inject = (key: string, value: any) => void export type Plugin = (ctx: Context, inject: Inject) => Promise | void @@ -96,21 +107,17 @@ export interface Transition { leaveToClass?: string leaveActiveClass?: string beforeEnter?(el: HTMLElement): void + // eslint-disable-next-line @typescript-eslint/ban-types enter?(el: HTMLElement, done: Function): void afterEnter?(el: HTMLElement): void enterCancelled?(el: HTMLElement): void beforeLeave?(el: HTMLElement): void + // eslint-disable-next-line @typescript-eslint/ban-types leave?(el: HTMLElement, done: Function): void afterLeave?(el: HTMLElement): void leaveCancelled?(el: HTMLElement): void } -export interface NuxtError { - message?: string - path?: string - statusCode?: number -} - export interface DefaultNuxtLoading extends Vue { canSucceed: boolean clear(): void @@ -146,10 +153,6 @@ export interface CustomNuxtLoading extends Vue { export type NuxtLoading = DefaultNuxtLoading | CustomNuxtLoading -export interface NuxtAppOptions extends ComponentOptions { - [key: string]: any // TBD -} - export interface NuxtApp extends Vue { $options: NuxtAppOptions $loading: NuxtLoading diff --git a/packages/types/app/vue.d.ts b/packages/types/app/vue.d.ts index 41b4497df4..116059648e 100644 --- a/packages/types/app/vue.d.ts +++ b/packages/types/app/vue.d.ts @@ -5,11 +5,13 @@ import Vue from 'vue' import { MetaInfo } from 'vue-meta' import { Route } from 'vue-router' -import { Context, Middleware, Transition, NuxtApp } from './index' import { NuxtRuntimeConfig } from '../config/runtime' +import { Context, Middleware, Transition, NuxtApp } from './index' declare module 'vue/types/options' { + // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars interface ComponentOptions { + // eslint-disable-next-line @typescript-eslint/ban-types asyncData?(ctx: Context): Promise | object | void fetch?(ctx: Context): Promise | void fetchKey?: string | ((getKey: (id: string) => number) => string) diff --git a/packages/types/app/vuex.d.ts b/packages/types/app/vuex.d.ts index 8493a38515..bc3da16f03 100644 --- a/packages/types/app/vuex.d.ts +++ b/packages/types/app/vuex.d.ts @@ -1,8 +1,8 @@ -import Store from 'vuex' import VueRouter from 'vue-router' import { NuxtAppOptions } from '.' declare module 'vuex/types/index' { + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars interface Store { app: NuxtAppOptions $router: VueRouter diff --git a/packages/types/config/build.d.ts b/packages/types/config/build.d.ts index 497d189e51..1fdb10fe62 100644 --- a/packages/types/config/build.d.ts +++ b/packages/types/config/build.d.ts @@ -90,6 +90,7 @@ interface NuxtBabelOptions extends Pick PluginItem[] | void) | PluginItem[] | null plugins?: ((env: NuxtBabelPresetEnv & NuxtWebpackEnv) => NonNullable) | TransformOptions['plugins'] } diff --git a/packages/types/config/generate.d.ts b/packages/types/config/generate.d.ts index 35818e4814..72153abba2 100644 --- a/packages/types/config/generate.d.ts +++ b/packages/types/config/generate.d.ts @@ -21,6 +21,7 @@ export interface NuxtOptionsGenerate { routes?: NuxtOptionsGenerateRoute[] | NuxtOptionsGenerateRoutesFunction | NuxtOptionsGenerateRoutesFunctionWithCallback subFolders?: boolean cache?: false | { + // eslint-disable-next-line @typescript-eslint/ban-types ignore?: string[] | Function, globbyOptions?: GlobbyOptions } diff --git a/packages/types/config/index.d.ts b/packages/types/config/index.d.ts index 3221a9f4fb..972700ec3d 100644 --- a/packages/types/config/index.d.ts +++ b/packages/types/config/index.d.ts @@ -73,4 +73,4 @@ export interface NuxtOptions extends Configuration { watchers: NuxtOptionsWatchers } -export interface NuxtConfig extends Partial {} +export type NuxtConfig = Partial diff --git a/packages/types/config/render.d.ts b/packages/types/config/render.d.ts index ac60d62bc4..0719a4b156 100644 --- a/packages/types/config/render.d.ts +++ b/packages/types/config/render.d.ts @@ -50,7 +50,7 @@ export interface NuxtOptionsRender { bundleRenderer?: BundleRendererOptions compressor?: CompressionOptions | NuxtOptionsServerMiddleware | false csp?: boolean | CspOptions - crossorigin?: "anonymous" | "use-credentials" | "" + crossorigin?: 'anonymous' | 'use-credentials' | '' dist?: ServeStaticOptions etag?: NuxtEtagOptions | false fallback?: { diff --git a/packages/types/test/vue.ts b/packages/types/test/vue.ts index cdc18c3840..ad1c3e7b19 100644 --- a/packages/types/test/vue.ts +++ b/packages/types/test/vue.ts @@ -61,7 +61,9 @@ options.loading = true const middlewares: Middleware[] = [ 'foo', + // eslint-disable-next-line @typescript-eslint/no-empty-function () => {}, + // eslint-disable-next-line @typescript-eslint/no-empty-function async () => {} ] diff --git a/packages/vue-app/index.d.ts b/packages/vue-app/index.d.ts index 11c189a84a..0c8f653073 100644 --- a/packages/vue-app/index.d.ts +++ b/packages/vue-app/index.d.ts @@ -1,3 +1,3 @@ // Dummy type definition file to provide backward compatibility // around Nuxt modules extending `@nuxt/vue-app` for Nuxt < 2.9 -declare module "@nuxt/vue-app" +declare module '@nuxt/vue-app' diff --git a/yarn.lock b/yarn.lock index 9f66068f14..b59b17a753 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1960,7 +1960,16 @@ rc9 "^1.2.0" std-env "^2.2.1" -"@nuxtjs/eslint-config@^5.0.0": +"@nuxtjs/eslint-config-typescript@^5.0.0": + version "5.0.0" + resolved "https://registry.npmjs.org/@nuxtjs/eslint-config-typescript/-/eslint-config-typescript-5.0.0.tgz#060c1402e559b1df78c8c19b2f5a873eac53cab2" + integrity sha512-jw6h/WsdPc5i5l+a3DmEdpoAbFE4Tt7X6DBdXY7gfAsZ6bfzjoMzoHYaAmUk2tWkRDZmYvP6YANkbvi3X3pPAg== + dependencies: + "@nuxtjs/eslint-config" "5.0.0" + "@typescript-eslint/eslint-plugin" "^4.7.0" + "@typescript-eslint/parser" "^4.7.0" + +"@nuxtjs/eslint-config@5.0.0", "@nuxtjs/eslint-config@^5.0.0": version "5.0.0" resolved "https://registry.npmjs.org/@nuxtjs/eslint-config/-/eslint-config-5.0.0.tgz#d66143ee4ada9d944de0bfbe2d7e4693a2e20d60" integrity sha512-xoi0CPpFj4hOTz5xMiqGK314276gOmI+8W+3tgybqsKiKQBFXe1IOUjHzsuGqkS44iGy+GmmrwA387ojvKnhkQ== @@ -2605,6 +2614,32 @@ dependencies: "@types/node" "*" +"@typescript-eslint/eslint-plugin@^4.13.0", "@typescript-eslint/eslint-plugin@^4.7.0": + version "4.13.0" + resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.13.0.tgz#5f580ea520fa46442deb82c038460c3dd3524bb6" + integrity sha512-ygqDUm+BUPvrr0jrXqoteMqmIaZ/bixYOc3A4BRwzEPTZPi6E+n44rzNZWaB0YvtukgP+aoj0i/fyx7FkM2p1w== + dependencies: + "@typescript-eslint/experimental-utils" "4.13.0" + "@typescript-eslint/scope-manager" "4.13.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.13.0": + version "4.13.0" + resolved "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.13.0.tgz#9dc9ab375d65603b43d938a0786190a0c72be44e" + integrity sha512-/ZsuWmqagOzNkx30VWYV3MNB/Re/CGv/7EzlqZo5RegBN8tMuPaBgNK6vPBCQA8tcYrbsrTdbx3ixMRRKEEGVw== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/scope-manager" "4.13.0" + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/typescript-estree" "4.13.0" + eslint-scope "^5.0.0" + eslint-utils "^2.0.0" + "@typescript-eslint/experimental-utils@^4.0.1": version "4.12.0" resolved "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.12.0.tgz#372838e76db76c9a56959217b768a19f7129546b" @@ -2617,6 +2652,16 @@ eslint-scope "^5.0.0" eslint-utils "^2.0.0" +"@typescript-eslint/parser@^4.13.0", "@typescript-eslint/parser@^4.7.0": + version "4.13.0" + resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.13.0.tgz#c413d640ea66120cfcc37f891e8cb3fd1c9d247d" + integrity sha512-KO0J5SRF08pMXzq9+abyHnaGQgUJZ3Z3ax+pmqz9vl81JxmTTOUfQmq7/4awVfq09b6C4owNlOgOwp61pYRBSg== + dependencies: + "@typescript-eslint/scope-manager" "4.13.0" + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/typescript-estree" "4.13.0" + debug "^4.1.1" + "@typescript-eslint/scope-manager@4.12.0": version "4.12.0" resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.12.0.tgz#beeb8beca895a07b10c593185a5612f1085ef279" @@ -2625,11 +2670,24 @@ "@typescript-eslint/types" "4.12.0" "@typescript-eslint/visitor-keys" "4.12.0" +"@typescript-eslint/scope-manager@4.13.0": + version "4.13.0" + resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.13.0.tgz#5b45912a9aa26b29603d8fa28f5e09088b947141" + integrity sha512-UpK7YLG2JlTp/9G4CHe7GxOwd93RBf3aHO5L+pfjIrhtBvZjHKbMhBXTIQNkbz7HZ9XOe++yKrXutYm5KmjWgQ== + dependencies: + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/visitor-keys" "4.13.0" + "@typescript-eslint/types@4.12.0": version "4.12.0" resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.12.0.tgz#fb891fe7ccc9ea8b2bbd2780e36da45d0dc055e5" integrity sha512-N2RhGeheVLGtyy+CxRmxdsniB7sMSCfsnbh8K/+RUIXYYq3Ub5+sukRCjVE80QerrUBvuEvs4fDhz5AW/pcL6g== +"@typescript-eslint/types@4.13.0": + version "4.13.0" + resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.13.0.tgz#6a7c6015a59a08fbd70daa8c83dfff86250502f8" + integrity sha512-/+aPaq163oX+ObOG00M0t9tKkOgdv9lq0IQv/y4SqGkAXmhFmCfgsELV7kOCTb2vVU5VOmVwXBXJTDr353C1rQ== + "@typescript-eslint/typescript-estree@4.12.0": version "4.12.0" resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.12.0.tgz#3963418c850f564bdab3882ae23795d115d6d32e" @@ -2644,6 +2702,20 @@ semver "^7.3.2" tsutils "^3.17.1" +"@typescript-eslint/typescript-estree@4.13.0": + version "4.13.0" + resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.13.0.tgz#cf6e2207c7d760f5dfd8d18051428fadfc37b45e" + integrity sha512-9A0/DFZZLlGXn5XA349dWQFwPZxcyYyCFX5X88nWs2uachRDwGeyPz46oTsm9ZJE66EALvEns1lvBwa4d9QxMg== + dependencies: + "@typescript-eslint/types" "4.13.0" + "@typescript-eslint/visitor-keys" "4.13.0" + debug "^4.1.1" + globby "^11.0.1" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^7.3.2" + tsutils "^3.17.1" + "@typescript-eslint/visitor-keys@4.12.0": version "4.12.0" resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.12.0.tgz#a470a79be6958075fa91c725371a83baf428a67a" @@ -2652,6 +2724,14 @@ "@typescript-eslint/types" "4.12.0" eslint-visitor-keys "^2.0.0" +"@typescript-eslint/visitor-keys@4.13.0": + version "4.13.0" + resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.13.0.tgz#9acb1772d3b3183182b6540d3734143dce9476fe" + integrity sha512-6RoxWK05PAibukE7jElqAtNMq+RWZyqJ6Q/GdIxaiUj2Ept8jh8+FUVlbq9WxMYxkmEOPvCE5cRSyupMpwW31g== + dependencies: + "@typescript-eslint/types" "4.13.0" + eslint-visitor-keys "^2.0.0" + "@vue/babel-helper-vue-jsx-merge-props@^1.2.1": version "1.2.1" resolved "https://registry.npmjs.org/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.2.1.tgz#31624a7a505fb14da1d58023725a4c5f270e6a81"