-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mattlqx/cookstyle
add cookstyle hook
- Loading branch information
Showing
8 changed files
with
94 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
source 'https://rubygems.org' | ||
|
||
gem 'rubocop', '0.57.2' | ||
gem 'rubocop', '0.77.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
def metadata_walk(path) | ||
dir = File.directory?(path) ? path : File.dirname(path) | ||
if File.exist?(File.join(dir, 'metadata.rb')) || File.exist?(File.join(dir, 'metadata.json')) | ||
[dir, File.exist?(File.join(dir, 'metadata.json')) ? 'json' : 'rb'] | ||
elsif ['.', '/'].include?(dir) | ||
false | ||
else | ||
metadata_walk(File.dirname(dir)) | ||
end | ||
end | ||
|
||
def bump_required?(file) | ||
%w[ | ||
metadata.(rb|json) | ||
Berksfile | ||
Berksfile.lock | ||
Policyfile.rb | ||
Policyfile.lock.json | ||
recipes/.* | ||
attributes/.* | ||
libraries/.* | ||
files/.* | ||
templates/.* | ||
].each do |regex| | ||
break true if file.match?("#{regex}$") | ||
end == true | ||
end | ||
|
||
def changed_cookbooks(bump_check: true) | ||
changed_cookbooks = [] | ||
ARGV.each do |file| | ||
cookbook, type = metadata_walk(file) | ||
next if cookbook == false || changed_cookbooks.map(&:first).include?(cookbook) || file.include?('/test/') | ||
|
||
next if bump_check && !bump_required?(file) | ||
|
||
changed_cookbooks << [cookbook, type] | ||
end | ||
changed_cookbooks.sort! | ||
changed_cookbooks | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative 'common' | ||
|
||
# Check each changed file for a spec directory in its heirarchy | ||
fix = '' | ||
Array.new(ARGV).each do |arg| | ||
next unless arg == '--fix' | ||
|
||
fix = '-a' | ||
ARGV.delete('--fix') | ||
break | ||
end | ||
|
||
# Exit early if there are no paths to lint | ||
success = true | ||
exit(success) if changed_cookbooks(bump_check: false).empty? | ||
|
||
# Install cookstyle and drop args that are paths | ||
system('bundle install >/dev/null') || exit(false) | ||
system("bundle exec cookstyle --color #{fix} #{changed_cookbooks.map(&:first).join(' ')}") || exit(false) |