Repository: SublimeLinter/SublimeLinter-rubocop Branch: master Commit: 11622ffd0268 Files: 20 Total size: 9.0 KB Directory structure: gitextract_va1oy1nv/ ├── .flake8 ├── .github/ │ └── workflows/ │ └── python-app.yml ├── .gitignore ├── .python-version ├── LICENSE ├── README.md ├── linter.py ├── messages/ │ ├── 1.0.21.txt │ ├── 1.0.22.txt │ ├── 1.0.23.txt │ ├── 1.0.24.txt │ ├── 1.0.5.txt │ ├── 1.0.6.txt │ ├── 1.0.7.txt │ ├── 1.0.8.txt │ ├── 1.0.9.txt │ ├── 2.0.0.txt │ ├── 2.0.2.txt │ └── install.txt └── messages.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .flake8 ================================================ [flake8] max-line-length = 100 ignore= D, W503 ================================================ FILE: .github/workflows/python-app.yml ================================================ name: Python on: push: branches: [ master ] pull_request: branches: [ master ] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 with: python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --max-line-length=100 --show-source --statistics ================================================ FILE: .gitignore ================================================ .DS_Store ================================================ FILE: .python-version ================================================ 3.8 ================================================ FILE: LICENSE ================================================ 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. ================================================ FILE: README.md ================================================ SublimeLinter-rubocop ========================= [![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-rubocop.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-rubocop) 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. ## Installation SublimeLinter must be installed in order to use this plugin. Please use [Package Control](https://packagecontrol.io) to install the linter plugin. 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: 1. Install [Ruby](http://ruby-lang.org). 1. Install `rubocop` by typing the following in a terminal: ``` [sudo] gem install rubocop ``` 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. 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). ## Settings - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 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). To override the config file path, you would add this to the Sublime Linter User Settings: ```json { "linters": { "rubocop": { "args": ["--config", "path/to/config.yml"] } } } ``` ### Bundler 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: ```json { "linters": { "rubocop": { "use_bundle_exec": true } } } ``` ================================================ FILE: linter.py ================================================ import os from SublimeLinter.lint import Linter class RubyLinter(Linter): __abstract__ = True def context_sensitive_executable_path(self, cmd): # The default implementation will look for a user defined `executable` # setting. success, executable = super().context_sensitive_executable_path(cmd) if success: return True, executable gem_name = cmd[0] if isinstance(cmd, list) else cmd if self.settings.get('use_bundle_exec', False): return True, ['bundle', 'exec', gem_name] rvm = self.which('rvm-auto-ruby') if rvm: return True, [rvm, '-S', gem_name] return False, None class Rubocop(RubyLinter): defaults = { 'selector': 'source.ruby - text.html - text.haml' } regex = ( r'^.+?:(?P\d+):(?P\d+): ' r'(:?(?P[RCW])|(?P[EF])): ' r'(?P\[Correctable\] )?' r'((?P\w+/\w+): )?' r'(?P.+)$' ) word_re = r'^((@|@@|\$)?\w+[!?]?)' def cmd(self): """Build command, using STDIN if a file path can be determined.""" command = ['rubocop', '--format', 'emacs', '--display-cop-names'] path = self.filename if not path: # File is unsaved, and by default unsaved files use the default # rubocop config because they do not technically belong to a folder # that might contain a custom .rubocop.yml. This means the lint # results may not match the rules for the currently open project. # # If the current window has open folders then we can use the # first open folder as a best-guess for the current projects # root folder - we can then pretend that this unsaved file is # inside this root folder, and rubocop will pick up on any # config file if it does exist: folders = self.view.window().folders() if folders: path = os.path.join(folders[0], 'untitled.rb') if path: # With this path we can instead pass the file contents in via STDIN # and then tell rubocop to use this path (to search for config # files and to use for matching against configured paths - i.e. for # inheritance, inclusions and exclusions). # # The 'force-exclusion' overrides rubocop's behavior of ignoring # global excludes when the file path is explicitly provided: command += ['--force-exclusion', '--stdin', path] # Ensure the files contents are passed in via STDIN: self.tempfile_suffix = None else: self.tempfile_suffix = 'rb' command += ['${temp_file}'] return command ================================================ FILE: messages/1.0.21.txt ================================================ SublimeLinter-rubocop 1.0.21 ---------------------------- - Fix the version check string - bump the version to match what we're reporting to Package Control ================================================ FILE: messages/1.0.22.txt ================================================ SublimeLinter-rubocop 1.0.22 ---------------------------- - Support more ruby syntaxes ================================================ FILE: messages/1.0.23.txt ================================================ SublimeLinter-rubocop 1.0.23 ---------------------------- - Support more ruby syntaxes again ================================================ FILE: messages/1.0.24.txt ================================================ SublimeLinter-rubocop 1.0.24 ---------------------------- - Support Better RSpec syntax ================================================ FILE: messages/1.0.5.txt ================================================ SublimeLinter-rubocop 1.0.5 ---------------------------- - Added 'ruby on rails' to syntax. ================================================ FILE: messages/1.0.6.txt ================================================ SublimeLinter-rubocop 1.0.6 ---------------------------- - Added rspec syntax. ================================================ FILE: messages/1.0.7.txt ================================================ SublimeLinter-rubocop 1.0.7 ---------------------------- - Added erb ("HTML (Rails)") support. ================================================ FILE: messages/1.0.8.txt ================================================ SublimeLinter-rubocop 1.0.8 ---------------------------- - refactor, convention, and warning messages are highlighted as warnings, error and fatal messages as errors. ================================================ FILE: messages/1.0.9.txt ================================================ SublimeLinter-rubocop 1.0.9 ---------------------------- - Use RubyLinter to help find the ruby we should be running. Should work on wider variety of ruby setups. ================================================ FILE: messages/2.0.0.txt ================================================ SublimeLinter-rubocop 2.0.0 ---------------------------- - Support File location specific Rubocop rules thanks to Mark Haylock @mhaylock - Major version bump because it requires a much newer version of rubocop ================================================ FILE: messages/2.0.2.txt ================================================ SublimeLinter-rubocop 2.0.1 ---------------------------- - add new config option `use_bundle_exec` @smanolloff - 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 ================================================ FILE: messages/install.txt ================================================ SublimeLinter-rubocop ------------------------------- This linter plugin for SublimeLinter provides an interface to rubocop. Please read the installation instructions at: https://github.com/SublimeLinter/SublimeLinter-rubocop ================================================ FILE: messages.json ================================================ { "install": "messages/install.txt", "1.0.5": "messages/1.0.5.txt", "1.0.6": "messages/1.0.6.txt", "1.0.7": "messages/1.0.7.txt", "1.0.8": "messages/1.0.8.txt", "1.0.9": "messages/1.0.9.txt", "1.0.21": "messages/1.0.21.txt", "1.0.22": "messages/1.0.22.txt", "1.0.23": "messages/1.0.23.txt", "1.0.24": "messages/1.0.24.txt", "2.0.0": "messages/2.0.0.txt", "2.0.2": "messages/2.0.2.txt" }