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

fix(rulegen): handle join('\n') style test code #763

Merged
merged 1 commit into from
Aug 19, 2023

Conversation

EYHN
Copy link
Contributor

@EYHN EYHN commented Aug 19, 2023

1. Support join('\n')

I'm trying to run just new-rule no-unexpected-multiline, It found rulegen not support test code pieced together using array.json("\n"), like

{
  code: [
      "const x = aaaa<",
      "  test",
      ">/*",
      "test",
      "*/`foo`"
  ].join("\n")
}

I found this kind of code widely in the eslint codebase, so it will be great if we can support this.

2. remove extra ,

And I found when meet unsupported code, rulegen will generate an extra ,, so I added a filter at

https://github.com/web-infra-dev/oxc/blob/45cf5fc3da04be07e2293ad1a8dc77b8690f1e9f/tasks/rulegen/src/main.rs#L363

3. handle escape string

The escape / and trailing / in the javascript code will break rulegen. example: "\"abc\\\n(123)\""

I made the following changes:

- test_code.replace('\n', "\n\t\t\t")
+ test_code.replace('\n', "\n\t\t\t").replace('\\', "\\\\").replace('\"', "\\\"")

@CLAassistant
Copy link

CLAassistant commented Aug 19, 2023

CLA assistant check
All committers have signed the CLA.

@Boshen Boshen merged commit 1781318 into oxc-project:main Aug 19, 2023
21 checks passed
@Boshen
Copy link
Member

Boshen commented Aug 19, 2023

Oh nice! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants