-
Notifications
You must be signed in to change notification settings - Fork 74
fix: false negatives and positives in no-reversed-media-syntax
#473
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
Conversation
…lse-negatives-no-reversed-media-syntax
Heading
/TableCell
false negatives in no-reversed-media-syntax
no-reversed-media-syntax
function findReversedMediaSyntax(node) { | ||
const text = context.sourceCode.getText(node); | ||
const skipRanges = findSkipRanges(node); | ||
let match; | ||
|
||
while ((match = reversedPattern.exec(text)) !== null) { | ||
const [reversedSyntax, label, url] = match; | ||
const matchIndex = match.index; | ||
const matchLength = reversedSyntax.length; | ||
|
||
if ( | ||
isInSkipRange( | ||
matchIndex + node.position.start.offset, | ||
skipRanges, | ||
) | ||
) { | ||
continue; | ||
} | ||
|
||
const { | ||
lineOffset: startLineOffset, | ||
columnOffset: startColumnOffset, | ||
} = findOffsets(text, matchIndex); | ||
const { | ||
lineOffset: endLineOffset, | ||
columnOffset: endColumnOffset, | ||
} = findOffsets(text, matchIndex + matchLength); | ||
|
||
const baseColumn = 1; | ||
const nodeStartLine = node.position.start.line; | ||
const nodeStartColumn = node.position.start.column; | ||
const startLine = nodeStartLine + startLineOffset; | ||
const endLine = nodeStartLine + endLineOffset; | ||
const startColumn = | ||
(startLine === nodeStartLine | ||
? nodeStartColumn | ||
: baseColumn) + startColumnOffset; | ||
const endColumn = | ||
(endLine === nodeStartLine ? nodeStartColumn : baseColumn) + | ||
endColumnOffset; | ||
|
||
context.report({ | ||
loc: { | ||
start: { | ||
line: startLine, | ||
column: startColumn, | ||
}, | ||
messageId: "reversedSyntax", | ||
fix(fixer) { | ||
const startOffset = | ||
node.position.start.offset + matchIndex; | ||
const endOffset = startOffset + matchLength; | ||
|
||
return fixer.replaceTextRange( | ||
[startOffset, endOffset], | ||
`[${label}](${url})`, | ||
); | ||
end: { | ||
line: endLine, | ||
column: endColumn, | ||
}, | ||
}); | ||
} | ||
}, | ||
messageId: "reversedSyntax", | ||
fix(fixer) { | ||
const startOffset = | ||
node.position.start.offset + matchIndex; | ||
const endOffset = startOffset + matchLength; | ||
|
||
return fixer.replaceTextRange( | ||
[startOffset, endOffset], | ||
`[${label}](${url})`, | ||
); | ||
}, | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The git diff shows some changes here, but I didn't change the logic itself.
I just wrapped the existing logic in a single function and reused it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks.
It looks like there's a merge conflict. Can you take a look? |
I've resolved the merge conflicts. |
Prerequisites checklist
What is the purpose of this pull request?
Hello,
In this PR, I have addressed both false negatives and false positives in
no-reversed-media-syntax
.False Negatives:
Currently, the
no-reversed-media-syntax
rule does not detect error-prone syntax inHeading
andTableCell
nodes.AST
Heading
andTableCell
nodes can containLink
orImage
nodes, but the current logic does not report them.This behavior is also consistent with Markdownlint:
So, I've fixed them to be reported correctly.
False Positives:
For cases involving HTML nodes, the logic should not report them; however, the current logic is producing false positives.
So, I've added HTML nodes to the skip range and excluded them when reporting errors.
For example:
What changes did you make? (Give an overview)
Related Issues
Is there anything you'd like reviewers to focus on?