Skip to content

Commit

Permalink
Docs: LintMessage.line and column are possibly undefined (#15032)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
btmills committed Sep 10, 2021
1 parent 921ba1e commit 91e82f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/developer-guide/nodejs-api.md
Expand Up @@ -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`)<br>
The error message.
* `line` (`number`)<br>
* `line` (`number | undefined`)<br>
The 1-based line number of the begin point of this message.
* `column` (`number`)<br>
* `column` (`number | undefined`)<br>
The 1-based column number of the begin point of this message.
* `endLine` (`number | undefined`)<br>
The 1-based line number of the end point of this message. This property is undefined if this message is not a range.
Expand Down
4 changes: 2 additions & 2 deletions lib/shared/types.js
Expand Up @@ -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.
Expand Down

0 comments on commit 91e82f5

Please sign in to comment.