Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@prettier/plugin-ruby and rubocop incompatibility example

prettier/plugin-ruby#1460

See this sample code in app.rb

expect do
  foo
end.to change(Bar, :baz, 1)

rubocop is happy with this code:

$ bundle exec rubocop
Inspecting 2 files
..

2 files inspected, no offenses detected

However, prettier is not:

$ node_modules/.bin/prettier --check .
Checking formatting...
[warn] app.rb
[warn] Code style issues found in the above file. Run Prettier with --write to fix.

When I format it with prettier (node_modules/.bin/prettier --write .), the code changes to:

expect do foo end.to change(Bar, :baz, 1)

Now prettier is happy:

$ node_modules/.bin/prettier --check .
Checking formatting...
All matched files use Prettier code style!

But rubocop is not:

$ bundle exec rubocop
Inspecting 2 files
.C

Offenses:

app.rb:1:1: C: [Correctable] Style/SingleLineDoEndBlock: Prefer multiline do...end block.
expect do foo end.to change(Bar, :baz, 1)
^^^^^^^^^^^^^^^^^
app.rb:1:8: C: [Correctable] Style/BlockDelimiters: Prefer {...} over do...end for single-line blocks.
expect do foo end.to change(Bar, :baz, 1)
       ^^

2 files inspected, 2 offenses detected, 2 offenses autocorrectable

But... if I correct those rubocop issues, I end up with the code I started with, and prettier is unhappy again. I'm in an infinite loop. The tools are clashing with each other.

If I instead write the code like this, both tools are happy

expect { foo }.to change(Bar, :baz, 1)

If prettier were to autoformat the original code into this code, both tools would be happy. I can do it manually in the meantime but it would be cool if it Just Worked automatically.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages