tools icon indicating copy to clipboard operation
tools copied to clipboard

:bug: The linter/formatter does not correctly fix errors on save

Open MakingStuffs opened this issue 3 years ago • 3 comments

Environment information

CLI:
  Version:              10.0.1
  Color support:        true

Platform:
  CPU Architecture:     x86_64
  OS:                   macos

Environment:
  ROME_LOG_DIR:         unset
  NO_COLOR:             unset
  TERM:                 "xterm-256color"

Rome Configuration:
  Status:               loaded
  Formatter disabled:   false
  Linter disabled:      false

Workspace:
  Open Documents:       0

What happened?

When I saved the file the Rome linter/formatter did not correct the issue it flagged about wanting if statements to have a scope defined.

Minimum reproducible repo: https://github.com/MakingStuffs/rome-issue

Expected result

The Rome linter/formatter would automatically fix the trivial issue.

Code of Conduct

  • [X] I agree to follow Rome's Code of Conduct

MakingStuffs avatar Nov 12 '22 09:11 MakingStuffs

Thanks for the repro. That was super helpful.

The code doesn't get formatted any differently as it already matches the expected formatting. You can change the file content to

const something = false;
(() => {

	
	if (something) return;
})();

then hit save and you'll see that Rome reformats the file.

Rome only automatically applies code fixes where it is guaranteed that the semantic of the program won't change. The useBlockStatement code action isn't automatically applied because it may be unsafe to do so.

The rule testing for comparing against -0 is safe. You can try

const something = false;
(() => {
	if (a === -0) return;
})();

MichaReiser avatar Nov 13 '22 11:11 MichaReiser

@MichaReiser ah I did notice that there was the --apply-suggested flag which can be added if you run rome and that does apply the fixes also. Makes perfect sense (the reasoning behind the decision) do you think it would ever be possible to add option to allow users to automatically apply this kind of transform?

MakingStuffs avatar Nov 13 '22 15:11 MakingStuffs

@leops is exploring a way to allow users to specify the fixes they want to apply in their VS Code configuration. We'll see how it goes but this is something that we want users to be able to do.

MichaReiser avatar Nov 13 '22 17:11 MichaReiser

@MichaReiser Ok great I will close this as you are already working on the implementation and it isn't so much a bug :) thanks for your help mate, appreciate it :)

MakingStuffs avatar Nov 14 '22 07:11 MakingStuffs