From 91e82f5c4cfeab5ac6d01865ce0eb9ea0649df39 Mon Sep 17 00:00:00 2001 From: Brandon Mills Date: Fri, 10 Sep 2021 01:37:42 -0400 Subject: [PATCH] Docs: LintMessage.line and column are possibly undefined (#15032) In `lib/linter/linter.js`, the `parse()` function's exception handler translates the exception's message to a `LintMessage`. It also passes through the exception's `lineNumber` and `column`, but the exception is not guaranteed to have those properties. In that case, `LintMessage.line` and `column` can be `undefined`. In eslint/eslint-plugin-markdown#191, the processor would crash when attempting to map messages without a line. Normally widening a type like this would be a breaking change, but since this is only updating the docs to reflect reality, I think this can be a semver-patch change. --- docs/developer-guide/nodejs-api.md | 4 ++-- lib/shared/types.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index 5218d0d7257..54f47c66500 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -376,9 +376,9 @@ The `LintMessage` value is the information of each linting error. The `messages` `true` if this is a fatal error unrelated to a rule, like a parsing error. * `message` (`string`)
The error message. -* `line` (`number`)
+* `line` (`number | undefined`)
The 1-based line number of the begin point of this message. -* `column` (`number`)
+* `column` (`number | undefined`)
The 1-based column number of the begin point of this message. * `endLine` (`number | undefined`)
The 1-based line number of the end point of this message. This property is undefined if this message is not a range. diff --git a/lib/shared/types.js b/lib/shared/types.js index c3b76e42d5f..bbfd2ed9a99 100644 --- a/lib/shared/types.js +++ b/lib/shared/types.js @@ -83,12 +83,12 @@ module.exports = {}; /** * @typedef {Object} LintMessage - * @property {number} column The 1-based column number. + * @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 {{range:[number,number], text:string}} [fix] Information for autofix. - * @property {number} line The 1-based line number. + * @property {number|undefined} line The 1-based line number. * @property {string} message The error message. * @property {string|null} ruleId The ID of the rule which makes this message. * @property {0|1|2} severity The severity of this message.