├── .python-version ├── .gitignore ├── .flake8 ├── messages ├── 1.0.6.txt ├── 1.0.22.txt ├── 1.0.24.txt ├── 1.0.5.txt ├── 1.0.23.txt ├── 1.0.7.txt ├── 1.0.21.txt ├── 1.0.9.txt ├── 1.0.8.txt ├── 2.0.0.txt ├── install.txt └── 2.0.2.txt ├── messages.json ├── .github └── workflows │ └── python-app.yml ├── LICENSE ├── README.md └── linter.py /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 100 3 | ignore= 4 | D, 5 | W503 6 | -------------------------------------------------------------------------------- /messages/1.0.6.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.6 2 | ---------------------------- 3 | - Added rspec syntax. 4 | -------------------------------------------------------------------------------- /messages/1.0.22.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.22 2 | ---------------------------- 3 | - Support more ruby syntaxes 4 | -------------------------------------------------------------------------------- /messages/1.0.24.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.24 2 | ---------------------------- 3 | - Support Better RSpec syntax 4 | -------------------------------------------------------------------------------- /messages/1.0.5.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.5 2 | ---------------------------- 3 | - Added 'ruby on rails' to syntax. 4 | -------------------------------------------------------------------------------- /messages/1.0.23.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.23 2 | ---------------------------- 3 | - Support more ruby syntaxes again 4 | -------------------------------------------------------------------------------- /messages/1.0.7.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.7 2 | ---------------------------- 3 | - Added erb ("HTML (Rails)") support. 4 | -------------------------------------------------------------------------------- /messages/1.0.21.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.21 2 | ---------------------------- 3 | - Fix the version check string 4 | - bump the version to match what we're reporting to Package Control 5 | -------------------------------------------------------------------------------- /messages/1.0.9.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.9 2 | ---------------------------- 3 | - Use RubyLinter to help find the ruby we should be running. Should work on wider variety of ruby setups. 4 | -------------------------------------------------------------------------------- /messages/1.0.8.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 1.0.8 2 | ---------------------------- 3 | - refactor, convention, and warning messages are highlighted 4 | as warnings, error and fatal messages as errors. 5 | -------------------------------------------------------------------------------- /messages/2.0.0.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 2.0.0 2 | ---------------------------- 3 | - Support File location specific Rubocop rules thanks to Mark Haylock @mhaylock 4 | - Major version bump because it requires a much newer version of rubocop 5 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 2 | ------------------------------- 3 | This linter plugin for SublimeLinter provides an interface to rubocop. 4 | 5 | Please read the installation instructions at: 6 | 7 | https://github.com/SublimeLinter/SublimeLinter-rubocop 8 | 9 | -------------------------------------------------------------------------------- /messages/2.0.2.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 2.0.1 2 | ---------------------------- 3 | - add new config option `use_bundle_exec` @smanolloff 4 | - I'm looking for a new maintainer. The maintenance cost has been pretty low but I'm no longer using sublime or ruby in a day to day capacity. If you're interested speak up! https://github.com/SublimeLinter/SublimeLinter-rubocop/issues/38 5 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt", 3 | "1.0.5": "messages/1.0.5.txt", 4 | "1.0.6": "messages/1.0.6.txt", 5 | "1.0.7": "messages/1.0.7.txt", 6 | "1.0.8": "messages/1.0.8.txt", 7 | "1.0.9": "messages/1.0.9.txt", 8 | "1.0.21": "messages/1.0.21.txt", 9 | "1.0.22": "messages/1.0.22.txt", 10 | "1.0.23": "messages/1.0.23.txt", 11 | "1.0.24": "messages/1.0.24.txt", 12 | "2.0.0": "messages/2.0.0.txt", 13 | "2.0.2": "messages/2.0.2.txt" 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/python-app.yml: -------------------------------------------------------------------------------- 1 | name: Python 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | lint: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Set up Python 3.8 15 | uses: actions/setup-python@v2 16 | with: 17 | python-version: 3.8 18 | - name: Install dependencies 19 | run: | 20 | python -m pip install --upgrade pip 21 | pip install flake8 22 | - name: Lint with flake8 23 | run: | 24 | # stop the build if there are Python syntax errors or undefined names 25 | flake8 . --count --max-line-length=100 --show-source --statistics 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLinter-rubocop 2 | ========================= 3 | 4 | [![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-rubocop.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-rubocop) 5 | 6 | This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [rubocop](https://github.com/bbatsov/rubocop). It will be used with files that have the `ruby`, `ruby on rails`, `rspec`, `betterruby`, `better rspec`, `ruby experimental` or `cucumber steps` syntaxes. 7 | 8 | ## Installation 9 | SublimeLinter must be installed in order to use this plugin. 10 | 11 | Please use [Package Control](https://packagecontrol.io) to install the linter plugin. 12 | 13 | Before using this plugin, you must ensure that `rubocop` (0.34.0 or later) is installed on your system. To install `rubocop`, do the following: 14 | 15 | 1. Install [Ruby](http://ruby-lang.org). 16 | 17 | 1. Install `rubocop` by typing the following in a terminal: 18 | ``` 19 | [sudo] gem install rubocop 20 | ``` 21 | 22 | 1. If you are using `rvm` or `rbenv`, ensure that they are loaded in your shell’s correct startup file. See [here](http://sublimelinter.com/en/latest/troubleshooting.html#adjusting-shell-startup-files) for more information. 23 | 24 | In order for `rubocop` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. The docs cover [troubleshooting PATH configuration](http://sublimelinter.com/en/latest/troubleshooting.html#finding-a-linter-executable). 25 | 26 | ## Settings 27 | - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html 28 | - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 29 | 30 | You can configure rubocop exactly the way you would from the command line, using `.rubocop.yml` configuration files. For more information, see the [rubocop documentation](https://github.com/bbatsov/rubocop#configuration). 31 | 32 | To override the config file path, you would add this to the Sublime Linter User Settings: 33 | 34 | ```json 35 | { 36 | "linters": { 37 | "rubocop": { 38 | "args": ["--config", "path/to/config.yml"] 39 | } 40 | } 41 | } 42 | ``` 43 | 44 | ### Bundler 45 | If you are using Bundler and would like to use the locked rubocop version (which will also allow you to use `inherit_gem` in `rubocop.yml`, in case you are inheriting from another gem in the project), you must set `use_bundle_exec` to true: 46 | 47 | ```json 48 | { 49 | "linters": { 50 | "rubocop": { 51 | "use_bundle_exec": true 52 | } 53 | } 54 | } 55 | ``` 56 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | import os 2 | from SublimeLinter.lint import Linter 3 | 4 | 5 | class RubyLinter(Linter): 6 | __abstract__ = True 7 | 8 | def context_sensitive_executable_path(self, cmd): 9 | # The default implementation will look for a user defined `executable` 10 | # setting. 11 | success, executable = super().context_sensitive_executable_path(cmd) 12 | if success: 13 | return True, executable 14 | 15 | gem_name = cmd[0] if isinstance(cmd, list) else cmd 16 | 17 | if self.settings.get('use_bundle_exec', False): 18 | return True, ['bundle', 'exec', gem_name] 19 | 20 | rvm = self.which('rvm-auto-ruby') 21 | if rvm: 22 | return True, [rvm, '-S', gem_name] 23 | 24 | return False, None 25 | 26 | 27 | class Rubocop(RubyLinter): 28 | defaults = { 29 | 'selector': 'source.ruby - text.html - text.haml' 30 | } 31 | regex = ( 32 | r'^.+?:(?P\d+):(?P\d+): ' 33 | r'(:?(?P[RCW])|(?P[EF])): ' 34 | r'(?P\[Correctable\] )?' 35 | r'((?P\w+/\w+): )?' 36 | r'(?P.+)$' 37 | ) 38 | word_re = r'^((@|@@|\$)?\w+[!?]?)' 39 | 40 | def cmd(self): 41 | """Build command, using STDIN if a file path can be determined.""" 42 | 43 | command = ['rubocop', '--format', 'emacs', '--display-cop-names'] 44 | 45 | path = self.filename 46 | if not path: 47 | # File is unsaved, and by default unsaved files use the default 48 | # rubocop config because they do not technically belong to a folder 49 | # that might contain a custom .rubocop.yml. This means the lint 50 | # results may not match the rules for the currently open project. 51 | # 52 | # If the current window has open folders then we can use the 53 | # first open folder as a best-guess for the current projects 54 | # root folder - we can then pretend that this unsaved file is 55 | # inside this root folder, and rubocop will pick up on any 56 | # config file if it does exist: 57 | folders = self.view.window().folders() 58 | if folders: 59 | path = os.path.join(folders[0], 'untitled.rb') 60 | 61 | if path: 62 | # With this path we can instead pass the file contents in via STDIN 63 | # and then tell rubocop to use this path (to search for config 64 | # files and to use for matching against configured paths - i.e. for 65 | # inheritance, inclusions and exclusions). 66 | # 67 | # The 'force-exclusion' overrides rubocop's behavior of ignoring 68 | # global excludes when the file path is explicitly provided: 69 | command += ['--force-exclusion', '--stdin', path] 70 | # Ensure the files contents are passed in via STDIN: 71 | self.tempfile_suffix = None 72 | else: 73 | self.tempfile_suffix = 'rb' 74 | command += ['${temp_file}'] 75 | 76 | return command 77 | --------------------------------------------------------------------------------