Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generating ignore list when one exists already #176

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/standard/runners/genignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def call(config)
# Run Rubocop to generate the files with errors into the temp file.
config.rubocop_options[:formatters] = [["json", temp_file.path]]
config.rubocop_options[:out] = temp_file.path
remove_project_files_from_ignore_list(config)
exit_code = Runners::Rubocop.new.call(config)

result = JSON.parse(temp_file.read)
Expand Down Expand Up @@ -39,6 +40,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