diff --git a/docs/src/extend/custom-processors.md b/docs/src/extend/custom-processors.md index 8f330883b03..d112d724688 100644 --- a/docs/src/extend/custom-processors.md +++ b/docs/src/extend/custom-processors.md @@ -59,19 +59,19 @@ Reported problems have the following location information in each lint message: type LintMessage = { /// The 1-based line number where the message occurs. - line: number; + line?: number; /// The 1-based column number where the message occurs. - column: number; + column?: number; /// The 1-based line number of the end location. - endLine: number; + endLine?: number; /// The 1-based column number of the end location. - endColumn: number; + endColumn?: number; /// If `true`, this is a fatal error. - fatal: boolean; + fatal?: boolean; /// Information for an autofix. fix: Fix; diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index 5bca1618b94..093a20b1ded 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -308,9 +308,11 @@ function createIgnoreResult(filePath, baseDir) { filePath: path.resolve(filePath), messages: [ { + ruleId: null, fatal: false, severity: 1, - message + message, + nodeType: null } ], suppressedMessages: [], diff --git a/lib/eslint/eslint-helpers.js b/lib/eslint/eslint-helpers.js index 29a9b4a9b8a..8fa0caececa 100644 --- a/lib/eslint/eslint-helpers.js +++ b/lib/eslint/eslint-helpers.js @@ -607,9 +607,11 @@ function createIgnoreResult(filePath, baseDir) { filePath: path.resolve(filePath), messages: [ { + ruleId: null, fatal: false, severity: 1, - message + message, + nodeType: null } ], suppressedMessages: [], diff --git a/lib/eslint/flat-eslint.js b/lib/eslint/flat-eslint.js index 7f16a46be19..f615ae17155 100644 --- a/lib/eslint/flat-eslint.js +++ b/lib/eslint/flat-eslint.js @@ -55,6 +55,7 @@ const LintResultCache = require("../cli-engine/lint-result-cache"); /** @typedef {import("../shared/types").ConfigData} ConfigData */ /** @typedef {import("../shared/types").DeprecatedRuleInfo} DeprecatedRuleInfo */ /** @typedef {import("../shared/types").LintMessage} LintMessage */ +/** @typedef {import("../shared/types").LintResult} LintResult */ /** @typedef {import("../shared/types").ParserOptions} ParserOptions */ /** @typedef {import("../shared/types").Plugin} Plugin */ /** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */ diff --git a/lib/linter/apply-disable-directives.js b/lib/linter/apply-disable-directives.js index 459c8591196..13ced990ff4 100644 --- a/lib/linter/apply-disable-directives.js +++ b/lib/linter/apply-disable-directives.js @@ -5,6 +5,16 @@ "use strict"; +//------------------------------------------------------------------------------ +// Typedefs +//------------------------------------------------------------------------------ + +/** @typedef {import("../shared/types").LintMessage} LintMessage */ + +//------------------------------------------------------------------------------ +// Module Definition +//------------------------------------------------------------------------------ + const escapeRegExp = require("escape-string-regexp"); /** @@ -196,7 +206,7 @@ function processUnusedDisableDirectives(allDirectives) { * @param {Object} options options for applying directives. This is the same as the options * for the exported function, except that `reportUnusedDisableDirectives` is not supported * (this function always reports unused disable directives). - * @returns {{problems: Problem[], unusedDisableDirectives: Problem[]}} An object with a list + * @returns {{problems: LintMessage[], unusedDisableDirectives: LintMessage[]}} An object with a list * of problems (including suppressed ones) and unused eslint-disable directives */ function applyDirectives(options) { diff --git a/lib/linter/config-comment-parser.js b/lib/linter/config-comment-parser.js index 643de8f2d31..9aab3c44458 100644 --- a/lib/linter/config-comment-parser.js +++ b/lib/linter/config-comment-parser.js @@ -19,6 +19,12 @@ const levn = require("levn"), const debug = require("debug")("eslint:config-comment-parser"); +//------------------------------------------------------------------------------ +// Typedefs +//------------------------------------------------------------------------------ + +/** @typedef {import("../shared/types").LintMessage} LintMessage */ + //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ @@ -61,7 +67,7 @@ module.exports = class ConfigCommentParser { * Parses a JSON-like config. * @param {string} string The string to parse. * @param {Object} location Start line and column of comments for potential error message. - * @returns {({success: true, config: Object}|{success: false, error: Problem})} Result map object + * @returns {({success: true, config: Object}|{success: false, error: LintMessage})} Result map object */ parseJsonConfig(string, location) { debug("Parsing JSON config"); @@ -109,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 ff8395d2601..233cbed5b5c 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -364,7 +364,7 @@ function extractDirectiveComment(value) { * @param {ASTNode} ast The top node of the AST. * @param {function(string): {create: Function}} ruleMapper A map from rule IDs to defined rules * @param {string|null} warnInlineConfig If a string then it should warn directive comments as disabled. The string value is the config name what the setting came from. - * @returns {{configuredRules: Object, enabledGlobals: {value:string,comment:Token}[], exportedVariables: Object, problems: Problem[], disableDirectives: DisableDirective[]}} + * @returns {{configuredRules: Object, enabledGlobals: {value:string,comment:Token}[], exportedVariables: Object, problems: LintMessage[], disableDirectives: DisableDirective[]}} * A collection of the directive comments that were found, along with any problems that occurred when parsing */ function getDirectiveComments(ast, ruleMapper, warnInlineConfig) { @@ -775,7 +775,7 @@ function analyzeScope(ast, languageOptions, visitorKeys) { * @param {string} text The text to parse. * @param {LanguageOptions} languageOptions Options to pass to the parser * @param {string} filePath The path to the file being parsed. - * @returns {{success: false, error: Problem}|{success: true, sourceCode: SourceCode}} + * @returns {{success: false, error: LintMessage}|{success: true, sourceCode: SourceCode}} * An object containing the AST and parser services if parsing was successful, or the error if parsing failed * @private */ @@ -851,7 +851,8 @@ function parse(text, languageOptions, filePath) { severity: 2, message, line: ex.lineNumber, - column: ex.column + column: ex.column, + nodeType: null } }; } @@ -921,7 +922,7 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze( * @param {boolean} disableFixes If true, it doesn't make `fix` properties. * @param {string | undefined} cwd cwd of the cli * @param {string} physicalFilename The full path of the file on disk without any code block information - * @returns {Problem[]} An array of reported problems + * @returns {LintMessage[]} An array of reported problems */ function runRules(sourceCode, configuredRules, ruleMapper, parserName, languageOptions, settings, filename, disableFixes, cwd, physicalFilename) { const emitter = createEmitter(); @@ -1253,7 +1254,8 @@ class Linter { severity: 2, message: `Configured parser '${config.parser}' was not found.`, line: 0, - column: 0 + column: 0, + nodeType: null }]; } parserName = config.parser; @@ -1464,7 +1466,8 @@ class Linter { severity: 2, message, line: ex.lineNumber, - column: ex.column + column: ex.column, + nodeType: null } ]; } @@ -1729,7 +1732,8 @@ class Linter { severity: 1, message: `No matching configuration found for ${filename}.`, line: 0, - column: 0 + column: 0, + nodeType: null } ]; } @@ -1794,7 +1798,8 @@ class Linter { severity: 2, message, line: ex.lineNumber, - column: ex.column + column: ex.column, + nodeType: null } ]; } @@ -1840,7 +1845,7 @@ class Linter { /** * Given a list of reported problems, distinguish problems between normal messages and suppressed messages. * The normal messages will be returned and the suppressed messages will be stored as lastSuppressedMessages. - * @param {Problem[]} problems A list of reported problems. + * @param {Array} problems A list of reported problems. * @returns {LintMessage[]} A list of LintMessage. */ _distinguishSuppressedMessages(problems) { diff --git a/lib/linter/report-translator.js b/lib/linter/report-translator.js index 781b3136ec5..7d2705206cd 100644 --- a/lib/linter/report-translator.js +++ b/lib/linter/report-translator.js @@ -17,6 +17,8 @@ const interpolate = require("./interpolate"); // Typedefs //------------------------------------------------------------------------------ +/** @typedef {import("../shared/types").LintMessage} LintMessage */ + /** * An error message description * @typedef {Object} MessageDescriptor @@ -29,23 +31,6 @@ const interpolate = require("./interpolate"); * @property {Array<{desc?: string, messageId?: string, fix: Function}>} suggest Suggestion descriptions and functions to create a the associated fixes. */ -/** - * Information about the report - * @typedef {Object} ReportInfo - * @property {string} ruleId The rule ID - * @property {(0|1|2)} severity Severity of the error - * @property {(string|undefined)} message The message - * @property {(string|undefined)} [messageId] The message ID - * @property {number} line The line number - * @property {number} column The column number - * @property {(number|undefined)} [endLine] The ending line number - * @property {(number|undefined)} [endColumn] The ending column number - * @property {(string|null)} nodeType Type of node - * @property {string} source Source text - * @property {({text: string, range: (number[]|null)}|null)} [fix] The fix object - * @property {Array<{text: string, range: (number[]|null)}|null>} [suggestions] Suggestion info - */ - //------------------------------------------------------------------------------ // Module Definition //------------------------------------------------------------------------------ @@ -239,7 +224,7 @@ function mapSuggestions(descriptor, sourceCode, messages) { * @param {{start: SourceLocation, end: (SourceLocation|null)}} options.loc Start and end location * @param {{text: string, range: (number[]|null)}} options.fix The fix object * @param {Array<{text: string, range: (number[]|null)}>} options.suggestions The array of suggestions objects - * @returns {function(...args): ReportInfo} Function that returns information about the report + * @returns {LintMessage} Information about the report */ function createProblem(options) { const problem = { @@ -314,7 +299,7 @@ function validateSuggestions(suggest, messages) { * problem for the Node.js API. * @param {{ruleId: string, severity: number, sourceCode: SourceCode, messageIds: Object, disableFixes: boolean}} metadata Metadata for the reported problem * @param {SourceCode} sourceCode The `SourceCode` instance for the text being linted - * @returns {function(...args): ReportInfo} Function that returns information about the report + * @returns {function(...args): LintMessage} Function that returns information about the report */ module.exports = function createReportTranslator(metadata) { diff --git a/lib/shared/types.js b/lib/shared/types.js index 20335f68a73..5c10462587a 100644 --- a/lib/shared/types.js +++ b/lib/shared/types.js @@ -96,10 +96,12 @@ module.exports = {}; * @property {number|undefined} column The 1-based column number. * @property {number} [endColumn] The 1-based column number of the end location. * @property {number} [endLine] The 1-based line number of the end location. - * @property {boolean} fatal If `true` then this is a fatal error. + * @property {boolean} [fatal] If `true` then this is a fatal error. * @property {{range:[number,number], text:string}} [fix] Information for autofix. * @property {number|undefined} line The 1-based line number. * @property {string} message The error message. + * @property {string} [messageId] The ID of the message in the rule's meta. + * @property {(string|null)} nodeType Type of node * @property {string|null} ruleId The ID of the rule which makes this message. * @property {0|1|2} severity The severity of this message. * @property {Array<{desc?: string, messageId?: string, fix: {range: [number, number], text: string}}>} [suggestions] Information for suggestions. @@ -110,10 +112,12 @@ module.exports = {}; * @property {number|undefined} column The 1-based column number. * @property {number} [endColumn] The 1-based column number of the end location. * @property {number} [endLine] The 1-based line number of the end location. - * @property {boolean} fatal If `true` then this is a fatal error. + * @property {boolean} [fatal] If `true` then this is a fatal error. * @property {{range:[number,number], text:string}} [fix] Information for autofix. * @property {number|undefined} line The 1-based line number. * @property {string} message The error message. + * @property {string} [messageId] The ID of the message in the rule's meta. + * @property {(string|null)} nodeType Type of node * @property {string|null} ruleId The ID of the rule which makes this message. * @property {0|1|2} severity The severity of this message. * @property {Array<{kind: string, justification: string}>} suppressions The suppression info. diff --git a/tests/lib/cli-engine/cli-engine.js b/tests/lib/cli-engine/cli-engine.js index 03dff9bb3d7..2528a398ea1 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 aa30047edc2..c05a869641d 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 2130623d40f..6cfb64a1d72 100644 --- a/tests/lib/eslint/flat-eslint.js +++ b/tests/lib/eslint/flat-eslint.js @@ -506,7 +506,8 @@ describe("FlatESLint", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], @@ -546,7 +547,8 @@ describe("FlatESLint", () => { severity: 2, message: "Parsing error: Unexpected token", line: 1, - column: 10 + column: 10, + nodeType: null } ], suppressedMessages: [], @@ -636,7 +638,8 @@ describe("FlatESLint", () => { severity: 2, message: "Parsing error: Unexpected token is", line: 1, - column: 19 + column: 19, + nodeType: null } ], suppressedMessages: [], @@ -5088,9 +5091,11 @@ describe("FlatESLint", () => { fixableWarningCount: 0, messages: [ { + ruleId: null, fatal: false, message: "File ignored by default. Use \"--ignore-pattern '!node_modules/*'\" to override.", - severity: 1 + severity: 1, + nodeType: null } ], usedDeprecatedRules: [], diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index d2fe9eaca2f..be1380f6880 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -6882,7 +6882,8 @@ var a = "test2"; severity: 2, message: "Preprocessing error: Invalid syntax", line: 1, - column: 1 + column: 1, + nodeType: null } ]); }); @@ -8864,7 +8865,8 @@ describe("Linter with FlatConfigArray", () => { severity: 1, message: "No matching configuration found for filename.ts.", line: 0, - column: 0 + column: 0, + nodeType: null }); }); @@ -15765,7 +15767,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 2e372b04c45..4ad793ac79a 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 }); }); });