-
-
Notifications
You must be signed in to change notification settings - Fork 477
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
feat(linter): add no-octal-escape
rule
#8151
base: main
Are you sure you want to change the base?
feat(linter): add no-octal-escape
rule
#8151
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
CodSpeed Performance ReportMerging #8151 will not alter performanceComparing Summary
|
static OCTAL_ESCAPE_PATTERN: OnceLock<Regex> = OnceLock::new(); | ||
|
||
fn get_octal_escape_pattern() -> &'static Regex { | ||
OCTAL_ESCAPE_PATTERN.get_or_init(|| { | ||
Regex::new(r"^(?:[^\\]|\\.)*?\\([0-3][0-7]{1,2}|[4-7][0-7]|(08|09)|[1-7])").unwrap() | ||
}) |
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.
you can use a lazy_static
oxc/crates/oxc_linter/src/rules/unicorn/throw_new_error.rs
Lines 96 to 99 in bd0693b
lazy_static! { | |
static ref CUSTOM_ERROR_REGEX_PATTERN: Regex = | |
Regex::new(r"^(?:[A-Z][\da-z]*)*Error$").unwrap(); | |
} |
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.
I learned this. fixed: 5aaf7e6
/// const str = "\xA9"; | ||
/// ``` | ||
NoOctalEscape, | ||
correctness, |
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.
i think should be possible to have a fixer for this?
could we mark it as pending (unless it's not possible to fix?)
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.
I think this can be auto-fixed, but we need to be careful because it’s impossible to mechanically determine whether the missing backquote was intentional or if u.....
should be used instead.
I’ve marked it as pending for now, but the fixer should be implemented as a dangerous auto-fix.
It seems like this is already a syntax error, which does not require a linter implementation.
|
Don’t you still think it’s effective for improving compatibility with ESLint? |
a9d99de
to
daf1aef
Compare
use lazy_static!
daf1aef
to
ac4226f
Compare
× Invalid Unicode escape sequence | ||
╭─[no_octal_escape.tsx:1:3] | ||
1 │ #\0\01' | ||
· ─ | ||
╰──── | ||
|
||
× Invalid Unicode escape sequence | ||
╭─[no_octal_escape.tsx:1:5] | ||
1 │ #\0\01' | ||
· ─ | ||
╰──── | ||
|
||
× Unterminated string | ||
╭─[no_octal_escape.tsx:1:7] | ||
1 │ #\0\01' | ||
· ─ | ||
╰──── | ||
|
||
× Expected `in` but found `Unknown` | ||
╭─[no_octal_escape.tsx:1:7] | ||
1 │ #\0\01' | ||
· ┬ | ||
· ╰── `in` expected | ||
╰──── |
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.
bad test case?
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.
Ohh a few test cases are failed as unexpected reason. I will check this.
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.
updated: c868ae4
One test did not pass, so I commented it out.
looks like it's only a semantic error in strict mode
|
implement: https://eslint.org/docs/latest/rules/no-octal-escape