Giter Club home page Giter Club logo

vscode-rubocop's Introduction

RuboCop Logo


Ruby Style Guide Gem Version Actions Status Test Coverage Maintainability Discord

Role models are important.
-- Officer Alex J. Murphy / RoboCop

RuboCop is a Ruby static code analyzer (a.k.a. linter) and code formatter. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide. Apart from reporting the problems discovered in your code, RuboCop can also automatically fix many of them for you.

RuboCop is extremely flexible and most aspects of its behavior can be tweaked via various configuration options.


Patreon OpenCollective OpenCollective Tidelift

Working on RuboCop is often fun, but it also requires a great deal of time and energy.

Please consider financially supporting its ongoing development.

Installation

RuboCop's installation is pretty standard:

$ gem install rubocop

If you'd rather install RuboCop using bundler, add a line for it in your Gemfile (but set the require option to false, as it is a standalone tool):

gem 'rubocop', require: false

RuboCop is stable between minor versions, both in terms of API and cop configuration. We aim to ease the maintenance of RuboCop extensions and the upgrades between RuboCop releases. All big changes are reserved for major releases. To prevent an unwanted RuboCop update you might want to use a conservative version lock in your Gemfile:

gem 'rubocop', '~> 1.65', require: false

See our versioning policy for further details.

Quickstart

Just type rubocop in a Ruby project's folder and watch the magic happen.

$ cd my/cool/ruby/project
$ rubocop

You can also use this magic in your favorite editor with RuboCop's built-in LSP server.

Documentation

You can read a lot more about RuboCop in its official docs.

Compatibility

RuboCop officially supports the following runtime Ruby implementations:

  • MRI 2.7+
  • JRuby 9.4+

Targets Ruby 2.0+ code analysis.

See the compatibility documentation for further details.

Readme Badge

If you use RuboCop in your project, you can include one of these badges in your readme to let people know that your code is written following the community Ruby Style Guide.

Ruby Style Guide

Ruby Style Guide

Here are the Markdown snippets for the two badges:

[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)

[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)

Team

Here's a list of RuboCop's core developers:

See the team page for more details.

Logo

RuboCop's logo was created by Dimiter Petrov. You can find the logo in various formats here.

The logo is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Contributors

Here's a list of all the people who have contributed to the development of RuboCop.

I'm extremely grateful to each and every one of them!

If you'd like to contribute to RuboCop, please take the time to go through our short contribution guidelines.

Converting more of the Ruby Style Guide into RuboCop cops is our top priority right now. Writing a new cop is a great way to dive into RuboCop!

Of course, bug reports and suggestions for improvements are always welcome. GitHub pull requests are even better! :-)

Funding

While RuboCop is free software and will always be, the project would benefit immensely from some funding. Raising a monthly budget of a couple of thousand dollars would make it possible to pay people to work on certain complex features, fund other development related stuff (e.g. hardware, conference trips) and so on. Raising a monthly budget of over $5000 would open the possibility of someone working full-time on the project which would speed up the pace of development significantly.

We welcome both individual and corporate sponsors! We also offer a wide array of funding channels to account for your preferences (although currently Open Collective is our preferred funding platform).

If you're working in a company that's making significant use of RuboCop we'd appreciate it if you suggest to your company to become a RuboCop sponsor.

You can support the development of RuboCop via GitHub Sponsors, Patreon, PayPal, Open Collective and Tidelift .

Note: If doing a sponsorship in the form of donation is problematic for your company from an accounting standpoint, we'd recommend the use of Tidelift, where you can get a support-like subscription instead.

Open Collective Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Open Collective Sponsors

Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]

Changelog

RuboCop's changelog is available here.

Copyright

Copyright (c) 2012-2024 Bozhidar Batsov. See LICENSE.txt for further details.

vscode-rubocop's People

Contributors

dependabot[bot] avatar koic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jverce dajabe

vscode-rubocop's Issues

Does not auto indent on save

I would expect the problem pictured below to be handled automatically on save. There is a "quick fix" for indentation and I can manually trigger one by one, but it does not do the formatting on save.

Screenshot 2023-11-15 at 11 47 04

It doesn't work with Rubocop 1.57.1 version

When I try to use it extension. I return this error in vscode.

[client] Disabling because the extension does not support this version of the rubocop gem.
[client]   Version reported by `/home/dbachinin/.rvm/gems/ruby-2.7.6/bin/rubocop -v`: Found no changes, using resolution from the lockfile
1.57.1 (>= 1.53.0 required)

[client] No Gemfile found in the current workspace

Getting this error on opening VS Code.

I think the problem is in the project structure. It is a git repo with several folders. The backend with the rails app is one of several folders.

.git repo
├── rails-app
          ├── app
          ├── ...
           .rubocop.yml
           ...
           Gemfile
           Gemfile.lock
           ...
├── another-folder
├── one-more-folder
.gitignore
README.md
...

The Gemfile is in the rails-app folder. I need to have open full git repo with all folders simultaneously.
It would be great to have a setting to pass the Gemfile path for the project/workspace

Full log:

[client] No Gemfile found in the current workspace
[client] Starting language server: rubocop --lsp
[server] RuboCop 1.54.1 language server initialized, PID 40280
cannot load such file -- rubocop-rspec
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:46:in `rescue in rescue in load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:39:in `rescue in load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:32:in `load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/feature_loader.rb:21:in `load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:14:in `block (2 levels) in resolve_requires'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:13:in `each'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:13:in `block in resolve_requires'
<internal:kernel>:90:in `tap'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader_resolver.rb:12:in `resolve_requires'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader.rb:53:in `load_file'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_loader.rb:112:in `configuration_from_file'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_store.rb:68:in `for_dir'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/config_store.rb:58:in `for'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:190:in `block in process_explicit_path'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:189:in `reject'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:189:in `process_explicit_path'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:40:in `block in find'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:36:in `each'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:36:in `find'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/runner.rb:111:in `find_target_files'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/runner.rb:68:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:78:in `run_rubocop'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:51:in `block in offenses'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/server/helper.rb:26:in `redirect'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:70:in `redirect_stdout'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/runtime.rb:51:in `offenses'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:53:in `offenses'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/routes.rb:195:in `diagnostic'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/routes.rb:84:in `block in <class:Routes>'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:34:in `call'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:34:in `block in start'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/lsp/server.rb:30:in `start'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli/command/lsp.rb:14:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:118:in `run_command'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:184:in `handle_exiting_options'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:158:in `act_on_options'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:47:in `block in run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/lib/rubocop/cli.rb:43:in `run'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/exe/rubocop:19:in `block in <top (required)>'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rubocop-1.54.1/exe/rubocop:19:in `<top (required)>'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/bin/rubocop:25:in `load'
/Users/zalyotov/.asdf/installs/ruby/3.1.4/bin/rubocop:25:in `<main>'
[Error - 16:24:35] Client RuboCop: connection to server is erroring. Shutting down server.
[Error - 16:24:35] Connection to server got closed. Server will not be restarted.
[Error - 16:24:35] Stopping server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 16:24:35] Stopping server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 

[Feature Request] Add Enable/Disable Rubocop command

Hello! Thank you for the extension, it's quite useful.

Lately I've wanted to have a new command to disable/enable the whole extension (I attach an example of another VS Extension).

image

This is because sometimes I'm editing a huge file (with several rubocop offenses) and as I have automatic lint&fix after saving, it takes a long time to do the whole file. And maybe I'm debugging something and I don't need that at the moment. So I have to go to extensions, disable it...

If only I had a command to disable everything...

I can make a PR! But I'd need guidelines on how to do it :)

Thanks!

VSCode trying to find find rubocop in the SYSTEM ruby

Hi. Having an issue to get the plugin to start.

[client] Command `bundle list --name-only` failed with exit code 1 (exec options: {"cwd":"/Users/frexuz/www/some-path"})
[client] stderr:
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.4.22) required by your /Users/frexuz/www//Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.4.22`
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
	from /usr/bin/bundle:23:in `<main>'
[client] Failed to invoke Bundler in the current workspace. After resolving the issue, run the command `RuboCop: Start Language Server`

I use rbenv and zsh
image
image
and the ruby lsp is starting fine:
image

I have also tried setting it directly
image

Not sure which settings im missing 🤔

Changing the configuration file makes the extension angry

I was switching from a non-official extension to this one, and at the same time I was adding a config file to my project. In doing so, I got a notification saying that the rubocop server crashed 5 times, and this was the output:

[client] Starting language server: bundle exec rubocop --lsp
[server] RuboCop 1.59.0 language server initialized, PID 76175
[server] Configuration file changed; restart required
[Info  - 12:17:50 PM] Connection to server got closed. Server will restart.
[server] RuboCop 1.59.0 language server initialized, PID 77028
[server] Configuration file changed; restart required
[Info  - 12:17:54 PM] Connection to server got closed. Server will restart.
[server] RuboCop 1.59.0 language server initialized, PID 78104
[server] Configuration file changed; restart required
[Info  - 12:18:00 PM] Connection to server got closed. Server will restart.
[server] RuboCop 1.59.0 language server initialized, PID 78208
[server] Configuration file changed; restart required
[Info  - 12:18:07 PM] Connection to server got closed. Server will restart.
[server] RuboCop 1.59.0 language server initialized, PID 79328
[server] Configuration file changed; restart required
[Error - 12:18:10 PM] The RuboCop server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

This seems like an "expected" case that VSCode is treating as "unexpected", but figured it's worth calling out in case y'all can do something to make VSCode happier.

rubocop.yml config not registered

Hi,

It seems like the rubocop.yml file is not considered when using this extension.

Any ideas? Do I need to configure it somehow specifically?

VS Code Version: 1.83.1
Extension Version: v0.6.0

MethodLength and ClassLength indicate the whole method

When a method/class is indicated as too long, the entire method/class gets underlined with a squiggle. This can be problematic because

  • It obfuscates other linting issues
  • When working in legacy code with many long methods/classes it can make parsing/referencing their behavior more difficult.
Screenshot 2023-11-16 at 3 28 22 PM

My suggestion is to have only the definition of the method/class be underlined, so that the rest of the content
is readable

Minimal required rubocop version

Hi!
First of all, thanks for finally making official vscode extension for rubocop 🙂
I hope it will work the best of all other extensions 🙂


Question: Could I weak the minimum required version? E.g. to 1.41.0 (this is just a version I use in my work project)

const requiredGemVersion = '>= 1.53.0';

Highlighting does not respect my .rubocop.yml file

Hello,

As the title said, the extension highlights the problems present in my Gemfile, even after i added an exclusion in the .rubocop.yml file, which is present at the root of my project folder. But when I execute the bundle exec rubocop command in my project, the exclusion are made correctly and the warning of those file are not shown in the report. I cannot determine if I missed some configuration when installing and managing the extension or if this behavior is not intended.

Here is an example of the issue:
Screenshot from 2024-03-20 13-30-26

And here is some of detailed information of my configuration:

Thanks for reading my problem and I am attent to respond any question or details that may be needed to clarify the situation

Show linting violations even if suppressed via .rubocop_todo.yml

I have previously been using the rebornix.Ruby extension and one difference I'm finding with rubocop.vscode-rubocop is I'm not finding a way to see linting errors in the editor as if our .rubocop_todo.yml didn't exist. Is there a way to show violations and autofix on save even if they are suppressed via .rubocop_todo.yml? This helps with gradual migration of a legacy code base. Thank you.

[Feature Request] Publish extension to open-vsx.org

Due to Microsoft's ToS, VSCodium and other VSCode-based IDEs (Theia etc) cannot use the Microsoft extensions marketplace.
As open-vsx.org is the default marketplace in Codium, would it be possible to publish Rubocop there?

(Related guide)
As a sidenote, rubocop-revived was published to open-vsx, but its repository was archived yesterday, so it would be nice to have an up-to-date/maintained rubocop extension in the registry still.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.