Add brew style --changed
This emulates `brew tests --changed` but for style checks. Should make things a bit quicker for the case of wanting to quickly fix up local files.
This commit is contained in:
parent
7878c73b85
commit
621114488e
@ -24,6 +24,8 @@ module Homebrew
|
||||
hidden: true
|
||||
switch "--reset-cache",
|
||||
description: "Reset the RuboCop cache."
|
||||
switch "--changed",
|
||||
description: "Check files that were changed from the `main` branch."
|
||||
switch "--formula", "--formulae",
|
||||
description: "Treat all named arguments as formulae."
|
||||
switch "--cask", "--casks",
|
||||
@ -45,12 +47,23 @@ module Homebrew
|
||||
def run
|
||||
Homebrew.install_bundler_gems!(groups: ["style"])
|
||||
|
||||
target = if args.no_named?
|
||||
if args.changed? && !args.no_named?
|
||||
raise UsageError, "`--changed` and named arguments are mutually exclusive!"
|
||||
end
|
||||
|
||||
target = if args.changed?
|
||||
changed_ruby_or_shell_files
|
||||
elsif args.no_named?
|
||||
nil
|
||||
else
|
||||
args.named.to_paths
|
||||
end
|
||||
|
||||
if target.blank? && args.changed?
|
||||
opoo "No style checks are available for the changed files!"
|
||||
return
|
||||
end
|
||||
|
||||
only_cops = args.only_cops
|
||||
except_cops = args.except_cops
|
||||
|
||||
@ -70,6 +83,19 @@ module Homebrew
|
||||
|
||||
Homebrew.failed = !Style.check_style_and_print(target, **options)
|
||||
end
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def changed_ruby_or_shell_files
|
||||
changed_files = Utils.popen_read("git", "diff", "--name-only", "main")
|
||||
|
||||
raise UsageError, "No files have been changed from the `main` branch!" if changed_files.blank?
|
||||
|
||||
changed_files.split("\n").filter_map do |file|
|
||||
next if !file.end_with?(".rb", ".sh", ".yml", ".rbi") && file != "bin/brew"
|
||||
|
||||
Pathname(file)
|
||||
end.select(&:exist?)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -17,6 +17,9 @@ class Homebrew::DevCmd::StyleCmd::Args < Homebrew::CLI::Args
|
||||
sig { returns(T::Boolean) }
|
||||
def casks?; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def changed?; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def display_cop_names?; end
|
||||
|
||||
|
@ -2429,6 +2429,7 @@ _brew_style() {
|
||||
-*)
|
||||
__brewcomp "
|
||||
--cask
|
||||
--changed
|
||||
--debug
|
||||
--except-cops
|
||||
--fix
|
||||
|
@ -1598,6 +1598,7 @@ __fish_brew_complete_arg 'shellenv' -l verbose -d 'Make some output more verbose
|
||||
|
||||
__fish_brew_complete_cmd 'style' 'Check formulae or files for conformance to Homebrew style guidelines'
|
||||
__fish_brew_complete_arg 'style' -l cask -d 'Treat all named arguments as casks'
|
||||
__fish_brew_complete_arg 'style' -l changed -d 'Check files that were changed from the `main` branch'
|
||||
__fish_brew_complete_arg 'style' -l debug -d 'Display any debugging information'
|
||||
__fish_brew_complete_arg 'style' -l except-cops -d 'Specify a comma-separated cops list to skip checking for violations of the listed RuboCop cops'
|
||||
__fish_brew_complete_arg 'style' -l fix -d 'Fix style violations automatically using RuboCop\'s auto-correct feature'
|
||||
|
@ -1960,6 +1960,7 @@ _brew_shellenv() {
|
||||
# brew style
|
||||
_brew_style() {
|
||||
_arguments \
|
||||
'--changed[Check files that were changed from the `main` branch]' \
|
||||
'--debug[Display any debugging information]' \
|
||||
'(--only-cops)--except-cops[Specify a comma-separated cops list to skip checking for violations of the listed RuboCop cops]' \
|
||||
'--fix[Fix style violations automatically using RuboCop'\''s auto-correct feature]' \
|
||||
|
@ -3121,6 +3121,10 @@ core code and all formulae.
|
||||
|
||||
: Reset the RuboCop cache.
|
||||
|
||||
`--changed`
|
||||
|
||||
: Check files that were changed from the `main` branch.
|
||||
|
||||
`--formula`
|
||||
|
||||
: Treat all named arguments as formulae.
|
||||
|
@ -1977,6 +1977,9 @@ Fix style violations automatically using RuboCop\[u2019]s auto\-correct feature\
|
||||
\fB\-\-reset\-cache\fP
|
||||
Reset the RuboCop cache\.
|
||||
.TP
|
||||
\fB\-\-changed\fP
|
||||
Check files that were changed from the \fBmain\fP branch\.
|
||||
.TP
|
||||
\fB\-\-formula\fP
|
||||
Treat all named arguments as formulae\.
|
||||
.TP
|
||||
|
Loading…
x
Reference in New Issue
Block a user