-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Upgrade: Reduce number of false-positive migrations of the important modifier #14737
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
Changes from all commits
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 |
---|---|---|
|
@@ -19,9 +19,50 @@ export function important( | |
designSystem: DesignSystem, | ||
_userConfig: Config, | ||
rawCandidate: string, | ||
location?: { | ||
contents: string | ||
start: number | ||
end: number | ||
}, | ||
): string { | ||
for (let candidate of parseCandidate(rawCandidate, designSystem)) { | ||
if (candidate.important && candidate.raw[candidate.raw.length - 1] !== '!') { | ||
// The important migration is one of the most broad migrations with a high | ||
// potential of matching false positives since `!` is a valid character in | ||
// most programming languages. Since v4 is technically backward compatible | ||
// with v3 in that it can read `!` in the front of the utility too, we err | ||
// on the side of caution and only migrate candidates that we are certain | ||
// are inside of a string. | ||
if (location) { | ||
let isQuoteBeforeCandidate = false | ||
for (let i = location.start - 1; i >= 0; i--) { | ||
let char = location.contents.at(i)! | ||
if (char === '\n') { | ||
break | ||
} | ||
if (isQuote(char)) { | ||
isQuoteBeforeCandidate = true | ||
break | ||
} | ||
} | ||
|
||
let isQuoteAfterCandidate = false | ||
for (let i = location.end; i < location.contents.length; i++) { | ||
let char = location.contents.at(i)! | ||
if (char === '\n') { | ||
break | ||
} | ||
if (isQuote(char)) { | ||
isQuoteAfterCandidate = true | ||
break | ||
} | ||
} | ||
|
||
if (!isQuoteBeforeCandidate || !isQuoteAfterCandidate) { | ||
continue | ||
} | ||
} | ||
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. Could we in theory scan backwards and forwards to look for quotes _on the same line? I feel like this logic may be too restrictive. 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. liked that, implemented 😎 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. I think that change disappeared — don't see it in the diff 😬 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. @thecrypticace forgot to push it 🫠 |
||
|
||
// The printCandidate function will already put the exclamation mark in | ||
// the right place, so we just need to mark this candidate as requiring a | ||
// migration. | ||
|
@@ -31,3 +72,14 @@ export function important( | |
|
||
return rawCandidate | ||
} | ||
|
||
function isQuote(char: string) { | ||
switch (char) { | ||
case '"': | ||
case "'": | ||
case '`': | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.