castwide / vscode-solargraph

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

Solargraph don't recognices .rubocop project file rules #231

Open brunoprietog opened 2 years ago

brunoprietog commented 2 years ago

Hello! I have a Rails project with custom rules from Rubocop. However, it seems that solargraph does not respect those rules. The errors I get when checking rubocop from the terminal and from vs code are different, and I have conflicts when formatting the files. For example, even though I excluded the db/schema.rb file, when I open it, vs code still shows about 500 errors. I get the same thing in other files, and the formatter causes some defined rules to be broken.

These are my rubocop rules:

.rubocop.yml:

# Do not modify this file at all.
---
inherit_from:
  - .rubocop_raw.yml
  - .rubocop_todo.yml

inherit_mode:
  merge:
    - Exclude
    - ExcludedMethods

require:
  - rubocop-performance
  - rubocop-rails
  - rubocop-rspec

.rubocop_raw.yml:

# Do not modify this file at all.
---
inherit_mode:
  merge:
    - Exclude
    - ExcludedMethods

require:
  - rubocop-performance
  - rubocop-rails
  - rubocop-rspec

AllCops:
  NewCops: enable
  Exclude:
    - 'db/schema.rb'
    - 'db/migrate/*'

Lint/MissingSuper:
  Exclude:
    - 'app/services/**/*'
    - 'app/queries/**/*'

Metrics/AbcSize:
  Exclude:
    - 'db/migrate/*'

Metrics/BlockLength:
  Exclude:
    - 'config/routes.rb'
    - 'spec/factories/*'
  IgnoredMethods:
    - context
    - describe
    - define_type

Metrics/MethodLength:
  IgnoredMethods: []
  Exclude:
    - 'db/**/*'

RSpec/EmptyExampleGroup:
  Enabled: false

Style/AsciiComments:
  Enabled: false

Style/Documentation:
  Enabled: false

Style/EmptyCaseCondition:
  Enabled: false

Style/EmptyMethod:
  EnforcedStyle: expanded

.rubocop_todo.yml:

# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 61`
# on 2020-08-24 01:32:50 UTC using RuboCop version 0.89.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
  Exclude:
    - '**/*.gemspec'
    - 'config/routes.rb'
    - 'spec/factories/*'
    - 'config/environments/development.rb'

# Offense count: 1
Rails/OutputSafety:
  Exclude:
    - 'config/application.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
  Exclude:
    - 'config/initializers/devise.rb'

I ran solargraph config in the project directory, restarted solargraph in VS Code and everything remains the same. The reporters are configured in rubocop, as the default Solargrapf config file comes.

I have another project with simpler rules and the same thing happens to me.

.rubocop.yml:

require:
  - rubocop-performance
  - rubocop-rails
AllCops:
  NewCops: enable
  Exclude:
    - "app/controllers/graphql_controller.rb"
    - "app/lib/rodauth_app.rb"
    - "bin/*"
    - "test/**/*"
    - "config/**/*"
    - "db/schema.rb"
    - "db/migrate/*"
Metrics/AbcSize:
  Exclude:
    - "db/migrate/*"
Metrics/BlockLength:
  Exclude:
    - "config/routes.rb"
Metrics/MethodLength:
  IgnoredMethods: []
  Exclude:
    - "db/**/*"
Style/AsciiComments:
  Enabled: false
Style/Documentation:
  Enabled: false

What could be going on? Is it a bug or am I doing something wrong?

Thanks!

jaredcwhite commented 2 years ago

It doesn't seem like Solargraph's formatting is honoring Rubocop's Exclude list. Even if a file is excluded and bundle exec rubocop reports no errors, Solargraph still wants to run the file through Rubocop and format it on save, etc.

jhirn commented 2 years ago

There is a know issue on the vscode-ruby plugin where it doesn't honor excluides.

Be sure solargraph is doing the formatting and not vscode. I'm currently in a state where I though solargraphi was running but it was just VSCode's built in language server and using rubocop directly.

brunoprietog commented 2 years ago

Thanks! I uninstalled ruby and vscode-ruby because I hardly used it. I also removed all settings related to those 2 extensions in settings.json. Even so, it still doesn't work. Did you manage to fix it somehow?

jhirn commented 2 years ago

I did it was the combination of

"[ruby]": {
  "editor.defaultFormatter": "castwide.solargraph"
}
"ruby.useLanguageServer":  false
brunoprietog commented 2 years ago

Strange, it still doesn't work. Are you using solargraph with bundler?