Giter Site home page Giter Site logo

sublimelinter-contrib-standardrb's Introduction

SublimeLinter-contrib-standardrb

This linter plugin for SublimeLinter provides an interface to StandardRB. It will be used with files that have the ruby, ruby on rails, rspec, betterruby, better rspec, ruby experimental or cucumber steps syntaxes.

Installation

You need to have SublimeLinter and StandardRB installed in order to use this plugin.

If you you already have those requirements met, great! πŸŽ‰. You can use Package Control to install the SublimeLinter-contrib-standardrb plugin.

If you haven't installed SublimeLinter and StandardRB, see below:

Install SublimeLinter

Refer to the SublimeLinter Docs for installation instructions.

Install StandardRB

Before using this plugin, you must ensure that standard is installed on your system. To install standard, do the following:

  1. Install Ruby.

  2. Install standard by typing the following in a terminal:

    ```
    gem install standard
    ```
    
  3. If you are using rvm or rbenv, ensure that they are loaded in your shell’s correct startup file. See here for more information.

PATH Configuration

In order for standard to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. The SublimeLinter docs cover troubleshooting PATH configuration.

Settings

To understand SublimeLinter settings in general, check out:

Bundler

If you are using Bundler and would like to use the locked version of StandardRB, you will need to set use_bundle_exec to true:

{
    "settings": {
        "SublimeLinter.linters.standardrb.use_bundle_exec": true
    }
}

Playing Nice With SublimeLinter-Rubocop

Assuming you also have the SublimeLinter-Rubocop plugin enabled...

It's likely that you'll want to use Standard as your linter for some projects and Rubocop directly for others. Since Standard is a wrapper on top of Rubocop and both linters will lint the same files, having both enabled can give you some conflicting results (such as allowing neither single nor double quoted string literals). There are a couple of ways to prevent conflicts between the two linters.

Option 1: Manually Toggle Between Linters

You can use "Disable Package" / "Enable Package" from the command palette to turn linter plugins on or off. You can also use your settings file to enable or disable linter plugins globally. Both of these are pretty terrible user experiences and you really should use one of the other options below.

Option 2: Using .sublime-project Files

One option for dealing with linter conflicts is to disable one linter in your global settings file and then override the setting on a per-project basis. For example, assuming you want to enable StandardRB globally and use Rubocop only on specific projects, you would first globally disable the rubocop linter in your Preferences.sublime-settings file:

{
    "SublimeLinter.linters.rubocop.disable": true
}

This will prevent SiblimeLinter from using the Rubocop linter while continuing to allow the SublimeRB linter.

Then, for any project you'd like to lint with Rubocop instead of StandardRB, you can then add the following to your *.sublime-project settings:

{
    "settings": {
        "SublimeLinter.linters.rubocop.disable": false,
        "SublimeLinter.linters.standardrb.disable": true
    }
}

The above settings will disable the StandardRB linter and enable Rubocop instead.

This approach works well if you are a heavy user of .sublime-project files. The drawback to this approach is that it may not select the linter you want if the project is opened without using the *.sublime-project file (e.g. executing subl ~/path/to/ruby/project from a terminal prompt).

Option 3: Using The prefer_standard setting to check for config files

(πŸ‘† - Hint: This is probably the one you want.)

A more intelligent (and opinionated) option is to use the prefer_standard option. Enabling this option will cause the StanrdardRB linter plugin to selectively enable either the StandardRB or Rubocop linter based on the presence of a corresponding linter config file. The project directory (first folder in the project) and each of it's parent directories are searched first for a .standard.yml file, and then for a .rubocop.yml file. The corresponding linter will be activated for the first config file found. If no config file is found, StandardRB will be used.

To use the prefer_standard option, you'll need to add the following to your global preferences:

{
    "settings": {
        "SublimeLinter.linters.rubocop.disable": null,
        "SublimeLinter.linters.standardrb.disable": null,
        "SublimeLinter.linters.standardrb.prefer_standard": true,
    }
}

Note that both linters have their disable setting set to null, not false. true and false are explicit decisions which prefer_standard will gladly honor. null means you're OK with making no decision and letting prefer_standard decide for you.

Help Us Improve

If you run into problems, please open an Issue or a Pull Request.

Code of Conduct

This project follows Test Double's code of conduct for all community interactions, including (but not limited to) one-on-one communications, public posts/comments, code reviews, pull requests, and GitHub issues. If violations occur, Test Double will take any action they deem appropriate for the infraction, up to and including blocking a user from the organization's repositories.


This plugin is largely based on SublimeLinter-Rubocop

sublimelinter-contrib-standardrb's People

Contributors

cpruitt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gobijan

sublimelinter-contrib-standardrb's Issues

prefer_standard no longer working

I'm having trouble getting the prefer_standard option working, as documented here. I suspect something may have changed in recent versions of SublimeLinter.

The readme says to add the provided settings to the "global preferences." I wasn't sure exactly where that was supposed to be, but I think it's talking about the SublimeLinter user settings (~/Library/Application Support/Sublime Text/Packages/User/SublimeLinter.sublime-settings)

However this file expects a different format than what the readme provies (maybe this has changed in the last 4 years). So I translated the settings into this format:

// SublimeLinter Settings - User
{
  "linters": {
    "rubocop": {
      "disable": null
    },
    "standardrb": {
      "disable": null,
      "prefer_standard": true
    }
  }
}

However this settings file has validation that runs on it, and when I use "disable": null I receive this error message:

Invalid settings in 'Packages/User/SublimeLinter.sublime-settings':
'linters' > 'rubocop' > 'disable': None is not of type 'boolean'

I tried using "disable": true and "disable": false, but neither of them makes this work, instead it just follows what the disable settings dictate. I also tried omitting disable for both and doing only prefer_standard and that's the same as having both active.

Automatically switch between StandardRB and Rubocop linters

The StandardRB and Rubocop linters will both lint the same files so using both with within various codebases requires either manually switching back and forth or using .sublime-project files to enable/disable the correct linter plugin.

It would be better if the user were able to configure a preferred Ruby linter and then have a the correct plugin be activated if the project directory or a parent directory contains an applicable .standard.yml or .rubocop.yml file.

The user would probably do this by preferring StandardRB by setting:

{
    "settings": {
        "SublimeLinter.linters.standard.disable": false,
        "SublimeLinter.linters.standardrb.prefer-standardrb": true,
        "SublimeLinter.linters.rubocop.disable": null
    }
}

(Note that rubocop disable is null not false.)

Then we can check to see if a Rubocop config is present and activate the rubocop linter and deactivate standard for that buffer view if the Rubocop linter is available. Maybe something like:

import sys
rubocop_installed = 'SublimeLinter-rubocop' in sys.modules  # rubocop installed
if rubocop_config_found && rubocop_installed:
    view.settings.set('SublimeLinter.linters.standardrb.disable', True)
    view.settings.set('SublimeLinter.linters.rubocop.disable', False)

It seems that on_activated_async is the hook we'll probably want to use to do this work.

parse': -s/--stdin requires exactly one path...

Hi, I get this warning.
Probably a regression introduced by new a Rubocop version?

WARNING:SublimeLinter.lint.linter:standardrb output:
/Users/bijan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rubocop-0.92.0/lib/rubocop/options.rb:34:in `parse': -s/--stdin requires exactly one path, relative to the root of the project. RuboCop will use this path to determine which cops are enabled (via eg. Include/Exclude), and so that certain cops like Naming/FileName can be checked. (RuboCop::OptionArgumentError)
	from /Users/bijan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/standard-0.7/lib/standard/merges_settings.rb:10:in `call'
	from /Users/bijan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/standard-0.7/lib/standard/builds_config.rb:21:in `call'
	from /Users/bijan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/standard-0.7/lib/standard/cli.rb:16:in `run'
	from /Users/bijan/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/standard-0.7/exe/standardrb:7:in `<top (required)>'
	from /Users/bijan/.rbenv/versions/2.7.2/bin/standardrb:23:in `load'
	from /Users/bijan/.rbenv/versions/2.7.2/bin/standardrb:23:in `<main>'

Add support for auto formatting

The plugin currently has no support for Standard's --fix option. We'd like to support this, but it may make more sense to do it as a separate plugin. We'll want to look into what it will take to add a formatting command and optionally allow fixing formatting on save.

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.