overcommit 0.36.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/default.yml +34 -0
- data/lib/overcommit/hook/commit_msg/capitalized_subject.rb +2 -1
- data/lib/overcommit/hook/pre_commit/fix_me.rb +15 -0
- data/lib/overcommit/hook/pre_commit/foodcritic.rb +147 -0
- data/lib/overcommit/hook/pre_commit/license_header.rb +46 -0
- data/lib/overcommit/hook/pre_commit/line_endings.rb +55 -0
- data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +13 -3
- data/lib/overcommit/hook/pre_commit/yaml_lint.rb +16 -0
- data/lib/overcommit/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeddd35416c0acbfbcd95473bf9026cce4f3bf5e
|
4
|
+
data.tar.gz: 9f805e9ee12b8db38da383c162c61f989f8d9ab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78894882777c8c82ddf27f57f3da0a502cbf7adc0360004d126b438110c974792011543cbcc4d7251561d595199d23043c230db5a2c45e2654abb51e076da371
|
7
|
+
data.tar.gz: 22ae853f2b0ee843890098c5364d2f30fe25e9abe4df61e9c011acbec4ace2c034673c193c55b8d3c812bfb29f1b85e658d152f5b489e69f86d5e282a4b8adda
|
data/config/default.yml
CHANGED
@@ -254,6 +254,20 @@ PreCommit:
|
|
254
254
|
install_command: 'gem install fasterer'
|
255
255
|
include: '**/*.rb'
|
256
256
|
|
257
|
+
FixMe:
|
258
|
+
enabled: false
|
259
|
+
description: 'Check for "token" strings'
|
260
|
+
required_executable: 'grep'
|
261
|
+
flags: ['-IEHnw']
|
262
|
+
keywords: ['BROKEN', 'BUG', 'ERROR', 'FIXME', 'HACK', 'NOTE', 'OPTIMIZE', 'REVIEW', 'TODO', 'WTF', 'XXX']
|
263
|
+
|
264
|
+
Foodcritic:
|
265
|
+
enabled: false
|
266
|
+
description: 'Analyze with Foodcritic'
|
267
|
+
required_executable: 'foodcritic'
|
268
|
+
flags: ['--epic-fail=any']
|
269
|
+
install_command: 'gem install foodcritic'
|
270
|
+
|
257
271
|
ForbiddenBranches:
|
258
272
|
enabled: false
|
259
273
|
description: 'Check for commit to forbidden branch'
|
@@ -367,6 +381,11 @@ PreCommit:
|
|
367
381
|
install_command: 'gem install json'
|
368
382
|
include: '**/*.json'
|
369
383
|
|
384
|
+
LicenseHeader:
|
385
|
+
enabled: false
|
386
|
+
license_file: 'LICENSE.txt'
|
387
|
+
description: 'Check source files for license headers'
|
388
|
+
|
370
389
|
LocalPathsInGemfile:
|
371
390
|
enabled: false
|
372
391
|
description: 'Check for local paths in Gemfile'
|
@@ -610,6 +629,11 @@ PreCommit:
|
|
610
629
|
include:
|
611
630
|
- '**/*.html'
|
612
631
|
|
632
|
+
LineEndings:
|
633
|
+
description: 'Check line endings'
|
634
|
+
enabled: false
|
635
|
+
eol: "\n" # or "\r\n" for Windows-style newlines
|
636
|
+
|
613
637
|
XmlLint:
|
614
638
|
enabled: false
|
615
639
|
description: 'Analyze with xmllint'
|
@@ -627,6 +651,16 @@ PreCommit:
|
|
627
651
|
- '**/*.xml'
|
628
652
|
- '**/*.svg'
|
629
653
|
|
654
|
+
YamlLint:
|
655
|
+
enabled: false
|
656
|
+
description: 'Analyze with YAMLlint'
|
657
|
+
required_executable: 'yamllint'
|
658
|
+
flags: ['--format=parsable']
|
659
|
+
install_command: 'pip install yamllint'
|
660
|
+
include:
|
661
|
+
- '**/*.yaml'
|
662
|
+
- '**/*.yml'
|
663
|
+
|
630
664
|
YamlSyntax:
|
631
665
|
enabled: false
|
632
666
|
description: 'Check YAML syntax'
|
@@ -4,7 +4,8 @@ module Overcommit::Hook::CommitMsg
|
|
4
4
|
def run
|
5
5
|
return :pass if empty_message?
|
6
6
|
|
7
|
-
|
7
|
+
# Git treats the first non-empty line as the subject
|
8
|
+
subject = commit_message_lines.find { |line| !line.strip.empty? }.to_s
|
8
9
|
first_letter = subject.match(/^[[:punct:]]*(.)/)[1]
|
9
10
|
unless special_prefix?(subject) || first_letter =~ /[[:upper:]]/
|
10
11
|
return :warn, 'Subject should start with a capital letter'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Overcommit::Hook::PreCommit
|
2
|
+
# Check for "token" strings
|
3
|
+
class FixMe < Base
|
4
|
+
def run
|
5
|
+
keywords = config['keywords']
|
6
|
+
result = execute(command, args: [keywords.join('|')] + applicable_files)
|
7
|
+
|
8
|
+
extract_messages(
|
9
|
+
result.stdout.split("\n"),
|
10
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
|
11
|
+
lambda { |_type| :warning }
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Overcommit::Hook::PreCommit
|
2
|
+
# Runs `foodcritic` against any modified Ruby files from Chef directory structure.
|
3
|
+
#
|
4
|
+
# @see http://www.foodcritic.io/
|
5
|
+
#
|
6
|
+
# There are two "modes" you can run this hook in based on the repo:
|
7
|
+
#
|
8
|
+
# SINGLE COOKBOOK REPO MODE
|
9
|
+
# -------------------------
|
10
|
+
# The default. Use this if your repository contains just a single cookbook,
|
11
|
+
# i.e. the top-level repo directory contains directories called `attributes`,
|
12
|
+
# `libraries`, `recipes`, etc.
|
13
|
+
#
|
14
|
+
# To get this to work well, you'll want to set your Overcommit configuration
|
15
|
+
# for this hook to something like:
|
16
|
+
#
|
17
|
+
# PreCommit:
|
18
|
+
# Foodcritic:
|
19
|
+
# enabled: true
|
20
|
+
# include:
|
21
|
+
# - 'attributes/**/*'
|
22
|
+
# - 'definitions/**/*'
|
23
|
+
# - 'files/**/*'
|
24
|
+
# - 'libraries/**/*'
|
25
|
+
# - 'providers/**/*'
|
26
|
+
# - 'recipes/**/*'
|
27
|
+
# - 'resources/**/*'
|
28
|
+
# - 'templates/**/*'
|
29
|
+
#
|
30
|
+
# MONOLITHIC REPO MODE
|
31
|
+
# --------------------
|
32
|
+
# Use this if you store multiple cookbooks, environments, and roles (or any
|
33
|
+
# combination thereof) in a single repository.
|
34
|
+
#
|
35
|
+
# There are three configuration options relevant here:
|
36
|
+
#
|
37
|
+
# * `cookbooks_directory`
|
38
|
+
# When set, hook will treat the path as a directory containing cookbooks.
|
39
|
+
# Each subdirectory of this directory will be treated as a separate
|
40
|
+
# cookbook.
|
41
|
+
#
|
42
|
+
# * `environments_directory`
|
43
|
+
# When set, hook will treat the path as a directory containing environment
|
44
|
+
# files.
|
45
|
+
#
|
46
|
+
# * `roles_directory`
|
47
|
+
# When set, hook will treat the given path as a directory containing role
|
48
|
+
# files.
|
49
|
+
#
|
50
|
+
# In order to run in monolithic repo mode, YOU MUST SET `cookbooks_directory`.
|
51
|
+
# The other configuration options are optional, if you happen to store
|
52
|
+
# environments/roles in another repo.
|
53
|
+
#
|
54
|
+
# To get this to work well, you'll want to set your Overcommit configuration
|
55
|
+
# for this hook to something like:
|
56
|
+
#
|
57
|
+
# PreCommit:
|
58
|
+
# Foodcritic:
|
59
|
+
# enabled: true
|
60
|
+
# cookbooks_directory: 'cookbooks'
|
61
|
+
# environments_directory: 'environments'
|
62
|
+
# roles_directory: 'roles'
|
63
|
+
# include:
|
64
|
+
# - 'cookbooks/**/*'
|
65
|
+
# - 'environments/**/*'
|
66
|
+
# - 'roles/**/*'
|
67
|
+
#
|
68
|
+
# ADDITIONAL CONFIGURATION
|
69
|
+
# ------------------------
|
70
|
+
# You can disable rules using the `flags` hook option. For example:
|
71
|
+
#
|
72
|
+
# PreCommit:
|
73
|
+
# Foodcritic:
|
74
|
+
# enabled: true
|
75
|
+
# ...
|
76
|
+
# flags:
|
77
|
+
# - '--epic-fail=any'
|
78
|
+
# - '-t~FC011' # Missing README in markdown format
|
79
|
+
# - '-t~FC064' # Ensure issues_url is set in metadata
|
80
|
+
#
|
81
|
+
# Any other command line flag supported by the `foodcritic` executable can be
|
82
|
+
# specified here.
|
83
|
+
#
|
84
|
+
# If you want the hook run to fail (and not just warn), set the `on_warn`
|
85
|
+
# option for the hook to `fail`:
|
86
|
+
#
|
87
|
+
# PreCommit:
|
88
|
+
# Foodcritic:
|
89
|
+
# enabled: true
|
90
|
+
# on_warn: fail
|
91
|
+
# ...
|
92
|
+
#
|
93
|
+
# This will treat any warnings as failures and cause the hook to exit
|
94
|
+
# unsuccessfully.
|
95
|
+
class Foodcritic < Base
|
96
|
+
def run
|
97
|
+
args = modified_cookbooks_args + modified_environments_args + modified_roles_args
|
98
|
+
result = execute(command, args: args)
|
99
|
+
|
100
|
+
if result.success?
|
101
|
+
:pass
|
102
|
+
else
|
103
|
+
return [:warn, result.stderr + result.stdout]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def directories_changed(dir_prefix)
|
110
|
+
applicable_files.
|
111
|
+
select { |path| path.start_with?(dir_prefix) }.
|
112
|
+
map { |path| path.gsub(%r{^#{dir_prefix}/}, '') }.
|
113
|
+
group_by { |path| path.split('/').first }.
|
114
|
+
keys.
|
115
|
+
map { |path| File.join(dir_prefix, path) }
|
116
|
+
end
|
117
|
+
|
118
|
+
def modified_environments_args
|
119
|
+
modified('environments').map { |env| %W[-E #{env}] }.flatten
|
120
|
+
end
|
121
|
+
|
122
|
+
def modified_roles_args
|
123
|
+
modified('roles').map { |role| %W[-R #{role}] }.flatten
|
124
|
+
end
|
125
|
+
|
126
|
+
def modified_cookbooks_args
|
127
|
+
# Return the repo root if repository contains a single cookbook
|
128
|
+
if !config['cookbooks_directory'] || config['cookbooks_directory'].empty?
|
129
|
+
['-B', Overcommit::Utils.repo_root]
|
130
|
+
else
|
131
|
+
# Otherwise return all modified cookbooks in the cookbook directory
|
132
|
+
modified('cookbooks').map { |cookbook| ['-B', cookbook] }.flatten
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def modified(type)
|
137
|
+
return [] if !config["#{type}_directory"] || config["#{type}_directory"].empty?
|
138
|
+
@modified ||= {}
|
139
|
+
@modified[type] ||= directories_changed(full_directory_path("#{type}_directory"))
|
140
|
+
end
|
141
|
+
|
142
|
+
def full_directory_path(config_option)
|
143
|
+
return config[config_option] if config[config_option].start_with?(File::SEPARATOR)
|
144
|
+
File.absolute_path(File.join(Overcommit::Utils.repo_root, config[config_option]))
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Overcommit::Hook::PreCommit
|
2
|
+
# Checks for license headers in source files
|
3
|
+
class LicenseHeader < Base
|
4
|
+
def run
|
5
|
+
begin
|
6
|
+
license_contents = license_lines
|
7
|
+
rescue Errno::ENOENT
|
8
|
+
return :fail, "Unable to load license file #{license_file}"
|
9
|
+
end
|
10
|
+
|
11
|
+
messages = applicable_files.map do |file|
|
12
|
+
check_file(file, license_contents)
|
13
|
+
end.compact
|
14
|
+
|
15
|
+
return :fail, messages.join("\n") if messages.any?
|
16
|
+
|
17
|
+
:pass
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_file(file, license_contents)
|
21
|
+
File.readlines(file).each_with_index do |l, i|
|
22
|
+
if i >= license_contents.length
|
23
|
+
break
|
24
|
+
end
|
25
|
+
|
26
|
+
l.chomp!
|
27
|
+
unless l.end_with?(license_contents[i])
|
28
|
+
message = "#{file} missing header contents from line #{i} of "\
|
29
|
+
"#{license_file}: #{license_contents[i]}"
|
30
|
+
return message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def license_file
|
36
|
+
config['license_file']
|
37
|
+
end
|
38
|
+
|
39
|
+
def license_lines
|
40
|
+
@license_regex ||= begin
|
41
|
+
file_root = Overcommit::Utils.convert_glob_to_absolute(license_file)
|
42
|
+
File.read(file_root).split("\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Overcommit::Hook::PreCommit
|
2
|
+
# Checks for line endings in files.
|
3
|
+
#
|
4
|
+
# WARNING: Works with Git 2.10.0 or newer.
|
5
|
+
class LineEndings < Base
|
6
|
+
def run
|
7
|
+
messages = []
|
8
|
+
|
9
|
+
offending_files.map do |file_name|
|
10
|
+
file = File.open(file_name)
|
11
|
+
file.each_line do |line|
|
12
|
+
# remove configured line-ending
|
13
|
+
line.gsub!(/#{config['eol']}/, '')
|
14
|
+
|
15
|
+
# detect any left over line-ending characters
|
16
|
+
next unless line.end_with?("\n", "\r")
|
17
|
+
|
18
|
+
messages << Overcommit::Hook::Message.new(
|
19
|
+
:error,
|
20
|
+
file_name,
|
21
|
+
file.lineno,
|
22
|
+
"#{file_name}:#{file.lineno}:#{line.inspect}"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
messages
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def offending_files
|
33
|
+
result = execute(%w[git ls-files --eol -z --], args: applicable_files)
|
34
|
+
raise 'Unable to access git tree' unless result.success?
|
35
|
+
|
36
|
+
result.stdout.split("\0").map do |file_info|
|
37
|
+
i, _w, _attr, path = file_info.split
|
38
|
+
next if i == 'l/-text' # ignore binary files
|
39
|
+
next if i == "l/#{eol}"
|
40
|
+
path
|
41
|
+
end.compact
|
42
|
+
end
|
43
|
+
|
44
|
+
def eol
|
45
|
+
@eol ||= case config['eol']
|
46
|
+
when "\n"
|
47
|
+
'lf'
|
48
|
+
when "\r\n"
|
49
|
+
'crlf'
|
50
|
+
else
|
51
|
+
raise 'Invalid `eol` option specified: must be "\n" or "\r\n"'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module Overcommit::Hook::PreCommit
|
2
|
-
# Check to see whether the schema file is in line with the migrations
|
2
|
+
# Check to see whether the schema file is in line with the migrations. When a
|
3
|
+
# schema file is present but a migration file is not, this is usually a
|
4
|
+
# failure. The exception is if the schema is at version 0 (i.e before any
|
5
|
+
# migrations have been run). In this case it is OK if there are no migrations.
|
3
6
|
class RailsSchemaUpToDate < Base
|
4
7
|
def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity
|
5
8
|
if migration_files.any? && schema_files.none?
|
6
9
|
return :fail, "It looks like you're adding a migration, but did not update the schema file"
|
7
|
-
elsif migration_files.none? && schema_files.any?
|
10
|
+
elsif migration_files.none? && schema_files.any? && non_zero_schema_version?
|
8
11
|
return :fail, "You're trying to change the schema without adding a migration file"
|
9
12
|
elsif migration_files.any? && schema_files.any?
|
10
13
|
# Get the latest version from the migration filename. Use
|
@@ -15,7 +18,6 @@ module Overcommit::Hook::PreCommit
|
|
15
18
|
File.basename(file)[/\d+/]
|
16
19
|
end.sort.last
|
17
20
|
|
18
|
-
schema = schema_files.map { |file| File.read(file) }.join
|
19
21
|
up_to_date = schema.include?(latest_version)
|
20
22
|
|
21
23
|
unless up_to_date
|
@@ -41,5 +43,13 @@ module Overcommit::Hook::PreCommit
|
|
41
43
|
file.match %r{db/schema\.rb|db/structure.*\.sql}
|
42
44
|
end
|
43
45
|
end
|
46
|
+
|
47
|
+
def schema
|
48
|
+
@schema ||= schema_files.map { |file| File.read(file) }.join
|
49
|
+
end
|
50
|
+
|
51
|
+
def non_zero_schema_version?
|
52
|
+
schema =~ /\d{14}/
|
53
|
+
end
|
44
54
|
end
|
45
55
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Overcommit::Hook::PreCommit
|
2
|
+
# Runs `YAMLLint` against any modified YAML files.
|
3
|
+
#
|
4
|
+
# @see https://github.com/adrienverge/yamllint
|
5
|
+
class YamlLint < Base
|
6
|
+
def run
|
7
|
+
result = execute(command, args: applicable_files)
|
8
|
+
|
9
|
+
if result.success?
|
10
|
+
:pass
|
11
|
+
else
|
12
|
+
return [:warn, result.stdout]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/overcommit/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overcommit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.37.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brigade Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: childprocess
|
@@ -117,6 +117,8 @@ files:
|
|
117
117
|
- lib/overcommit/hook/pre_commit/es_lint.rb
|
118
118
|
- lib/overcommit/hook/pre_commit/execute_permissions.rb
|
119
119
|
- lib/overcommit/hook/pre_commit/fasterer.rb
|
120
|
+
- lib/overcommit/hook/pre_commit/fix_me.rb
|
121
|
+
- lib/overcommit/hook/pre_commit/foodcritic.rb
|
120
122
|
- lib/overcommit/hook/pre_commit/forbidden_branches.rb
|
121
123
|
- lib/overcommit/hook/pre_commit/go_lint.rb
|
122
124
|
- lib/overcommit/hook/pre_commit/go_vet.rb
|
@@ -132,6 +134,8 @@ files:
|
|
132
134
|
- lib/overcommit/hook/pre_commit/jscs.rb
|
133
135
|
- lib/overcommit/hook/pre_commit/jsl.rb
|
134
136
|
- lib/overcommit/hook/pre_commit/json_syntax.rb
|
137
|
+
- lib/overcommit/hook/pre_commit/license_header.rb
|
138
|
+
- lib/overcommit/hook/pre_commit/line_endings.rb
|
135
139
|
- lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb
|
136
140
|
- lib/overcommit/hook/pre_commit/mdl.rb
|
137
141
|
- lib/overcommit/hook/pre_commit/merge_conflicts.rb
|
@@ -163,6 +167,7 @@ files:
|
|
163
167
|
- lib/overcommit/hook/pre_commit/w3c_html.rb
|
164
168
|
- lib/overcommit/hook/pre_commit/xml_lint.rb
|
165
169
|
- lib/overcommit/hook/pre_commit/xml_syntax.rb
|
170
|
+
- lib/overcommit/hook/pre_commit/yaml_lint.rb
|
166
171
|
- lib/overcommit/hook/pre_commit/yaml_syntax.rb
|
167
172
|
- lib/overcommit/hook/pre_push/base.rb
|
168
173
|
- lib/overcommit/hook/pre_push/brakeman.rb
|
@@ -240,4 +245,3 @@ signing_key:
|
|
240
245
|
specification_version: 4
|
241
246
|
summary: Git hook manager
|
242
247
|
test_files: []
|
243
|
-
has_rdoc:
|