From 7bafa973340462a3b428aee439b7926815c7debe Mon Sep 17 00:00:00 2001 From: MathBunny Date: Thu, 6 Aug 2020 10:55:54 -0400 Subject: [PATCH 1/5] chore: Demonstrate adoption of no-unused-vars-experimental --- .eslintrc.js | 8 +++++++- src/database.d.ts | 2 -- src/instance-id.d.ts | 1 - src/machine-learning/machine-learning.ts | 3 +-- src/remote-config.d.ts | 1 - test/integration/database.spec.ts | 2 -- test/resources/mocks.ts | 2 +- tsconfig.eslint.json | 12 ++++++++++++ tsconfig.json | 1 + 9 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 tsconfig.eslint.json diff --git a/.eslintrc.js b/.eslintrc.js index 1fc00bbd78..546f1a818a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -29,6 +29,7 @@ module.exports = { // Following checks are temporarily disabled. We shall incrementally enable them in the // future, fixing any violations as we go. '@typescript-eslint/no-non-null-assertion': 0, + '@typescript-eslint/no-unused-vars': 0, // Disabled checks '@typescript-eslint/no-explicit-any': 0, @@ -46,5 +47,10 @@ module.exports = { 'allowHigherOrderFunctions': true } ], - } + '@typescript-eslint/no-unused-vars-experimental': 2, + }, + // See github.com/typescript-eslint/typescript-eslint/issues/1320 + parserOptions: { + project: './tsconfig.eslint.json', + }, }; diff --git a/src/database.d.ts b/src/database.d.ts index 3046e25f21..40ca71ea73 100644 --- a/src/database.d.ts +++ b/src/database.d.ts @@ -1631,11 +1631,9 @@ export namespace admin.database { */ interface ThenableReference extends admin.database.Reference, Promise { } - /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ function enableLogging(logger?: boolean | ((message: string) => any), persistent?: boolean): any; } -/* eslint-disable @typescript-eslint/no-unused-vars */ export namespace admin.database.ServerValue { /** diff --git a/src/instance-id.d.ts b/src/instance-id.d.ts index 616d0d193e..34269be5b0 100644 --- a/src/instance-id.d.ts +++ b/src/instance-id.d.ts @@ -1,6 +1,5 @@ import * as _admin from './index.d'; -/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ export namespace admin.instanceId { /** * Gets the {@link InstanceId `InstanceId`} service for the diff --git a/src/machine-learning/machine-learning.ts b/src/machine-learning/machine-learning.ts index 9d2330aa92..3b09d07c23 100644 --- a/src/machine-learning/machine-learning.ts +++ b/src/machine-learning/machine-learning.ts @@ -285,8 +285,7 @@ export class Model { return false; } - /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ - public waitForUnlocked(maxTimeSeconds?: number): Promise { + public waitForUnlocked(_maxTimeSeconds?: number): Promise { // Backend does not currently return locked models. // This will likely change in future. return Promise.resolve(); diff --git a/src/remote-config.d.ts b/src/remote-config.d.ts index c3897a2dd2..2da1d28336 100644 --- a/src/remote-config.d.ts +++ b/src/remote-config.d.ts @@ -1,6 +1,5 @@ import * as _admin from './index.d'; -/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ export namespace admin.remoteConfig { /** diff --git a/test/integration/database.spec.ts b/test/integration/database.spec.ts index e8d0a746a4..708c3a153a 100644 --- a/test/integration/database.spec.ts +++ b/test/integration/database.spec.ts @@ -173,8 +173,6 @@ describe('admin.database', () => { // Check for type compilation. This method is not invoked by any tests. But it // will trigger a TS compilation failure if the RTDB typings were not loaded // correctly. (Marked as export to avoid compilation warning.) -// -// eslint-disable-next-line @typescript-eslint/no-unused-vars export function addValueEventListener( db: admin.database.Database, callback: (s: admin.database.DataSnapshot | null) => any): void { diff --git a/test/resources/mocks.ts b/test/resources/mocks.ts index cb2be41a8f..28884b30d2 100644 --- a/test/resources/mocks.ts +++ b/test/resources/mocks.ts @@ -221,7 +221,7 @@ export function generateSessionCookie(overrides?: object, expiresIn?: number): s export function firebaseServiceFactory( firebaseApp: FirebaseApp, - extendApp?: (props: object) => void, // eslint-disable-line @typescript-eslint/no-unused-vars + _extendApp?: (props: object) => void, ): FirebaseServiceInterface { const result = { app: firebaseApp, diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000000..dd9ce177c0 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,12 @@ +// Used for @typescript-eslint/no-unused-vars-experimental to glob the entire +// source. An alternative is createDefaultProgram: true but it has exponential +// complexity. See: github.com/typescript-eslint/typescript-eslint/issues/967 +{ + "compilerOptions": { + "strict": true, + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts", + ], +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e13292b408..a4a18ba019 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,7 @@ // "declaration": true, "rootDir": "." }, + // "include": ["**/*.ts"], "files": [ "src/index.ts" ] From c722de4d31218bad8082fad0e221dba30506e931 Mon Sep 17 00:00:00 2001 From: MathBunny Date: Thu, 6 Aug 2020 11:01:07 -0400 Subject: [PATCH 2/5] Add newline at EOF, remove comment --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index a4a18ba019..e13292b408 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,6 @@ // "declaration": true, "rootDir": "." }, - // "include": ["**/*.ts"], "files": [ "src/index.ts" ] From ea761c02f47055d5cc7e40952f7d2ec4702b7356 Mon Sep 17 00:00:00 2001 From: MathBunny Date: Thu, 6 Aug 2020 11:01:42 -0400 Subject: [PATCH 3/5] Add newline at EOF --- tsconfig.eslint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index dd9ce177c0..fdb5ad2719 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -9,4 +9,4 @@ "src/**/*.ts", "test/**/*.ts", ], -} \ No newline at end of file +} From 4634f2b114b151ad6b8090c886b16f88b0fcd8e0 Mon Sep 17 00:00:00 2001 From: MathBunny Date: Thu, 6 Aug 2020 11:10:25 -0400 Subject: [PATCH 4/5] fix: no-unused-vars is disabled permanently, not temporarily --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 546f1a818a..cf3c29250f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -29,11 +29,11 @@ module.exports = { // Following checks are temporarily disabled. We shall incrementally enable them in the // future, fixing any violations as we go. '@typescript-eslint/no-non-null-assertion': 0, - '@typescript-eslint/no-unused-vars': 0, // Disabled checks '@typescript-eslint/no-explicit-any': 0, '@typescript-eslint/no-use-before-define': 0, + '@typescript-eslint/no-unused-vars': 0, // Required checks 'indent': ['error', 2], From fc1e0469a9381f791a44b077679c55d7bd799120 Mon Sep 17 00:00:00 2001 From: MathBunny Date: Thu, 6 Aug 2020 14:00:34 -0400 Subject: [PATCH 5/5] Address comment --- .eslintrc.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.eslintrc.js b/.eslintrc.js index cf3c29250f..37125d1535 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -49,6 +49,8 @@ module.exports = { ], '@typescript-eslint/no-unused-vars-experimental': 2, }, + // Required by the @typescript-eslint/no-unused-vars-experimental rule. + // We use a separate tsconfig file for linting to reduce the time complexity of the operation. // See github.com/typescript-eslint/typescript-eslint/issues/1320 parserOptions: { project: './tsconfig.eslint.json',