Skip to content

Commit

Permalink
Fix generating ignore list when one exists already
Browse files Browse the repository at this point in the history
Generating an ignore list is done by running Rubocop over all the files
in the project to detect which have errors, and then writing that list
of files to `.standard_todo.yml`.

When a file was already ignored in `.standard_todo.yml`, Rubocop would
be configured to not run cops against it. In that case, no errors were
reported, so the file would not be written to `.standard_todo.yml`.

This leads to a situation where if a file is ignored, running
`standardrb --generated-todo` would remove it from the todo list, and
add all other files with errors. Running the same command again would
then flip the file list.

We fix this by setting the list of ignored files to an empty array
before running Rubocop in the `genignore` runner.
  • Loading branch information
craigw committed May 18, 2020
1 parent 4b05ef6 commit d339851
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/standard/runners/genignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def call(config)
config.rubocop_options[:formatters] = [["files", temp_file.path]]
config.rubocop_options[:format] = "files"
config.rubocop_options[:out] = temp_file.path
remove_project_files_from_ignore_list(config)
Runners::Rubocop.new.call(config)

# Read in the files with errors. It will have the absolute paths
Expand Down Expand Up @@ -43,6 +44,14 @@ def call(config)
temp_file.unlink
end
end

# FIXME: This will also remove files which are in
# `Standard::CreatesConfigStore::ConfiguresIgnoredPaths::DEFAULT_IGNORES`.
def remove_project_files_from_ignore_list(config)
options_config = config.rubocop_config_store.instance_variable_get("@options_config")
options_config["AllCops"] ||= []
options_config["AllCops"]["Exclude"] = []
end
end
end
end
11 changes: 11 additions & 0 deletions test/standard/runners/genignore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def test_todo_generated
def create_config(config_path)
store = RuboCop::ConfigStore.new.tap do |config_store|
config_store.options_config = config_path

# Simulate a `.standard_todo.yml` that contains an ignore file:
#
# ---
# ignore:
# - errors_one.rb
#
options_config = config_store.instance_variable_get("@options_config")
options_config["AllCops"] ||= []
options_config["AllCops"]["Exclude"] ||= []
options_config["AllCops"]["Exclude"] |= [path("errors_one.rb")]
end

Standard::Config.new(nil, ["."], {}, store)
Expand Down

0 comments on commit d339851

Please sign in to comment.