+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_analyze): noConfusingArrow #4321

Merged
merged 2 commits into from
Mar 30, 2023
Merged

feat(rome_js_analyze): noConfusingArrow #4321

merged 2 commits into from
Mar 30, 2023

Conversation

malobre
Copy link
Contributor

@malobre malobre commented Mar 24, 2023

Summary

Closes #3931.

Test Plan

just test-lintrule noConfusingArrow

just _touch crates/rome_js_analyze/tests/spec_tests.rs
touch crates/rome_js_analyze/tests/spec_tests.rs
cargo test -p rome_js_analyze -- no_confusing_arrow
   Compiling rome_js_analyze v0.0.0 (/home/malobre/workspace/rust/tools/crates/rome_js_analyze)
    Finished test [unoptimized + debuginfo] target(s) in 6.94s
     Running unittests src/lib.rs (target/debug/deps/rome_js_analyze-f3cf2ebbd37dd529)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 46 filtered out; finished in 0.00s

     Running tests/spec_tests.rs (target/debug/deps/spec_tests-445dd1d975dfdf40)

running 2 tests
test specs::nursery::no_confusing_arrow::invalid_js ... ok
test specs::nursery::no_confusing_arrow::valid_js ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 334 filtered out; finished in 0.16s

   Doc-tests rome_js_analyze

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out; finished in 0.00s

Documentation

  • The PR requires documentation
  • I will create a new PR to update the documentation

@netlify
Copy link

netlify bot commented Mar 24, 2023

Deploy Preview for docs-rometools canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 970f507
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/64248995fdf8f600089c8848

@github-actions github-actions bot added A-Diagnostic Area: errors and diagnostics A-Linter Area: linter A-Project Area: project configuration and loading labels Mar 24, 2023
@malobre
Copy link
Contributor Author

malobre commented Mar 24, 2023

I have not implemented the options, should I also do that ?

If I should, I will need some guidance on options deserialization (doc seems to be outdated since #4160).

@ematipico
Copy link
Contributor

I have not implemented the options, should I also do that ?

If I should, I will need some guidance on options deserialization (doc seems to be outdated since #4160).

We can implement the rule without options for now. That part of the analyzer is still a bit unstable/subject to change

@Conaclos
Copy link
Contributor

Thanks for your contribution! This looks good at first glance!

@malobre malobre marked this pull request as ready for review March 25, 2023 15:39
@malobre malobre requested a review from Conaclos March 25, 2023 15:40
@Conaclos
Copy link
Contributor

Conaclos commented Mar 26, 2023

Our CI check the rules against the code of the website.
A code is triggering the rule:

website/src/playground/Playground.tsx:75:30 lint/nursery/noConfusingArrow  FIXABLE  ━━━━━━━━━━━━━━━━

  × Fat arrows can be confused with some comparison operators (<, >, <=, >=).
  
    73 │ 	const onUpdate = useCallback((viewUpdate: ViewUpdate) => {
    74 │ 		const cursorPosition = viewUpdate.state.selection.ranges[0]?.from ?? 0;
  > 75 │ 		setPlaygroundState((state) =>
       │ 		                           ^^
    76 │ 			state.cursorPosition !== cursorPosition
    77 │ 				? {
  
  i Safe fix: Wrap the function body in parenthesis.
  
     74  74 │   		const cursorPosition = viewUpdate.state.selection.ranges[0]?.from ?? 0;
     75  75 │   		setPlaygroundState((state) =>
     76     │ - → → → state.cursorPosition·!==·cursorPosition
         76 │ + → → → (
         77 │ + → → → state.cursorPosition·!==·cursorPosition
     77  78 │   				? {
     78  79 │   						...state,
     79  80 │   						cursorPosition,
     80  81 │   				  }
     81     │ - → → → → :·state,
         82 │ + → → → → :·state),
     82  83 │   		);
     83  84 │   	}, []);

The PR should thus fix the code that triggers the rule.

The PR should also be rebased against the branch main.

Once these two changes done, I think we can merge it :)

@malobre
Copy link
Contributor Author

malobre commented Mar 27, 2023

Rebased & applied the fix to Playground.tsx however there seems to be a conflict with the formatter which doesn't output parenthesis around the function body.

@Conaclos
Copy link
Contributor

Rebased & applied the fix to Playground.tsx however there seems to be a conflict with the formatter which doesn't output parenthesis around the function body.

I think that website/src/playground/Playground.tsx format just need to be formatted with Rome or a compatible formatter such as Prettier. This should fix the issue.

@malobre
Copy link
Contributor Author

malobre commented Mar 29, 2023

What I meant is that this lint suggests adding parenthesis while rome format removes them. The formatter needs to be updated to take this into consideration.

@ematipico
Copy link
Contributor

What I meant is that this lint suggests adding parenthesis while rome format removes them. The formatter needs to be updated to take this into consideration.

We are better off removing the code action for the time being.

@ematipico
Copy link
Contributor

ematipico commented Mar 29, 2023

@malobre We recently changed the way to make PRs. Particularly, now PRs need to add a changelog line: https://github.com/rome/tools/blob/main/CONTRIBUTING.md#changelog

@github-actions github-actions bot added A-CLI Area: CLI A-Tooling Area: our own build, development, and release tooling and removed A-Tooling Area: our own build, development, and release tooling labels Mar 29, 2023
@malobre
Copy link
Contributor Author

malobre commented Mar 29, 2023

I added a line to the changelog, commented out the action and reverted the changes to Playground.tsx.
Also messed up the rebase, but I think its good now.

Edit: Fixed the commit author, sorry for all the noise

@Conaclos
Copy link
Contributor

Fixed the commit author, sorry for all the noise

No problem :)

The CI is still failing. Could you set recommended to false? Hopefully, this will solve the issue. Sorry about this...

@Conaclos Conaclos merged commit 3a6da07 into rome:main Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-CLI Area: CLI A-Diagnostic Area: errors and diagnostics A-Linter Area: linter A-Project Area: project configuration and loading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 Implement ESLint's rule no-confusing-arrow
3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载