Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code loss from transformation of symbol arrays #304

Closed
mpoisot opened this issue May 14, 2019 · 5 comments
Closed

Code loss from transformation of symbol arrays #304

mpoisot opened this issue May 14, 2019 · 5 comments

Comments

@mpoisot
Copy link

mpoisot commented May 14, 2019

Metadata

  • Ruby version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]
  • @prettier/plugin-ruby version: 0.12.2
    Installed in ~/.vscode/extensions/esbenp.prettier-vscode-1.9.0 as suggested here.

Input

Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'localhost'

    resource '*',
      headers: :any,
      methods: [:get, :post, :put, :patch, :delete, :options, :head]
  end
end

test1 = methods: [:get, :post, :put, :patch, :delete, :options, :head]

test2 = { methods: [:get, :post, :put, :patch, :delete, :options, :head] }

Current output

Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'localhost'

    resource '*',
             headers: :any, methods: %i[get post put patch delete options head]
  end
end

test1 = methods

Expected output

  1. I don't expect test1 and test2 lines to lose a bunch of code.
  2. I don't expect an array of symbols to change to %i[] format, and I can't find a way to turn it off. I see where the transformation happens, but I don't know the framework well enough to know how to disable it properly.
@kddnewton
Copy link
Member

kddnewton commented May 14, 2019

Hi @mpoisot -

  1. The code you gave is invalid ruby. There's a bug in that prettier isn't telling you it's invalid, but it is. It's on the line with assignment to test1.
  2. This is intentional. %i literal arrays are not a configuration option - they're meant to replace all arrays with just simple symbol literals.

@mpoisot
Copy link
Author

mpoisot commented May 15, 2019

Is there some background story behind converting to %i arrays? Is it superior somehow, or just a style consistency thing?

@kddnewton
Copy link
Member

kddnewton commented May 15, 2019 via email

@mpoisot
Copy link
Author

mpoisot commented May 15, 2019

Very helpful, thanks.

@kddnewton
Copy link
Member

No worries! Thanks for trying the plugin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants