castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
423 stars 25 forks source link

Solargraph formatting doesn't follow the project's .rubocop.yml file #206

Closed ubmit closed 3 years ago

ubmit commented 3 years ago

Solargraph formatting doesn't follow the project's .rubocop.yml file.

Here is my .solargraph.yml file:

---
include:
  - "**/*.rb"
exclude:
  - spec/**/*
  - test/**/*
  - vendor/**/*
  - ".bundle/**/*"
require: []
domains: []
reporters:
  - rubocop
  - require_not_found
require_paths: []
plugins: []
max_files: 5000

And here is a part of settings.json:

{
 ...
  "solargraph.diagnostics": true,
  "solargraph.hover": true,
  "solargraph.formatting": true
}

Example file:

class Cat
  def meow
    'meow!'
  end
end

Even though .rubocop.yml contains the following cop:

Style/StringLiterals:
  EnforcedStyle: double_quotes

Solargraph won't format the 'meow!' to "meow"!. This is just an example, the same thing happens with others cops.

Also, somehow, if I do write the class like this:

class Cat
  def meow
    "meow!"
  end
end

The Solargraph formatter will "work" and replace the double quotes for single quotes.

dim commented 3 years ago

Same here!

jaredcwhite commented 3 years ago

Same here…and in fact another project where it had been working for quite some time is now not formatting anything at all after upgrading to latest Solargraph version. Just silently fails to do anything at all. 😕

jaredcwhite commented 3 years ago

For the time being, I've turned off SolarGraph's formatter and I'm using the File Watcher extension to run RuboCop after save. FWIW, here's my settings.json:

  "filewatcher.commands": [
    {
      "match": "\\.rb",
      "isAsync": true,
      "cmd": "/bin/zsh --login -c \"cd ${fileDirname}; rubocop --force-exclusion -a ${file}\"",
      "event": "onFileChange"
    }  
  ]
castwide commented 3 years ago

This problem should be fixed in gem version 0.40.3. If the problem persists, please reply in the related issue in the gem repo: https://github.com/castwide/solargraph/issues/406