Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: LintMessage.line and column are possibly undefined #15032

Merged
merged 1 commit into from Sep 10, 2021

Conversation

btmills
Copy link
Member

@btmills btmills commented Sep 6, 2021

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[x] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

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.

eslint/lib/linter/linter.js

Lines 693 to 711 in f966fe6

} catch (ex) {
// If the message includes a leading line number, strip it:
const message = `Parsing error: ${ex.message.replace(/^line \d+:/iu, "").trim()}`;
debug("%s\n%s", message, ex.stack);
return {
success: false,
error: {
ruleId: null,
fatal: true,
severity: 2,
message,
line: ex.lineNumber,
column: ex.column
}
};
}

In eslint/eslint-plugin-markdown#191, the processor would crash when attempting to map messages without a line.

Is there anything you'd like reviewers to focus on?

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.

For the JSDoc type, I used {number|undefined} line instead of {number} [line] because line and column are always present but may have the value undefined.

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.
@btmills btmills added documentation Relates to ESLint's documentation core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 6, 2021
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@btmills btmills merged commit 91e82f5 into master Sep 10, 2021
@btmills btmills deleted the lintmessage-line-column-undefined branch September 10, 2021 05:37
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Mar 10, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features documentation Relates to ESLint's documentation evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants