Skip to content

Commit

Permalink
style: chdir before running rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Jun 30, 2024
1 parent d726657 commit 26e52b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 15 additions & 5 deletions Library/Homebrew/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 26e52b2

Please # to comment.