Rubocop: `-n` option doesn't disable colors

Created on 25 Mar 2017  路  6Comments  路  Source: rubocop-hq/rubocop

Expected behavior

rubocop -n runs Rubocop without coloring the output.

Actual behavior

Rubocop runs with colors.

Steps to reproduce the problem

rubocop -n

RuboCop version

0.47.1 (using Parser 2.4.0.0, running on ruby 2.3.1 x86_64-darwin15)

The cause

Here's what I found out. There was only --no-color option, without optional [no-] part. When --[no-]color was introduced, the shorthand version of this flag (-n) wasn't taken into account.
https://github.com/bbatsov/rubocop/commit/a5ce6dfe62c6411609d285e4befcc0fec28e9d57#diff-aabedc1d8225971d14fe2ceecc1be1e1

OptionParser just don't knows that -n is a negative flag:

require 'optparse'

option_parser = OptionParser.new do |cli|
  cli.on('-n', '--[no-]color', 'Force color output on or off.') do |color|
    p color
  end
end

option_parser.parse(['--color'])
option_parser.parse(['--no-color'])
option_parser.parse(['-n'])
true
false
true

I suggest to drop this flag.

What do you think?

bug

All 6 comments

It looks like you found the reason for this issue already. It seems like the only options are to split this out so there is a --color option and a -n, --no-color option, or split it out so that we have a --[no-]color option and a -n option that sets no color. I am not sure which would be preferred or if anyone has another idea how to fix this. What are your thought @bbatsov?

I guess another other option could be to remove the -n flag since it seems like it has been broken for over a year, and as far as I know, this is the first that anyone has mentioned it.

I guess another other option could be to remove the -n flag since it seems like it has been broken for over a year, and as far as I know, this is the first that anyone has mentioned it.

Yeah, probably this functionality doesn't warrant having short option names at all.

@bbatsov may I submit PR that removes the short option?

@sadovnik PRs are always welcome. I don't think anyone has started this work, so I say go for it.

I guess another other option could be to remove the -n flag since it seems like it has been broken for over a year, and as far as I know, this is the first that anyone has mentioned it.

Yeah, probably this functionality doesn't warrant having short option names at all.

Agree. Also -n is not the most intuitive option for disabling color. 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lepieru picture lepieru  路  3Comments

mikegee picture mikegee  路  3Comments

kirrmann picture kirrmann  路  3Comments

cabello picture cabello  路  3Comments

mlammers picture mlammers  路  3Comments