From e687d36d02bba1f618ba1dbfe4fa46a7b348788a Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 8 Aug 2017 16:17:03 -0400 Subject: [PATCH 1/6] New: Only warn about an unsupported TypeScript version once (fixes #348) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It gets annoying when you’re trying to lint a project with lots of files. --- parser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parser.js b/parser.js index 944606e..7d576d9 100644 --- a/parser.js +++ b/parser.js @@ -17,6 +17,7 @@ const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies(ACTIVE_TYPESCRIPT_VERSION, SUPPORTED_TYPESCRIPT_VERSIONS); let extra; +let warnedAboutTSVersion = false; /** * Resets the extra config object @@ -103,7 +104,7 @@ function parse(code, options) { } - if (!isRunningSupportedTypeScriptVersion) { + if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) { const border = "============="; const versionWarning = [ border, @@ -115,6 +116,7 @@ function parse(code, options) { border ]; extra.log(versionWarning.join("\n\n")); + warnedAboutTSVersion = true; } // Even if jsx option is set in typescript compiler, filename still has to From 547db22022b641c7f5f1fe3238148c525cf23bab Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 8 Aug 2017 16:27:57 -0400 Subject: [PATCH 2/6] Move the warning message outside of the parser function --- parser.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/parser.js b/parser.js index 7d576d9..42d2f4f 100644 --- a/parser.js +++ b/parser.js @@ -16,8 +16,21 @@ const SUPPORTED_TYPESCRIPT_VERSIONS = require("./package.json").devDependencies. const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies(ACTIVE_TYPESCRIPT_VERSION, SUPPORTED_TYPESCRIPT_VERSIONS); +if (!isRunningSupportedTypeScriptVersion) { + const border = "============="; + const versionWarning = [ + border, + "WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.", + "You may find that it works just fine, or you may not.", + `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`, + `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`, + "Please only submit bug reports when using the officially supported version.", + border + ]; + console.log(versionWarning.join("\n\n")); +} + let extra; -let warnedAboutTSVersion = false; /** * Resets the extra config object @@ -104,21 +117,6 @@ function parse(code, options) { } - if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) { - const border = "============="; - const versionWarning = [ - border, - "WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.", - "You may find that it works just fine, or you may not.", - `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`, - `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`, - "Please only submit bug reports when using the officially supported version.", - border - ]; - extra.log(versionWarning.join("\n\n")); - warnedAboutTSVersion = true; - } - // Even if jsx option is set in typescript compiler, filename still has to // contain .tsx file extension const FILENAME = (extra.ecmaFeatures.jsx) ? "eslint.tsx" : "eslint.ts"; From f11a370286825b1d1ef0a3b1b8c3a60051785711 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 8 Aug 2017 16:33:21 -0400 Subject: [PATCH 3/6] Silence lint warning --- parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser.js b/parser.js index 42d2f4f..b877414 100644 --- a/parser.js +++ b/parser.js @@ -27,7 +27,7 @@ if (!isRunningSupportedTypeScriptVersion) { "Please only submit bug reports when using the officially supported version.", border ]; - console.log(versionWarning.join("\n\n")); + console.log(versionWarning.join("\n\n")); // eslint-disable-line no-console } let extra; From 6505f65aec145ecc2e8a9cc7beaa79e2369acaf8 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 8 Aug 2017 16:39:25 -0400 Subject: [PATCH 4/6] Revert "Move the warning message outside of the parser function" This reverts commit 547db22022b641c7f5f1fe3238148c525cf23bab. --- parser.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/parser.js b/parser.js index b877414..7d576d9 100644 --- a/parser.js +++ b/parser.js @@ -16,21 +16,8 @@ const SUPPORTED_TYPESCRIPT_VERSIONS = require("./package.json").devDependencies. const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies(ACTIVE_TYPESCRIPT_VERSION, SUPPORTED_TYPESCRIPT_VERSIONS); -if (!isRunningSupportedTypeScriptVersion) { - const border = "============="; - const versionWarning = [ - border, - "WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.", - "You may find that it works just fine, or you may not.", - `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`, - `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`, - "Please only submit bug reports when using the officially supported version.", - border - ]; - console.log(versionWarning.join("\n\n")); // eslint-disable-line no-console -} - let extra; +let warnedAboutTSVersion = false; /** * Resets the extra config object @@ -117,6 +104,21 @@ function parse(code, options) { } + if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) { + const border = "============="; + const versionWarning = [ + border, + "WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.", + "You may find that it works just fine, or you may not.", + `SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`, + `YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`, + "Please only submit bug reports when using the officially supported version.", + border + ]; + extra.log(versionWarning.join("\n\n")); + warnedAboutTSVersion = true; + } + // Even if jsx option is set in typescript compiler, filename still has to // contain .tsx file extension const FILENAME = (extra.ecmaFeatures.jsx) ? "eslint.tsx" : "eslint.ts"; From 4feeb32a22e7126bf60662bf93b6ef9b14a45204 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Wed, 9 Aug 2017 06:47:42 -0400 Subject: [PATCH 5/6] Allow disabling logging with `loggerFn: false` --- parser.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parser.js b/parser.js index 7d576d9..6ab789d 100644 --- a/parser.js +++ b/parser.js @@ -100,6 +100,9 @@ function parse(code, options) { */ if (typeof options.loggerFn === "function") { extra.log = options.loggerFn; + } else if (options.loggerFn === false) { + /** */ // eslint-disable-line valid-jsdoc + extra.log = () => {}; } } From fa0f83e874c51ed0b8f7c4f5f916acdf13cce7e5 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Wed, 9 Aug 2017 07:56:38 -0400 Subject: [PATCH 6/6] Remove the ESLint incantation and use `Function.prototype` instead. --- parser.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parser.js b/parser.js index 6ab789d..250eebd 100644 --- a/parser.js +++ b/parser.js @@ -101,8 +101,7 @@ function parse(code, options) { if (typeof options.loggerFn === "function") { extra.log = options.loggerFn; } else if (options.loggerFn === false) { - /** */ // eslint-disable-line valid-jsdoc - extra.log = () => {}; + extra.log = Function.prototype; } }