fix: report messages for configuration comments correctly#618
fix: report messages for configuration comments correctly#618andreahlert wants to merge 4 commits intoeslint:mainfrom
Conversation
31d9362 to
dcccf5a
Compare
|
Thanks for the review, @Ari4ka! |
|
@andreahlert thanks, I'll take a look when I'm able. Did you use AI to generate this PR? |
|
Hey @nzakas . Everybody says that to me 😅 I write lots of docs at work so it's a habit to be super detailed. And I usually generate an AI template of PR (for headers for exemple), to keep the same looking, but its all my writing. I'll keep PR descriptions shorter going forward. Lmk if you want me to clarify anything about the implementation! |
| if (commentInfo) { | ||
| return { | ||
| ...message, | ||
| line: commentInfo.position.start.line, |
There was a problem hiding this comment.
Question to the team: Is it okay that the precise location is lost?
For example when a disable directive has multiple rules but only one is unused, the location spans only the name of the unused rule instead of the whole directive.
There was a problem hiding this comment.
I'm having a hard time parsing your question. Are you saying that previously we spanned only the unused rule name and this change loses that? If so, I'd say we don't want to lose that.
Or are you saying we didn't span only the unused rule name and this PR does? Then I'd say this is the preferred approach.
There was a problem hiding this comment.
To clarify for @nzakas: before this PR those messages were dropped (no report at all). With this PR we report them but the position is the whole HTML comment (start line of the comment in the Markdown), not the exact column of the unused rule name inside the comment. So we’re not losing the previous “span only the unused rule name” behavior; we’re adding reporting with a coarser location.
If the team wants column-level precision (e.g. only the unused rule name) we’d need extra mapping from the linted code columns back to the original comment;
I can explore that in a follow-up if needed.
There was a problem hiding this comment.
I agree we should postpone this to a follow-up.
There was a problem hiding this comment.
From what I can tell, the current commentInfo type is derived from the Markdown HTML node's position field, which contains full position information including start.line, start.column, end.line, and end.column.
Also, the comment is sanitized by the getComment helper before being pushed into the htmlComments array:
Therefore, the comment syntax should be valid and retain full position information (verified via logging).
Losing the position information causes the following issue: only the first character is highlighted instead of the entire line.
- Current
- Expected
I believe retaining the full position information here is necessary.
|
Thank you for submitting a PR for this. It is a really good starting for fixing this. |
|
Hi — there's a CI failure. If you have a moment, could you take a look? |
Lint was failing because report-unused-disable-directives now correctly reports warnings in .md files; tests/fixtures/long.md has intentional directives that trigger those warnings. Align with main config which already ignores tests/fixtures. Refs eslint#618
Done! Ready for final review. |
|
|
||
| export interface BlockBase { | ||
| baseIndentText: string; | ||
| comments: string[]; |
There was a problem hiding this comment.
The comments property should be removed as it is no longer set.
There was a problem hiding this comment.
Can you double-check this? It seems like comments is still used.
There was a problem hiding this comment.
It seems the current implementation still uses the comments property. Otherwise it throws a type error.
There was a problem hiding this comment.
Confirmed, comments is still used in getBlockRangeMap, block.comments.join for assembling linted text, and leadingCommentLines calculation. Kept it as-is.
There was a problem hiding this comment.
My point was that comments is unnecessary as the relevant data is available in commentInfos. Further on line 430 the code also recreates the data from comments with wrapComment(commentInfo.text) which would be available on the same index on comments.
There was a problem hiding this comment.
Could you also take a look at the comments here when you have a moment?
|
Sorry for the delay. Other than the small things I mentioned, the changes LGTM. |
Lint was failing because report-unused-disable-directives now correctly reports warnings in .md files; tests/fixtures/long.md has intentional directives that trigger those warnings. Align with main config which already ignores tests/fixtures. Refs eslint#618 Signed-off-by: André Ahlert <andre@aex.partners>
- Rename CommentInfo to MappedCommentLocation for clarity - Import MappedCommentLocation type from ./types.js instead of inline @typedef - Remove unnecessary * from wrapComment regex character sets - Refactor tests to use beforeEach with shared config - Add reportUnusedDisableDirectives tests under LegacyESLint describe block Signed-off-by: André Ahlert <andre@aex.partners>
e4ed80c to
aaa9b03
Compare
|
@nzakas Renamed |
|
@lumirlumir Rebased on main, all feedback addressed. Tests and lint are passing. |
|
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
nzakas
left a comment
There was a problem hiding this comment.
LGTM. Thanks!
Leaving open for @lumirlumir to review.
|
@andreahlert be sure to double-check the CI failures. |
lumirlumir
left a comment
There was a problem hiding this comment.
The test in https://github.com/eslint/markdown/blob/main/tests/types/types.test.ts needs to be updated to fix the CI failure. Running npm run fmt will also resolve the formatting error.
Signed-off-by: André Ahlert <andre@aex.partners>
|
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
|
This PR needs a new review. |
lumirlumir
left a comment
There was a problem hiding this comment.
Apologies for the delay.
This PR needs some dedicated time for me to review. I’ll take a thorough look within 2-3 days. I appreciate your patience.
|
|
||
| export interface BlockBase { | ||
| baseIndentText: string; | ||
| comments: string[]; |
There was a problem hiding this comment.
Could you also take a look at the comments here when you have a moment?
| export default defineConfig([ | ||
| globalIgnores( | ||
| ["**/*.js", "**/.cjs", "**/.mjs"], | ||
| ["**/*.js", "**/.cjs", "**/.mjs", "**/tests/fixtures/**"], |
There was a problem hiding this comment.
I think this comment still hasn't been addressed.
| position: { | ||
| start: { line: number; column: number }; | ||
| end?: { line: number; column: number }; | ||
| }; |
There was a problem hiding this comment.
| position: { | |
| start: { line: number; column: number }; | |
| end?: { line: number; column: number }; | |
| }; | |
| position: Position; |
The current position information comes from node.position, which uses the Position type from unist.
htmlComments.push({
text: comment,
position: node.position,
});However, the current position information is hard-coded and not derived from the existing type.
Could we add at the top level import type { Position } from "unist"; and reuse that type?
The current type testing in typest.test.ts relies on this type information, so the type tests will need to be adjusted accordingly.
| export interface BlockBase { | ||
| baseIndentText: string; | ||
| comments: string[]; | ||
| commentInfos: MappedCommentLocation[]; |
There was a problem hiding this comment.
As noted in #618 (comment), I also think that the commentInfos type can be removed and consolidated into the comments type to minimize changes.
For example, if we remove MappedCommentLocation type and simply create a Comment type as follows:
export interface Comment {
text: string;
position: Position;
}And update BlockBase as follows:
export interface BlockBase {
// ...
- comments: string[];
+ comments: Comment[];
// ...
}| * original HTML comment info. This allows us to map messages that point to | ||
| * configuration comments back to their original location in the Markdown. | ||
| */ | ||
| const commentLineMap = new Map(); |
There was a problem hiding this comment.
| const commentLineMap = new Map(); | |
| /** @type {...} */ | |
| const commentLineMap = new Map(); |
Could we specify its type using JSDoc syntax? Currently it's declared as const commentLineMap: Map<any, any>, so the type information is lost when other code consumes it.
| if (commentInfo) { | ||
| return { | ||
| ...message, | ||
| line: commentInfo.position.start.line, |
There was a problem hiding this comment.
From what I can tell, the current commentInfo type is derived from the Markdown HTML node's position field, which contains full position information including start.line, start.column, end.line, and end.column.
Also, the comment is sanitized by the getComment helper before being pushed into the htmlComments array:
Therefore, the comment syntax should be valid and retain full position information (verified via logging).
Losing the position information causes the following issue: only the first character is highlighted instead of the entire line.
- Current
- Expected
I believe retaining the full position information here is necessary.
|
Could you take a look at the merge conflict as well? |
Summary
Previously, ESLint messages that pointed to configuration comments (such as unused disable directive warnings) were being silently dropped because the
adjustMessagefunction returnednullfor any message pointing to lines before the actual code content.This change:
This fixes the issue where
--report-unused-disable-directiveswould not work with the markdown processor, as those warnings were being filtered out.Before
After
Test plan
reportUnusedDisableDirectiveswith tests for single-line and multi-line HTML commentsFixes #115