Skip to content

Commit

Permalink
Add opposite versions of --auto-gen-config adjacent switches so tha…
Browse files Browse the repository at this point in the history
…t they can be overridden when regenerating the todo file
  • Loading branch information
dvandersluis committed Sep 24, 2020
1 parent 33ce5ac commit 7375130
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
11 changes: 7 additions & 4 deletions docs/modules/ROOT/pages/usage/basic_usage.adoc
Expand Up @@ -199,11 +199,14 @@ $ rubocop -h
| `-L/--list-target-files`
| List all files RuboCop will inspect.

| `--no-auto-gen-timestamp`
| Don't include the date and time when --auto-gen-config was run in the config file it generates
| `--[no-]auto-gen-only-exclude`
| Generate only `Exclude` parameters and not `Max` when running `--auto-gen-config`, except if the number of files with offenses is bigger than `exclude-limit`. Default is false

| `--no-offense-counts`
| Don't show offense counts in config file generated by --auto-gen-config
| `--[no-]auto-gen-timestamp`
| Include the date and time when `--auto-gen-config` was run in the config file it generates. Default is true.

| `--[no-]offense-counts`
| Show offense counts in config file generated by `--auto-gen-config`. Default is true.

| `--only`
| Run only the specified cop(s) and/or cops in the specified departments.
Expand Down
17 changes: 12 additions & 5 deletions lib/rubocop/formatter/disabled_config_formatter.rb
Expand Up @@ -32,7 +32,6 @@ def file_started(_file, _file_info)
@exclude_limit_option = @options[:exclude_limit]
@exclude_limit = Integer(@exclude_limit_option ||
RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS)
@show_offense_counts = !@options[:no_offense_counts]
end

def file_finished(file, offenses)
Expand All @@ -56,6 +55,14 @@ def finished(_inspected_files)

private

def show_timestamp?
@options.fetch(:auto_gen_timestamp, true)
end

def show_offense_counts?
@options.fetch(:offense_counts, true)
end

def command
command = 'rubocop --auto-gen-config'

Expand All @@ -66,15 +73,15 @@ def command
format(' --exclude-limit %<limit>d',
limit: Integer(@exclude_limit_option))
end
command += ' --no-offense-counts' if @options[:no_offense_counts]
command += ' --no-offense-counts' unless show_offense_counts?

command += ' --no-auto-gen-timestamp' if @options[:no_auto_gen_timestamp]
command += ' --no-auto-gen-timestamp' unless show_timestamp?

command
end

def timestamp
@options[:no_auto_gen_timestamp] ? '' : "on #{Time.now.utc} "
show_timestamp? ? "on #{Time.now.utc} " : ''
end

def output_offenses
Expand Down Expand Up @@ -112,7 +119,7 @@ def set_max(cfg, cop_name)
end

def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
output_buffer.puts "# Offense count: #{offense_count}" if @show_offense_counts
output_buffer.puts "# Offense count: #{offense_count}" if show_offense_counts?

cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
output_buffer.puts '# Cop supports --auto-correct.' if cop_class&.support_autocorrect?
Expand Down
27 changes: 11 additions & 16 deletions lib/rubocop/options.rb
Expand Up @@ -120,14 +120,9 @@ def add_auto_gen_options(opts)

option(opts, '--disable-uncorrectable')

option(opts, '--no-offense-counts') do
@options[:no_offense_counts] = true
end

option(opts, '--auto-gen-only-exclude')
option(opts, '--no-auto-gen-timestamp') do
@options[:no_auto_gen_timestamp] = true
end
option(opts, '--[no-]offense-counts')
option(opts, '--[no-]auto-gen-only-exclude')
option(opts, '--[no-]auto-gen-timestamp')

option(opts, '--init')
end
Expand Down Expand Up @@ -318,7 +313,7 @@ def validate_auto_gen_config

message = '--%<flag>s can only be used together with --auto-gen-config.'

%i[exclude_limit no_offense_counts no_auto_gen_timestamp
%i[exclude_limit offense_counts auto_gen_timestamp
auto_gen_only_exclude].each do |option|
if @options.key?(option)
raise OptionArgumentError,
Expand Down Expand Up @@ -423,17 +418,17 @@ module OptionsHelp
config: 'Specify configuration file.',
auto_gen_config: ['Generate a configuration file acting as a',
'TODO list.'],
no_offense_counts: ['Do not include offense counts in configuration',
'file generated by --auto-gen-config.'],
no_auto_gen_timestamp:
['Do not include the date and time when',
'the --auto-gen-config was run in the file it',
'generates.'],
offense_counts: ['Include offense counts in configuration',
'file generated by --auto-gen-config.',
'Default is true.'],
auto_gen_timestamp:
['Include the date and time when the --auto-gen-config',
'was run in the file it generates. Default is true.'],
auto_gen_only_exclude:
['Generate only Exclude parameters and not Max',
'when running --auto-gen-config, except if the',
'number of files with offenses is bigger than',
'exclude-limit.'],
'exclude-limit. Default is false.'],
exclude_limit: ['Used together with --auto-gen-config to',
'set the limit for how many Exclude',
"properties to generate. Default is #{MAX_EXCL}."],
Expand Down
12 changes: 6 additions & 6 deletions spec/rubocop/options_spec.rb
Expand Up @@ -58,15 +58,15 @@ def abs(path)
--disable-uncorrectable Used with --auto-correct to annotate any
offenses that do not support autocorrect
with `rubocop:todo` comments.
--no-offense-counts Do not include offense counts in configuration
--[no-]offense-counts Include offense counts in configuration
file generated by --auto-gen-config.
--auto-gen-only-exclude Generate only Exclude parameters and not Max
Default is true.
--[no-]auto-gen-only-exclude Generate only Exclude parameters and not Max
when running --auto-gen-config, except if the
number of files with offenses is bigger than
exclude-limit.
--no-auto-gen-timestamp Do not include the date and time when
the --auto-gen-config was run in the file it
generates.
exclude-limit. Default is false.
--[no-]auto-gen-timestamp Include the date and time when the --auto-gen-config
was run in the file it generates. Default is true.
--init Generate a .rubocop.yml file in the current directory.
-f, --format FORMATTER Choose an output formatter. This option
can be specified multiple times to enable
Expand Down

0 comments on commit 7375130

Please sign in to comment.