Skip to content

Commit

Permalink
Add missing null nodeTypes
Browse files Browse the repository at this point in the history
`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`.
  • Loading branch information
btmills committed Apr 9, 2023
1 parent 83eb749 commit d2604b7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 23 deletions.
3 changes: 2 additions & 1 deletion lib/cli-engine/cli-engine.js
Expand Up @@ -313,7 +313,8 @@ function createIgnoreResult(filePath, baseDir) {
severity: 1,
message,
line: 0,
column: 0
column: 0,
nodeType: null
}
],
suppressedMessages: [],
Expand Down
3 changes: 2 additions & 1 deletion lib/eslint/eslint-helpers.js
Expand Up @@ -612,7 +612,8 @@ function createIgnoreResult(filePath, baseDir) {
severity: 1,
message,
line: 0,
column: 0
column: 0,
nodeType: null
}
],
suppressedMessages: [],
Expand Down
3 changes: 2 additions & 1 deletion lib/linter/config-comment-parser.js
Expand Up @@ -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
}
};

Expand Down
15 changes: 10 additions & 5 deletions lib/linter/linter.js
Expand Up @@ -851,7 +851,8 @@ function parse(text, languageOptions, filePath) {
severity: 2,
message,
line: ex.lineNumber,
column: ex.column
column: ex.column,
nodeType: null
}
};
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1492,7 +1494,8 @@ class Linter {
severity: 2,
message,
line: ex.lineNumber,
column: ex.column
column: ex.column,
nodeType: null
}
];
}
Expand Down Expand Up @@ -1757,7 +1760,8 @@ class Linter {
severity: 1,
message: `No matching configuration found for ${filename}.`,
line: 0,
column: 0
column: 0,
nodeType: null
}
];
}
Expand Down Expand Up @@ -1822,7 +1826,8 @@ class Linter {
severity: 2,
message,
line: ex.lineNumber,
column: ex.column
column: ex.column,
nodeType: null
}
];
}
Expand Down
9 changes: 6 additions & 3 deletions tests/lib/cli-engine/cli-engine.js
Expand Up @@ -577,7 +577,8 @@ describe("CLIEngine", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19
column: 19,
nodeType: null
}
],
suppressedMessages: [],
Expand Down Expand Up @@ -622,7 +623,8 @@ describe("CLIEngine", () => {
severity: 2,
message: "Parsing error: Unexpected token",
line: 1,
column: 10
column: 10,
nodeType: null
}
],
suppressedMessages: [],
Expand Down Expand Up @@ -713,7 +715,8 @@ describe("CLIEngine", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19
column: 19,
nodeType: null
}
],
suppressedMessages: [],
Expand Down
9 changes: 6 additions & 3 deletions tests/lib/eslint/eslint.js
Expand Up @@ -690,7 +690,8 @@ describe("ESLint", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19
column: 19,
nodeType: null
}
],
suppressedMessages: [],
Expand Down Expand Up @@ -730,7 +731,8 @@ describe("ESLint", () => {
severity: 2,
message: "Parsing error: Unexpected token",
line: 1,
column: 10
column: 10,
nodeType: null
}
],
suppressedMessages: [],
Expand Down Expand Up @@ -819,7 +821,8 @@ describe("ESLint", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19
column: 19,
nodeType: null
}
],
suppressedMessages: [],
Expand Down
12 changes: 8 additions & 4 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -475,7 +475,8 @@ describe("FlatESLint", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19
column: 19,
nodeType: null
}
],
suppressedMessages: [],
Expand Down Expand Up @@ -515,7 +516,8 @@ describe("FlatESLint", () => {
severity: 2,
message: "Parsing error: Unexpected token",
line: 1,
column: 10
column: 10,
nodeType: null
}
],
suppressedMessages: [],
Expand Down Expand Up @@ -605,7 +607,8 @@ describe("FlatESLint", () => {
severity: 2,
message: "Parsing error: Unexpected token is",
line: 1,
column: 19
column: 19,
nodeType: null
}
],
suppressedMessages: [],
Expand Down Expand Up @@ -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: [],
Expand Down
9 changes: 6 additions & 3 deletions tests/lib/linter/linter.js
Expand Up @@ -6866,7 +6866,8 @@ var a = "test2";
severity: 2,
message: "Preprocessing error: Invalid syntax",
line: 1,
column: 1
column: 1,
nodeType: null
}
]);
});
Expand Down Expand Up @@ -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
});
});

Expand Down Expand Up @@ -15556,7 +15558,8 @@ var a = "test2";
severity: 2,
message: "Preprocessing error: Invalid syntax",
line: 1,
column: 1
column: 1,
nodeType: null
}
]);
});
Expand Down
6 changes: 4 additions & 2 deletions tests/tools/eslint-fuzzer.js
Expand Up @@ -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
});
});
});
Expand Down Expand Up @@ -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
});
});
});
Expand Down

0 comments on commit d2604b7

Please sign in to comment.