Code Monkey home page Code Monkey logo

sublime_rubocop's Introduction

Note

Searching for a new maintainer. Please see #71 for more information.

Sublime RuboCop

A Sublime Text plugin that runs RuboCop on your Ruby files in the editor. It will mark issues right inside the view but it can also be called as a "compiler" from the ST menu.

The Plugin currently supports both ST2 and ST3, but the usage of ST3 is strongly recommended.

Installation

Prerequisites

Please make sure rubocop is installed:

gem install rubocop

Recommended

Install Sublime RuboCop via Package Control.

Manual

  1. Navigate to the Sublime Text Packages folder (You can find the location of the Packages folder here).

  2. Run the git clone command right inside the packages directory: git clone [email protected]:pderichs/sublime_rubocop.git "RuboCop"

  3. Restart Sublime Text.

What can it do for you?

By default, the plugin marks RuboCop issues right in the view when you open or save a Ruby file.

Additionally you can run RuboCop from the ST menu in many ways. For example you can perform a RuboCop check on all files of the current project to get a general overview. The issues will be listed inside the Sublime output window, so you can easily navigate to each of them.

You can also run the RuboCop auto correction for the current file from the Sublime Text menu.

ST2

Due to performance issues the plugin behaves a bit different under ST2. It will run RuboCop only when you save files. If you experience any performance issues when saving ruby files caused by that plugin, just disable the functionality in the settings (see mark_issues_in_view).

Environment

By default this plugin uses rvm to run RuboCop, but you can switch to rbenv or provide your own command line in the settings. The plugin uses default paths to run rvm or rbenv but you can customize these paths in the settings.

To use rbenv, for example, go to Preferences > Package Settings > Rubocop > Settings-User and add the following:

{
  "check_for_rvm": false,
  "check_for_rbenv": true,
  // In case you need a custom rbenv path
  "rbenv_path": "~/.rbenv/bin/rbenv",
}

ToDo

  • As reported by some users the plugin seems to be not working properly when using RVM with custom gemsets: issue #19.

Reporting issues

If you encounter an issue, please add some general information about your environment:

  • Operating System
  • Sublime Text version
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop?

Please also provide the steps to reproduce the issue.

Contributing

  1. Fork the repo.
  2. Create a branch from the current master branch.
  3. Start hacking.
  4. Create a pull request.
  5. Patience ☺️ .

Credits

Thanks go out to all contributors.

Thanks go out to Will Bond for his awesome sample and documentation about ST plugins, and thanks go out to the people implementing the sublime-text-2-ruby-tests Plugin - your source gave me some important hints for my implementation.

License

All of Sublime RuboCop is licensed under the MIT license.

Copyright (c) 2013 Patrick Derichs [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sublime_rubocop's People

Contributors

adarn avatar attenzione avatar ayonkhan avatar dnicolson avatar duderman avatar fwuensche avatar melonbreadvr avatar noahpatterson avatar pderichs avatar pocheptsov avatar shagabutdinov avatar vdh 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublime_rubocop's Issues

Add screenshot of plugin in action in readme

It not only makes readme more attractive (at least to me) but also shows what should be expected after installation.

I had some minor installation problem (I needed to modify settings for it to work) and one of things that I investigated was that by default it is subtle or hides output somewhere. With screenshoot in readme I would be able to discard this possibility immediately.

I may make PR fixing this issue.

Rubocop highlighting remains in buffer even after Sublime Text is restarted

This issue was first described in a StackOverflow question since I was not sure at the time what was causing it.

http://stackoverflow.com/questions/21639983/unexpected-highlighting-in-sublime-text-3

Since then, I think I've narrowed down the issue.

OS: OSX 10.9.1 Build 13B42
Sublime Text : Stable Channel, Build 3059
Rubocop Package: v2014.02.01.19.05.03

After disabling Rubocop, I did not close the file, instead just used Cmd + Q to quit. Then when relaunching Sublime, the previously opened file was reopened/still open. This screenshot is after a restart and shows the Rubocop line highlighting and the results of Sublime's "Package Control: Enable Packages" (showing the currently disabled packages).

Screenshot of the Issue

It appears that closing the file and restarting Sublime prevents seeing highlighting after the package is disabled.

rubocop_auto_correct seems incompatible with require (in .rubocop.yml)

Please add some general information about your environment:
  • Operating System - OSX Big Sur
  • Sublime Text version - 3 (Build 4107)
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop?
    rvm with gemsets & config looks like this:
{
  // Here you can provide your own command line
  // which is used to run rubocop. The path will be
  // replaced by the file or folder which needs
  // to be checked.
  //
  // If check_for_rvm or check_for_rbenv is enabled,
  // it will be prefixed with a call to rvm or rbenv.
  // If none of them are enabled, the command will be
  // executed without any additions.
  "rubocop_command": "",

  // If you want use RVM to run RuboCop, just
  // set this to true.
  //
  // Note: If check_for_rvm and check_for_rbenv are both enabled,
  // the plugin will use RVM.
  "check_for_rvm": true,

  // The path to RVM's rvm-auto-ruby binary
  "rvm_auto_ruby_path":  "~/.rvm/bin/rvm-auto-ruby",

  // If you want to use rbenv to run RuboCop, just
  // set this to true.
  //
  // Note: If check_for_rvm and check_for_rbenv are both enabled,
  // the plugin will use RVM.
  "check_for_rbenv": false,

  // The path to rbenv's binary
  "rbenv_path":  "~/.rbenv/bin/rbenv",

  // If you want issues to be marked automatically inside the view
  // set this to true.
  //
  // Attention ST2 users: Using that functionality consumes a bit
  // of time, so ST2 might be a bit unresponsive when saving. As soon
  // as you encounter performance problems during saving a ruby file you
  // should set this to false.
  "mark_issues_in_view": false,

  // Auto correct feature warning message
  "show_auto_correct_warning": false,

  // Optional general config file for rubocop.
  "rubocop_config_file": ""
}
Steps to reproduce:

Add this to your Sublime User Key Bindings (preferences)
{ "keys": ["super+shift+s"], "command": "rubocop_auto_correct" }

Works correctly if project .rubocop.yml file doesn't require any extensions; fails silently otherwise.
e.g. this .rubocop.yml file fails:

require:
  - rubocop-performance

but it works as soon as you comment out the value:

require:
#  - rubocop-performance

Does not work on Windows 2012 server

startup, version: 2221 windows x64 channel: stable
executable: /C/Program Files/Sublime Text 2/sublime_text.exe
working dir: /C/Windows/system32
packages path: /C/Users/Chef/AppData/Roaming/Sublime Text 2/Packages
settings path: /C/Users/Chef/AppData/Roaming/Sublime Text 2/Settings
PackageSetup not required
Py_GetProgramName(): sublime_text.exe
Py_GetExecPrefix(): C:\Program Files\Sublime Text 2
Py_GetProgramFullPath(): C:\Program Files\Sublime Text 2\sublime_text.exe
Py_GetPath(): C:\Program Files\Sublime Text 2\python26.zip;C:\Program Files\Sublime Text 2\DLLs;C:\Program Files\Sublime Text 2\lib;C:\Program Files\Sublime Text 2\lib\plat-win;C:\Program Files\Sublime Text 2\lib\lib-tk;C:\Program Files\Sublime Text 2
Py_GetPythonHome(): C:\Program Files\Sublime Text 2
catalogue loaded
found 7 files for base name Default.sublime-keymap
found 1 files for base name Default.sublime-mousemap
found 5 files for base name Main.sublime-menu
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\0_package_control_loader\00-package_control.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\0_package_control_loader\01-ssl-windows.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\0_package_control_loader\02-bz2.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\0_package_control_loader\02-select-windows.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Alignment\Alignment.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_core.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_logging.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_plugin.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_regions.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_remove.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_rules.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_search.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_swapping.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\bh_wrapping.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\BracketHighlighter\ure.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\CSS\css_completions.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\comment.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\copy_path.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\delete_word.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\detect_indentation.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\duplicate_line.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\echo.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\exec.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\fold.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\font.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\goto_line.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\indentation.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\kill_ring.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\mark.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\new_templates.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\open_file_settings.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\open_in_browser.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\paragraph.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\save_on_focus_lost.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\scroll.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\set_unsaved_view_name.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\side_bar.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\sort.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\swap_line.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\switch_file.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\transform.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\transpose.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Default\trim_trailing_white_space.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Diff\diff.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\HTML\encode_html_entities.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\HTML\html_completions.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Package Control\Package Control.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\Package Control\bootstrap.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\RuboCop\constants.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\RuboCop\file_tools.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\RuboCop\rubocop_command.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\RuboCop\rubocop_listener.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\RuboCop\rubocop_runner.py
Reloading plugin C:\Users\Chef\AppData\Roaming\Sublime Text 2\Packages\RuboCop\rubocop_runner_tests.py
plugin init time: 0.36579
loading bindings
loading pointer bindings
found 1 files for base name Default.sublime-theme
theme loaded
app ready
pre session restore time: 0.586555
startup cache, total files: 106 cache hits: 106
startup time: 0.693405 (package setup was not run)
loaded 908 snippets
Package Control: Skipping automatic upgrade, last run at 2015-04-23 18:54:54, next run at 2015-04-23 19:54:54 or after
Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
return self.run(edit)
File ".\rubocop_command.py", line 158, in run
File ".\rubocop_command.py", line 47, in run_rubocop_on
AttributeError: 'Window' object has no attribute 'project_data'
Writing file /C/Users/Chef/AppData/Roaming/Sublime Text 2/Packages/RuboCop/RuboCop.sublime-settings with encoding UTF-8
reloading /C/Users/Chef/AppData/Roaming/Sublime Text 2/Packages/RuboCop/RuboCop.sublime-settings
Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
return self.run(edit)
File ".\rubocop_command.py", line 158, in run
File ".\rubocop_command.py", line 47, in run_rubocop_on
AttributeError: 'Window' object has no attribute 'project_data'
Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
return self.run(edit)
File ".\rubocop_command.py", line 158, in run
File ".\rubocop_command.py", line 47, in run_rubocop_on
AttributeError: 'Window' object has no attribute 'project_data'
Writing file /C/Users/Chef/Desktop/test_sublime/test_recipe.rb with encoding UTF-8
Traceback (most recent call last):
File ".\sublime_plugin.py", line 190, in on_post_save
callback.module, "on_post_save", EVENT_TIMEOUT)
File ".\sublime_plugin.py", line 154, in run_timed_function
ret = f()
File ".\sublime_plugin.py", line 189, in
run_timed_function(lambda: callback.on_post_save(v),
File ".\rubocop_listener.py", line 119, in on_post_save
File ".\rubocop_listener.py", line 112, in do_in_file_check
File ".\rubocop_listener.py", line 105, in mark_issues
File ".\rubocop_listener.py", line 99, in run_rubocop
File ".\rubocop_runner.py", line 48, in run
File ".\subprocess.py", line 633, in init
File ".\subprocess.py", line 842, in _execute_child
TypeError: CreateProcess() argument 2 must be string without null bytes or None, not unicode

command not found for rubocop

Please add some general information about your environment:
  • Operating System -
    Max os x yosemite
  • Sublime Text version -
    Sublime Text 3 (build 3126)
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop?
    I am using rbenv but rubocop is in my path
I am using zsh shell
β–Ά echo $PATH
/Users/myname/.exenv/shims:/Users/myname/.exenv/bin:/usr/local/Cellar/erlang/18.3/bin:/opt/gradle-2.8/bin:/Users/myname/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myname/.fzf/bin

and rubocop is under /Users/myname/.rbenv/shims

Steps to reproduce:

my rubocop user setting file

{
	"check_for_rbenv": false,
	"check_for_rvm": false,
	"mark_issues_in_view": true,
	"rbenv_path": "~/.rbenv/shims/rubocop"
}

When I run RobuCop check current file I got this error

/bin/sh: rubocop: command not found
[Finished in 0.0s with exit code 127]
[cmd: rubocop /Users/myname/data/src/myproject/app/controllers/application_controller.rb]
[dir: /Users/myname/data/src/myproject]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

rubocop highlighting is not working on giving rubocop config file path

Hi,
I was trying to use my own custom gem of rubocop but package wasn't able to find the gem as bundler installs it in ~/.rvm/gems/ruby<version@gemset>/bundler/gems instead of ~/.rvm/gems/ruby<version@gemset>/gems, which i figured is marked as a bug in the repo.

So i thought of keeping default.yml of rubocop in my projects root directory and giving path to it in Rubocop.sublime-settings to rubocop_config_file variable. it works fine, shows errors in console but highlighting doesn't work.
Am i doing something wrong?

Your help is appreciated

Thanks

Not Working: Empty Console

I am running ST3 on OS X 10.9.2. The plugin is not working. All I see is an empty console with no output whatsoever.

ayonkhan ~ $ which rubocop
/usr/local/var/rbenv/shims/rubocop
ayonkhan ~ $ cat ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/RuboCop.sublime-settings
{
    "rubocop_command": "/usr/local/var/rbenv/shims/rubocop",
    "check_for_rvm": false,
    "check_for_rbenv": false
}

The plugin seems to use rvm even it is not installed ?

Hi Guys,
The plugin seems to look for rvm, even if I did not install it. I' using rbenv.
Here my SublimeText Plugin config :

{
  "rubocop_command": "/usr/local/bin/rubocop --auto-correct --format simple -D",
  "check_for_rvm": false,
  "rvm_auto_ruby_path":  "", 
  "check_for_rbenv": false,
  "rbenv_path":  "/usr/local/bin/rbenv",
  "mark_issues_in_view": true,
  "show_auto_correct_warning": true,
  "rubocop_config_file": ""
}

The plugin should not check for rvm as far it is set to falsein my config, should it ?
Here is the error I get when I am trying to execute rubocop in ST.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'rubocop' (>= 0) among 24 total gem(s) (Gem::LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /usr/local/bin/rubocop:22:in `<main>'
[Finished in 0.1s with exit code 1]
[cmd: /usr/local/bin/rubocop --auto-correct --format simple -D /Users/pgl/developpement/service-suivi-perso/objects/right.rb]
[dir: /Users/pgl/developpement/service-suivi-perso]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

Am I doing some thing wrong ??
Any Idea ?

ImportError: No module named 'RuboCop'

Please add some general information about your environment:
  • Operating System: Ubuntu 16.04.5
  • Sublime Text version: 3.1.1 Build 3176
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop?: Using rbenv.
Steps to reproduce:
  1. Added git repo using Package Control: Add Repository (because it is not listed otherwise)
  2. Added sublime_rubocop using Package Control
  3. Start Sublime
Error:
Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 116, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "/opt/sublime_text/sublime_plugin.py", line 1183, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "/home/david/.config/sublime-text-3/Installed Packages/sublime_rubocop.sublime-package/rubocop_command.py", line 7, in <module>
ImportError: No module named 'RuboCop'
reloading plugin sublime_rubocop.rubocop_listener
Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 116, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "/opt/sublime_text/sublime_plugin.py", line 1183, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "/home/david/.config/sublime-text-3/Installed Packages/sublime_rubocop.sublime-package/rubocop_listener.py", line 8, in <module>
ImportError: No module named 'RuboCop'

doesn't honor .rubocop.yml?

I may be doing it wrong, but I have a .rubocop.yml file locally that configures my project. Specifically it defines that Ruby 1.8 style hashes should be enforced. However, when I run the auto correct from within Sublime, they're converted to Ruby 1.9 style hashes.

Sublime rubocop with rbenv gemset ?

  • Mac OS Sierra
  • Sublime Text 3
  • rbenv, rbenv gemset

Error:

rbenv: rubocop: command not found
[Finished in 0.3s with exit code 127]
[cmd: /Users/bekicot/.rbenv/bin/rbenv exec rubocop /Users/bekicot/Projects/anak-pulau/osm_ppk_comparators.rb]
[dir: /Users/bekicot/Projects/anak-pulau]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

I think the possible fix is to add an option to set environment variables manually, just like what Seeing Is Believing have done.

here is the excerpt from the code:

# set up env vars
env                   = os.environ.copy()
env_variables         = settings.get("environment_variables")
environment_variables = ({} if env_variables is None else env_variables) # prob a better way to do this, if you know the pythons, feel free to do it for me :D

https://github.com/JoshCheek/sublime-text-2-and-3-seeing-is-believing/blob/master/seeing_is_believing.py#L25

So that user can manually specify environment variables like
image

Regression on Windows

Commit 5815543 removes lines added for Windows support in cb60ac3

Consequence: sublime_rubocop doesn't work nice in Windows again :-(

(Putting the 3 lines back in works on latest version)

Rubocop >= 0.36 AttributeError: 'NoneType' object has no attribute 'rfind'

  • Operating System - OSX El Capitan 10.11.3
  • Sublime Text version - Build 3114
  • I'm using rvm with the following config in sublime
{
  "rubocop_command": "",
  "check_for_rvm": true,
  "rvm_auto_ruby_path":  "~/.rvm/bin/rvm-auto-ruby",
  "check_for_rbenv": false,
  "rbenv_path":  "~/.rbenv/bin/rbenv",
  "mark_issues_in_view": true,
  "show_auto_correct_warning": true,
  "rubocop_config_file": ""
}
Steps to reproduce:
  1. From osx console gem install rubocop -v 0.35.0
  2. Edit a ruby file in sublime so there are obvious errors and notice the underline squiggles
  3. From osx console gem install rubocop -v 0.36.0
  4. Edit a ruby file in sublime so there are obvious errors and notice there are no squiggles.
  5. Open the sublime console (Cntrl+`) and notice the following message:
  6. Uninstall 0.36.0 and it starts working again
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 258, in on_load_async
    callback.on_load_async(v)
  File "rubocop_listener in /Users/zkloepping/Library/Application Support/Sublime Text 3/Installed Packages/RuboCop.sublime-package", line 132, in on_load_async
  File "rubocop_listener in /Users/zkloepping/Library/Application Support/Sublime Text 3/Installed Packages/RuboCop.sublime-package", line 119, in do_in_file_check
  File "rubocop_listener in /Users/zkloepping/Library/Application Support/Sublime Text 3/Installed Packages/RuboCop.sublime-package", line 113, in mark_issues
  File "rubocop_listener in /Users/zkloepping/Library/Application Support/Sublime Text 3/Installed Packages/RuboCop.sublime-package", line 58, in set_marks_by_results
  File "./python3.3/posixpath.py", line 142, in basename
AttributeError: 'NoneType' object has no attribute 'rfind'

Run on save not working on ST3?

I'm running this plugin under Sublime3. Manually running it works fine (ctrl+alt+c opens a console with the output), but when saving the file I get nothing. The following is my user config file:

{
  "rubocop_command": "rubocop {path}",
  "check_for_rvm": false,
  "check_for_rbenv": false,
  "mark_issues_in_view": true,
  "show_auto_correct_warning": true
}

Am I missing something?

auto check doesn't seem to do anything

Please add some general information about your environment:
  • Operating System - Linux (Arch)
  • Sublime Text version - 4126
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop? rbenv
Steps to reproduce:
  • modify a file and save multiple times
  • the linkt hints never change

They only change if I manually choose "Check current file" in which case it works fine. The console doesn't seem to have any logs or errors.

ST3 menu options are greyed out

Please add some general information about your environment:
  • System -
    OSX Sierra / ST3 / rbenv

  • Config

{
  "check_for_rvm": false,
  "check_for_rbenv": true,
  "rbenv_path": "/usr/local/bin/rbenv",
  "mark_issues_in_view": true,
  "show_auto_correct_warning": true
}

Versions

gem list | grep rubocop
rubocop (0.44.1)

/usr/local/bin/rbenv -v
rbenv 1.1.0
Steps to reproduce:

Just cloned the project, and created the User config in ST, and hard-restarted ST.
screen shot 2017-02-13 at 17 05 18

Auto_correct on save

Hey,

I'm not sure it's implemented but would it be possible to auto correct the current file when saving, just like other plugins do (CodeFormatter etc)? It works well by using the command palette ("Rubocop: auto correct current file") but I'd like to do it automatically when saving. I didn't find what to add in the settings file to do so, am I missing something?

Here's my settings file:

{
"mark_issues_in_view": false,
"show_auto_correct_warning": false
}

(I still use SublimeLinter for linting).

Cheers

No such file or directory -- rubocop (LoadError)

I'm running OSX 10.9.2, with RVM and rubocop installed, but I get the following output:

ruby: No such file or directory -- rubocop (LoadError)
[Finished in 0.4s with exit code 1]
[cmd: ['/Users/siyfion/.rvm/bin/rvm-auto-ruby -S rubocop  /Users/siyfion/Git/LabelLogicLive_PDF/']]
[dir: /Users/siyfion/Git/LabelLogicLive_PDF]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

Using rvm with custom gemset causes a rubocop LoadError message

I am running OSX 10.9.2, with rubocop and rvm. I use a custom gemset for the project but I only can check one file and not the whole project.

ruby: No such file or directory -- rubocop (LoadError)
[Finished in 0.4s with exit code 1]
[cmd: ['/Users/nemtes/.rvm/bin/rvm-auto-ruby -S rubocop  /Users/nemtes/Projekte/****']]
[dir: /Users/nemtes/Projekte]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

Wrong ruby executable taken, when using with rvm.

General Infos
  • Operating System: Linux (Debian jessie)
  • Sublime Text version: Build 3126
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop?:
    Using rvm, includin rvm-auto-ruby
Problem & Fix:

When using SublimeLinter-rubocop the Linter always use 'ruby' to execute rubocop, whereas SublimeLinter-RubyLinter has detected rvm-auto-ruby as executable.

# The problematic line is (in linter.rb):
class RuboCop(RubyLinter):
    ...
    def cmd(self):
        ...
        command = ['ruby', '-S', 'rubocop', '--format', 'emacs']  #Here ... ruby is hardcoded.

# better would be:
    command = self.executable_path + ['-S', 'rubocop', '--format', 'emacs']

With kind regards, Raimund

Marking issues in view causes Save to halt main thread

When using "mark_issues_in_view", a Save in Sublime can take 2 seconds on my 2013 mac using MRI, 10+ seconds using JRuby. Isn't there any way to speed this up or to at the least move this processing into the background so as to not lock up Sublime on every save?

working_dir broken in Windows.

Working directory was broken in Windows.
The quoted path 'c:\d\e' was getting passed to os.path.dirname, and the result was 'c:\d\e (trailing ' missed)

Sorry - I can't test on Linux at the moment so I've not done a pull request. The Windows patch is as below:

 if not file_list:
   # Single item to check.
  •  quoted_file_path = self.quote(path)
    
  •  working_dir = os.path.dirname(quoted_file_path)
    
  •  working_dir = os.path.dirname(path)
    
    else:

    Multiple files to check.

    working_dir = '.'

Windows: Mark issues in view is not working

The call to rubocop seems to fail on windows for the mark issues in view handling within rubocop_listener.py.

It seems, the popen command is not able to find the rubocop command: FileNotFoundError: [WinError 2].

Non .rb files are not auto-checked

If I understand this code, auto-checks only run on .rb files. If not too complicated, I suggest parsing rubocop.yml and extracting the AllCops: Include and AllCops: Exclude rules, (see https://github.com/bbatsov/rubocop/blob/master/config/default.yml#L9-29) and use that in the is_ruby_file method.

If that's too complicated, adding some other extension to that list might be a good fallback (.gemspec, Gemfile, .rake etc).

Sorry for not sending a PR, I don't know Python. Kudos for a very useful plugin.

ST3 Support

Is this package not supported in ST3? I've installed it via Package Control, but running Tools -> Rubocop -> Rubocop Check Single File results in this error:

ruby: No such file or directory -- rubocop (LoadError)
[Finished in 0.8s with exit code 1]
[cmd: ['/Users/dmoore/.rvm/bin/rvm-auto-ruby -S rubocop /Users/dmoore/projects/colddata/gradrocket/gradrocket-com/app/controllers/graduates/registrations_controller.rb']]
[dir: /Users/dmoore/projects/colddata/gradrocket/gradrocket-com/app/controllers/graduates]
[path: /Users/dmoore/.rvm/gems/ruby-2.0.0-p247/bin:/Users/dmoore/.rvm/gems/ruby-2.0.0-p247@global/bin:/Users/dmoore/.rvm/rubies/ruby-2.0.0-p247/bin:/Users/dmoore/.rvm/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:~/bin]

issues in views not displayed after Sublime 3 update

I'm running Sublime text 3 (build 3083) on OS X 10.10.2.

After the upgrade of Sublime text 3, I don't see the rubocop violations in Sublime. If i launch the sublime_rubocop in the terminal, it works great. They're just not displayed in the view...

Is it because of the latest version of sublime text 3?

rvm-auto-ruby: No such file or directory on Sublime Text 2

I've installed the Sublime Text 2 Rubocop plugin but it's failing to check any file. When I run "Rubocop: Check current file", I get the following error:

/bin/sh: /Users/jevon/.rvm/bin/rvm-auto-ruby: No such file or directory
[Finished in 0.0s with exit code 127]
  • Operating System: Mac OS X 10.10.5
  • Sublime Text version - 2.0.2, build 2221
  • I don't have rvm installed, I use rbenv.
  • Running rubocop --version on my shell works fine.
  • I can't find any way to set settings for Rubocop, the only settings I can set are "Settings", "SublimeLinter Settings" and "Package Control Settings".

Is there a way to configure this plugin with Sublime Text 2 to not use rvm? Or to configure the command that's run?

Weird output on Ubuntu

Hi, I've stumbled across this plugin and it works great! Although it works as expected, I get the following output:

screenshot from 2013-05-11 20 15 25

The weird bits are the ESC things and the fact that there is no line breaks or anything so the output is easier to read. Could you please fix it? I'm on Ubuntu 12.04. Also, have you though about putting your plugin on Sublime Package Control?

"Auto correct current file" does nothing

Please add some general information about your environment:
  • Operating System - macOS 12.4
  • Sublime Text version - 4126
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop? rvm
Steps to reproduce:

The command "Check current file" works ok, but "Auto correct current file" does nothing.

# .rubocop.yml
require:
  - rubocop-rails
  - rubocop-rspec
  - standard

inherit_gem:
  standard: config/base.yml

Running rubocop -a in the console works ok.

Option to disable gutter marking

  • Operating System: macOS Mojave 10.14.2
  • Sublime Text version: Sublime Text 3.1.1 Build 3176
  • I use rbenv

Can I disable the gutter marking of issues? I'd like to just have them marked by the squiggly line.

Keybindings overwrite sublime defaults

ctrl+shift+v is paste and intend in sublime and rubocop surprisingly overwrites this.
I can't seem to find a way to overwrite this in User keybindings.

Supporting other Ruby executables

Firstly, this is an awesome plugin πŸ‘

How hard would it be to enable people to set their ruby executable via a preference rather than hardcoding RVM?

e.g. rubocop_ruby_executable: "some/direct/executable/path/ruby"

I would be happy to have a bash but it might me take a while to get my head around the plugin and how to add preferences and I figure for you it's probably 10 seconds work.

Let me know either way :)

I have items Tools->RuboCop-> but this items are not active

Please add some general information about your environment:
  • Ubuntu 18.04
  • Sublime 3
  • I use rbenv
Steps to reproduce:

1)gem install rubocop
2).config/sublime-text-3
git clone [email protected]:pderichs/sublime_rubocop.git "RuboCop"
3){
"check_for_rvm": false,
"check_for_rbenv": true,
// In case you need a custom rbenv path
"rbenv_path": "~/.rbenv/bin/rbenv",
}
4) Restart sublime
5) I have items Tools->RuboCop->
2019-05-02_10-19

but this items are not active
RuboCop Check Single File
RuboCop Check Project
RuboCop Check File Folder

Using a Docker container doesn't work

Steps to reproduce:
  1. Install the latest version of this plugin and Docker
  2. Create a shell script which runs the Docker command to run Rubocop from a container:
#!/usr/bin/env bash

docker run --rm -it -v ${PWD}:/code registry.gitlab.com/pipeline-components/rubocop:latest $@
  1. Make it executable with chmod +x
  2. Configure this plugin with:
{
  "rubocop_command": "/usr/local/bin/rubocop",
  "check_for_rvm": false
}
  1. Check if it is working:
$ rubocop --version
1.52.1
$ rubocop my_ruby_file.rb
Inspecting 1 file
C

Offenses:

my_ruby_file.rb:45:3: C: Metrics/MethodLength: Method has too many lines. [12/10]
  def move_screenshot_html_to_public_folder_as(filename) ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1. Now open the Ruby file in Sublime Text

No Rubocop offenses reported in ST, and nothing is printed in the ST console, no idea what is going wrong.
I have updated my script in order to write into a file the command that is going to be executed, but no log file appears, like if the script is not ran at all.
BTW when I set a wrong path as rubocop_command, I do have an error in ST stating the given path doesn't exist.

Projects with relative paths do not work

I have sublime text project files with relative paths to folders, which look like:

{
    "folders":
    [
        {
            "path": "FolderName"
        },
...
    ]
}

When rubocop is run on these, I get an error about rubocop trying to use the relative folder path as its working directory:

Running / p a t h / t o / r u b o c o p   / p a t h / t o / r u b y / f i l e . r b
Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 533, in run_
    return self.run(**args)
  File "exec in /opt/sublime_text/Packages/Default.sublime-package", line 204, in run
FileNotFoundError: [Errno 2] No such file or directory: 'FolderName'

Editing the project to specify an absolute path to the folder seems to work fine, but I'd prefer to keep using paths relative to the project root.

Getting Naming/FileName has the wrong namespace error on autocorrect

Please add some general information about your environment:
  • Operating System - OS X El Captain 10.11.6
  • Sublime Text version - Sublime-text-3 build 3126
  • Rubocop gem version - 0.49.1
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop?
{
  "check_for_rvm": false,
  "check_for_rbenv": true,
  "show_auto_correct_warning": false,
  "mark_issues_in_view": false,
  "rbenv_path":  "/usr/local/bin/rbenv",
  "rubocop_config_file": ".rubocop.yml"
}
  • Details about your rubocop.yml config
---
AllCops:
  DisplayCopNames:    true
  DisplayStyleGuide:  true
  StyleGuideCopsOnly: true
  TargetRubyVersion:  2.1.5

Metrics/ParameterLists:
  Max: 5

Metrics/LineLength:
  Max: 120

Style/Alias:
  Enabled: false

Style/ClassAndModuleChildren:
  EnforcedStyle: compact

Style/FrozenStringLiteralComment:
  Enabled: false

Style/ModuleFunction:
  Enabled: false

Style/StringLiterals:
  EnforcedStyle: single_quotes

Style/StringLiteralsInInterpolation:
  EnforcedStyle: double_quotes

Naming/FileName:
  Enabled: false

Steps to reproduce:

Create .rubocop.yml file in your project root with settings as above. Try to autocorrect any ruby file with warnings via Command Palette.

In Sublime-Linter debug mode Im getting this error

~/projects/my_project/.rubocop.yml: Naming/FileName has the wrong namespace - should be Style 
SublimeLinter: No match for <_sre.SRE_Pattern object at 0x7fbc8059cb90>

Due to default.yml in rubocop github repo this is a correct setting. So command

rubocop --auto-correct path/to/file

works fine.

save_on_focus_lost not working when this package installed

Please add some general information about your environment:
  • Mac OSX Sierra 10.12.6 -
  • Dev Channel, Build 3175 -
  • I have made no changes to the configuration of the install -
Steps to reproduce:
  • install package
  • set save_on_focus_lost to true in sublime settings
  • alter a file in your project and navigate to another tab
    -- previously select tab should save

Contextual Rails errors doesn't work

The linter doesn't gives me a few rails warnings/errors.

An example would be to create a new Rails project, add the following to a .rubocop.yml:

AllCops:
  RunRailsCops: true

And then create an app/models/some_model.rb file with:

class SomeModel < ActiveModel
  validates_presence_of :some_attribute
end

Running it with ~/.rbenv/shims/rubocop --format emacs --config ~/Documents/RubocopLinterErrorExample/.rubocop.yml some_model.rb gives me:

~/Documents/RubocopLinterErrorExample/app/models/some_model.rb:1:1: C: Missing top-level class documentation comment.
~/Documents/RubocopLinterErrorExample/app/models/some_model.rb:2:3: C: Prefer the new style validations `validates :column, presence: value` over `validates_presence_of`.

but rubocop linter only shows the error related to missing top level class documentation, it doesn't show the second warning.

I've also tried passing '-R' in the arguments instead of using a .rubocop.yml, but the result was the same.

It seems 'exclude' doesn't work

Hello.

I've created .rubocop.yml :

AllCops:
  Exclude:
    - 'db/schema.rb'
    - 'bin/**/*'
    - 'config/initializers/devise.rb'
    - 'config/initializers/simple_form*'
    - 'db/migrate/*'

But in my migration I see error:

Method has too many lines.

How can I fix it ?

ruby

Please add some general information about your environment:
  • Operating System -
  • Sublime Text version -
  • Details about your config e.g. do you use rbenv, rvm or your_own_command to run rubocop?
Steps to reproduce:

SublimeText3 support

This plugin seems to work (as far as i can tell) in ST3 as well (which is currently in beta).

I was able to install it through packagecontrol just as i hoped for :)

So maybe just updating the documentation (first line of readme.md) is enough to solve this issue

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.