oxc/tasks
EYHN 1781318f44
fix(rulegen): handle join('\n') style test code (#763)
# 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

```js
{
  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.


![](https://github.com/web-infra-dev/oxc/assets/13579374/195ed4ba-1efb-4c3f-9e49-0ebdb5527506)

# 2. remove extra `,`

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


45cf5fc3da/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:

```diff
- test_code.replace('\n', "\n\t\t\t")
+ test_code.replace('\n', "\n\t\t\t").replace('\\', "\\\\").replace('\"', "\\\"")
```
2023-08-19 23:19:51 +08:00
..
benchmark feat(linter): enable module record builder 2023-08-02 11:44:27 +08:00
common fix(rulegen): fix ureq not working without tls 2023-06-09 12:43:41 +08:00
coverage feat(ast): add SymbolId and ReferenceId (#755) 2023-08-19 18:09:47 +08:00
minsize feat(minifier): compress undefined variable declarations (#532) 2023-07-10 10:33:42 +08:00
rulegen fix(rulegen): handle join('\n') style test code (#763) 2023-08-19 23:19:51 +08:00
libs.txt chore(benchmark): sync js versions to privatenumber/minification-benchmarks 2023-05-22 12:23:24 +08:00