Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

baseballyama
Copy link
Contributor

Copy link

graphite-app bot commented Dec 27, 2024

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 27, 2024
Copy link

codspeed-hq bot commented Dec 27, 2024

CodSpeed Performance Report

Merging #8151 will not alter performance

Comparing baseballyama:feat/linter/no-octal-escape (c868ae4) with main (5234d96)

Summary

✅ 29 untouched benchmarks

Comment on lines 58 to 63
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()
})
Copy link
Contributor

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

lazy_static! {
static ref CUSTOM_ERROR_REGEX_PATTERN: Regex =
Regex::new(r"^(?:[A-Z][\da-z]*)*Error$").unwrap();
}

Copy link
Contributor Author

@baseballyama baseballyama Dec 28, 2024

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,
Copy link
Contributor

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?)

Copy link
Contributor Author

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.

ac4226f

@Boshen
Copy link
Member

Boshen commented Dec 28, 2024

It seems like this is already a syntax error, which does not require a linter implementation.

Error: '0'-prefixed octal literals and octal escape sequences are deprecated

@baseballyama
Copy link
Contributor Author

baseballyama commented Dec 28, 2024

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?
And this rule would clearly be valuable if it becomes fixable.

@baseballyama baseballyama force-pushed the feat/linter/no-octal-escape branch 3 times, most recently from a9d99de to daf1aef Compare December 28, 2024 00:55
@baseballyama baseballyama force-pushed the feat/linter/no-octal-escape branch from daf1aef to ac4226f Compare December 28, 2024 00:55
@baseballyama baseballyama requested a review from camc314 December 28, 2024 00:58
Comment on lines 125 to 148
× 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
╰────
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad test case?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@camc314
Copy link
Contributor

camc314 commented Dec 28, 2024

looks like it's only a semantic error in strict mode

if ctx.strict_mode() {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants