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
Update: support multiple fixes in a report (fixes #7348) #8101
Changes from 1 commit
926b00a
7271a5e
5dba973
cc5de10
c888f09
3847673
a4c3372
f85aee0
11a9043
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,18 +92,18 @@ function mergeFixes(fixes, sourceCode) { | |
const start = fixes[0].range[0]; | ||
const end = fixes[fixes.length - 1].range[1]; | ||
let text = ""; | ||
let lastPos = Math.max(0, start); | ||
let lastPos = Number.MIN_SAFE_INTEGER; | ||
|
||
for (const fix of fixes) { | ||
assert(fix.range[0] >= lastPos || fix.range[0] < 0, "Fix objects must not be overlapped in a report."); | ||
assert(fix.range[0] >= lastPos, "Fix objects must not be overlapped in a report."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requiring the ranges to be disjoint could make With this API, I guess what I'd do is compute One possible solution, if we're ok with it being a little magical, is to allow fixes to be completely contained within other fixes and always use the most specific one. Or maybe the fixes could be applied in order in a reasonable way, with later ones taking precedence. (Although I recognize that there's maybe some disagreement about whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I think it's rare case if we need locking the outer node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, I can see how the fixes for I think locking the outer node can be nice because it's safer and makes the rule simpler, but I can see the argument that it's usually not necessary. And if the long-term plan is to allow a distinction between "fixing" and "locking" operations, then I think it shouldn't be hard to allow the two types to overlap, which would address my concerns there. |
||
|
||
if (fix.range[0] >= 0) { | ||
text += originalText.slice(lastPos, fix.range[0]); | ||
text += originalText.slice(Math.max(0, start, lastPos), fix.range[0]); | ||
} | ||
text += fix.text; | ||
lastPos = fix.range[1]; | ||
} | ||
text += originalText.slice(lastPos, end); | ||
text += originalText.slice(Math.max(0, start, lastPos), end); | ||
|
||
return { range: [start, end], text }; | ||
} | ||
|
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.
Maybe it would be better to use
-Infinity
in case someone uses extremely small numbers in fix ranges for whatever reason, but I think it's probably fine -- files usually don't have 253 BOMs. 😄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.
Yeah 😄
I expect that integer variables are faster by compiler optimization.