From d2604b78922ee1b28e325ee0bf1d866c3b950d90 Mon Sep 17 00:00:00 2001 From: Brandon Mills Date: Sat, 8 Apr 2023 20:05:14 -0400 Subject: [PATCH] Add missing null nodeTypes `LintMessage.nodeType` is currently defined as required but nullable. Actual implementations explicitly set it to `null` in a couple places and omit it in several. After discussion in #16968, we initially leaned toward making it non-nullable but optional. I pursued that, but it resulted in slightly more runtime code changes, including some branching in `report-translator` to set it conditionally. Instead, I'm presenting the opposite solution of updating the remaining implementations to match the existing type definition by explicitly setting `nodeType` to `null`. --- lib/cli-engine/cli-engine.js | 3 ++- lib/eslint/eslint-helpers.js | 3 ++- lib/linter/config-comment-parser.js | 3 ++- lib/linter/linter.js | 15 ++++++++++----- tests/lib/cli-engine/cli-engine.js | 9 ++++++--- tests/lib/eslint/eslint.js | 9 ++++++--- tests/lib/eslint/flat-eslint.js | 12 ++++++++---- tests/lib/linter/linter.js | 9 ++++++--- tests/tools/eslint-fuzzer.js | 6 ++++-- 9 files changed, 46 insertions(+), 23 deletions(-) diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index be98762118cf..b52429f9e7f5 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -313,7 +313,8 @@ function createIgnoreResult(filePath, baseDir) { severity: 1, message, line: 0, - column: 0 + column: 0, + nodeType: null } ], suppressedMessages: [], diff --git a/lib/eslint/eslint-helpers.js b/lib/eslint/eslint-helpers.js index 8caa54851936..88c0fcafe18f 100644 --- a/lib/eslint/eslint-helpers.js +++ b/lib/eslint/eslint-helpers.js @@ -612,7 +612,8 @@ function createIgnoreResult(filePath, baseDir) { severity: 1, message, line: 0, - column: 0 + column: 0, + nodeType: null } ], suppressedMessages: [], diff --git a/lib/linter/config-comment-parser.js b/lib/linter/config-comment-parser.js index 3f703db4d91e..9aab3c444585 100644 --- a/lib/linter/config-comment-parser.js +++ b/lib/linter/config-comment-parser.js @@ -115,7 +115,8 @@ module.exports = class ConfigCommentParser { severity: 2, message: `Failed to parse JSON from '${normalizedString}': ${ex.message}`, line: location.start.line, - column: location.start.column + 1 + column: location.start.column + 1, + nodeType: null } }; diff --git a/lib/linter/linter.js b/lib/linter/linter.js index 9d52bb9cd536..71dea0d48cc1 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -851,7 +851,8 @@ function parse(text, languageOptions, filePath) { severity: 2, message, line: ex.lineNumber, - column: ex.column + column: ex.column, + nodeType: null } }; } @@ -1281,7 +1282,8 @@ class Linter { severity: 2, message: `Configured parser '${config.parser}' was not found.`, line: 0, - column: 0 + column: 0, + nodeType: null }]; } parserName = config.parser; @@ -1492,7 +1494,8 @@ class Linter { severity: 2, message, line: ex.lineNumber, - column: ex.column + column: ex.column, + nodeType: null } ]; } @@ -1757,7 +1760,8 @@ class Linter { severity: 1, message: `No matching configuration found for ${filename}.`, line: 0, - column: 0 + column: 0, + nodeType: null } ]; } @@ -1822,7 +1826,8 @@ class Linter { severity: 2, message, line: ex.lineNumber, - column: ex.column + column: ex.column, + nodeType: null } ]; } diff --git a/tests/lib/cli-engine/cli-engine.js b/tests/lib/cli-engine/cli-engine.js index 03dff9bb3d76..2528a398ea1e 100644 --- a/tests/lib/cli-engine/cli-engine.js +++ b/tests/lib/cli-engine/cli-engine.js @@ -577,7 +577,8 @@ describe("CLIEngine", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], @@ -622,7 +623,8 @@ describe("CLIEngine", () => { severity: 2, message: "Parsing error: Unexpected token", line: 1, - column: 10 + column: 10, + nodeType: null } ], suppressedMessages: [], @@ -713,7 +715,8 @@ describe("CLIEngine", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], diff --git a/tests/lib/eslint/eslint.js b/tests/lib/eslint/eslint.js index aa30047edc28..c05a869641d1 100644 --- a/tests/lib/eslint/eslint.js +++ b/tests/lib/eslint/eslint.js @@ -690,7 +690,8 @@ describe("ESLint", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], @@ -730,7 +731,8 @@ describe("ESLint", () => { severity: 2, message: "Parsing error: Unexpected token", line: 1, - column: 10 + column: 10, + nodeType: null } ], suppressedMessages: [], @@ -819,7 +821,8 @@ describe("ESLint", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], diff --git a/tests/lib/eslint/flat-eslint.js b/tests/lib/eslint/flat-eslint.js index 9c8eeedb5877..def57a11814e 100644 --- a/tests/lib/eslint/flat-eslint.js +++ b/tests/lib/eslint/flat-eslint.js @@ -475,7 +475,8 @@ describe("FlatESLint", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], @@ -515,7 +516,8 @@ describe("FlatESLint", () => { severity: 2, message: "Parsing error: Unexpected token", line: 1, - column: 10 + column: 10, + nodeType: null } ], suppressedMessages: [], @@ -605,7 +607,8 @@ describe("FlatESLint", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], @@ -5017,7 +5020,8 @@ describe("FlatESLint", () => { message: "File ignored by default. Use \"--ignore-pattern '!node_modules/*'\" to override.", severity: 1, line: 0, - column: 0 + column: 0, + nodeType: null } ], usedDeprecatedRules: [], diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index 0ece277dc9a9..dd23f941cc04 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -6866,7 +6866,8 @@ var a = "test2"; severity: 2, message: "Preprocessing error: Invalid syntax", line: 1, - column: 1 + column: 1, + nodeType: null } ]); }); @@ -8848,7 +8849,8 @@ describe("Linter with FlatConfigArray", () => { severity: 1, message: "No matching configuration found for filename.ts.", line: 0, - column: 0 + column: 0, + nodeType: null }); }); @@ -15556,7 +15558,8 @@ var a = "test2"; severity: 2, message: "Preprocessing error: Invalid syntax", line: 1, - column: 1 + column: 1, + nodeType: null } ]); }); diff --git a/tests/tools/eslint-fuzzer.js b/tests/tools/eslint-fuzzer.js index da267de24c1d..b606f3b68655 100644 --- a/tests/tools/eslint-fuzzer.js +++ b/tests/tools/eslint-fuzzer.js @@ -183,7 +183,8 @@ describe("eslint-fuzzer", function() { severity: 2, message: `Parsing error: ${expectedSyntaxError.message}`, line: expectedSyntaxError.lineNumber, - column: expectedSyntaxError.column + column: expectedSyntaxError.column, + nodeType: null }); }); }); @@ -232,7 +233,8 @@ describe("eslint-fuzzer", function() { severity: 2, message: `Parsing error: ${expectedSyntaxError.message}`, line: expectedSyntaxError.lineNumber, - column: expectedSyntaxError.column + column: expectedSyntaxError.column, + nodeType: null }); }); });