From 26e52b2e90160ff4935682add445c15b80d02df1 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sun, 30 Jun 2024 01:21:54 +0100 Subject: [PATCH] style: chdir before running rubocop --- Library/.rubocop.yml | 5 +++++ Library/Homebrew/style.rb | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 43339e2660eff1..aaddb602a6ddc8 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -327,6 +327,11 @@ Style/Documentation: - "**/{Formula,Casks}/**/*.rb" - "**/*.rbi" +# This is impossible to fix if the line exceeds the maximum length. +Style/EmptyMethod: + Exclude: + - "**/*.rbi" + # This is quite a large change, so don't enforce this yet for formulae. # We should consider doing so in the future, but be aware of the impact on third-party taps. Style/FetchEnvVar: diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index 0f0dd36b96425e..c19657f0928218 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -149,12 +149,19 @@ def self.run_rubocop(files, output_type, end files&.map!(&:expand_path) + base_dir = Dir.pwd if files.blank? || files == [HOMEBREW_REPOSITORY] files = [HOMEBREW_LIBRARY_PATH] + base_dir = HOMEBREW_LIBRARY_PATH elsif files.any? { |f| f.to_s.start_with?(HOMEBREW_REPOSITORY/"docs") || (f.basename.to_s == "docs") } args << "--config" << (HOMEBREW_REPOSITORY/"docs/docs_rubocop_style.yml") - elsif files.none? { |f| f.to_s.start_with? HOMEBREW_LIBRARY_PATH } + elsif files.any? { |f| f.to_s.start_with? HOMEBREW_LIBRARY_PATH } + base_dir = HOMEBREW_LIBRARY_PATH + else args << "--config" << (HOMEBREW_LIBRARY/".rubocop.yml") + base_dir = HOMEBREW_LIBRARY if files.any? { |f| f.to_s.start_with? HOMEBREW_LIBRARY } + else + end args += files @@ -174,14 +181,17 @@ def self.run_rubocop(files, output_type, args << "--color" if Tty.color? - system cache_env, *ruby_args, "--", RUBOCOP, *args + system cache_env, *ruby_args, "--", RUBOCOP, *args, chdir: base_dir $CHILD_STATUS.success? when :json result = system_command ruby_args.shift, - args: [*ruby_args, "--", RUBOCOP, "--format", "json", *args], - env: cache_env + args: [*ruby_args, "--", RUBOCOP, "--format", "json", *args], + env: cache_env, + chdir: base_dir json = json_result!(result) - json["files"] + json["files"].each do |file| + file["path"] = File.absolute_path(file["path"], base_dir) + end end end