oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
12.2k stars 442 forks source link

rulegen: support `outdent` and `dedent` tagged template expressions #6645

Open camchenry opened 2 weeks ago

camchenry commented 2 weeks ago

Currently, we filter out any test cases which use the outdent and dedent functions, which are sometimes used for unicorn and typescriot-eslint rule tests. This means that we are likely missing many test cases from our rule testing. We should implement our own version of dedent and outdent so that we can import these test cases as well:

https://github.com/oxc-project/oxc/blob/92812349e5266b074d2cb050cc7a6f200e4ac914/tasks/rulegen/src/main.rs#L319

gaoachao commented 1 week ago

I would like to work on this issue. Can I try this?

gaoachao commented 1 week ago

It seems that there are still some places in rulegen that do not handle String.raw and dedent, outdent in Expression::TaggedTemplateExpression. I am thinking whether to deal with it in this issue, I would be grateful if you could give me some advice or guidance. https://github.com/oxc-project/oxc/blob/4348eae1577bd72094d1ec1f6c2422c20288a3d9/tasks/rulegen/src/main.rs#L271 https://github.com/oxc-project/oxc/blob/4348eae1577bd72094d1ec1f6c2422c20288a3d9/tasks/rulegen/src/main.rs#L229

camchenry commented 1 week ago

It seems that there are still some places in rulegen that do not handle String.raw and dedent, outdent in Expression::TaggedTemplateExpression. I am thinking whether to deal with it in this issue, I would be grateful if you could give me some advice or guidance.

I think we should try to handle outdent/dedent wherever it shows up, but I don't think we need to handle it all in one PR. It would probably help to break it up into a few smaller PRs to get feedback early and make it easier to review (and implement)

https://github.com/oxc-project/oxc/blob/4348eae1577bd72094d1ec1f6c2422c20288a3d9/tasks/rulegen/src/main.rs#L271

This does seem like a case we should handle, outdent in output seems to be a case that is often used: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/0d91fe8530611f68a95261e2a8f5f80b12caee35/test/prefer-ternary.mjs#L107-L111. We don't support String.raw here yet, but that would be a good idea too, since there are examples of that: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/0d91fe8530611f68a95261e2a8f5f80b12caee35/test/string-content.mjs#L116

https://github.com/oxc-project/oxc/blob/4348eae1577bd72094d1ec1f6c2422c20288a3d9/tasks/rulegen/src/main.rs#L229

We already handle String.raw here, but I think we should handle outdent here as well, since it's also common to see outdent inside of a code property: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/0d91fe8530611f68a95261e2a8f5f80b12caee35/test/prefer-ternary.mjs#L98-L106

gaoachao commented 1 week ago

@camchenry Thank you very much for your reply. Considering the reusability of code, I have already handled String.raw and dedent, outdent in Expression::TaggedTemplateExpression. I plan to handle noFormat (in typescript-eslint) in the future, and I will PR again at that time. If possible, could you please help me review #6866? Thanks in advance for your suggestions on my code.