diff --git a/docs/modules/ROOT/pages/usage/basic_usage.adoc b/docs/modules/ROOT/pages/usage/basic_usage.adoc index 6df7803e4af..7fb748e4584 100644 --- a/docs/modules/ROOT/pages/usage/basic_usage.adoc +++ b/docs/modules/ROOT/pages/usage/basic_usage.adoc @@ -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. diff --git a/lib/rubocop/formatter/disabled_config_formatter.rb b/lib/rubocop/formatter/disabled_config_formatter.rb index 840fb2744a7..5d8f7f4b7c3 100644 --- a/lib/rubocop/formatter/disabled_config_formatter.rb +++ b/lib/rubocop/formatter/disabled_config_formatter.rb @@ -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) @@ -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' @@ -66,15 +73,15 @@ def command format(' --exclude-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 @@ -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? diff --git a/lib/rubocop/options.rb b/lib/rubocop/options.rb index cecfd6ac64b..5e5b418222d 100644 --- a/lib/rubocop/options.rb +++ b/lib/rubocop/options.rb @@ -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 @@ -318,7 +313,7 @@ def validate_auto_gen_config message = '--%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, @@ -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}."], diff --git a/spec/rubocop/options_spec.rb b/spec/rubocop/options_spec.rb index 3b5bed02115..f5cb284ba0c 100644 --- a/spec/rubocop/options_spec.rb +++ b/spec/rubocop/options_spec.rb @@ -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