tools icon indicating copy to clipboard operation
tools copied to clipboard

feature(rome_js_analyze): implement import sorting for named specifiers

Open leops opened this issue 3 years ago • 2 comments

Summary

This PR extends the organizeImports code action to not only sort whole import nodes, but also reorder the named import specifiers within a given node. The implementation is made quite complex by the necessity of moving nodes along with the relevant comments while remaining syntactically correct, which means inserting or removing comma tokens and newline trivias as nodes get moved to different places. The current solution correctly handles nodes that were formatted using the Rome Formatter, but the output may be formatted incorrectly when the formatting of the input get more complex (this is only formatting though, it should not result in any syntax errors).

I've also fixed a bug in the SyntaxTrivia::first method that was causing it to return a trivia piece with an incorrect source offset.

Test Plan

I've added an additional snapshot file for the rule testing both case that are expected to work correctly, as well as more complex patterns that are not currently well supported.

leops avatar Dec 01 '22 16:12 leops

Deploy Preview for docs-rometools canceled.

Name Link
Latest commit 3fcd0d2498dcf3329d828d9bce3d735681845f0b
Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/638a222a3dece200091de003

netlify[bot] avatar Dec 01 '22 16:12 netlify[bot]

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44936 44936 0
Failed 943 943 0
Panics 0 0 0
Coverage 97.94% 97.94% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1757 1757 0
Failed 4189 4189 0
Panics 0 0 0
Coverage 29.55% 29.55% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12397 12397 0
Failed 3860 3860 0
Panics 0 0 0
Coverage 76.26% 76.26% 0.00%

github-actions[bot] avatar Dec 01 '22 17:12 github-actions[bot]