overcommit 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6030d9d4951a3c37f536bfd4caefc3890c6c4f2d
4
- data.tar.gz: 04a5f6031e2217c33382a2c034f7670f711dbdbe
3
+ metadata.gz: f85ad2d80c2da4defeec5bce808514385a27c6e6
4
+ data.tar.gz: e547ff585ce285436624840c7b16e32ab79677a7
5
5
  SHA512:
6
- metadata.gz: c6769844c60d201e95417a06610daef7c1a5465184c176423ad7bf9bfb958373116fe8d17085ecc9f2d741677d9a928e28df6ac6b174f5499d8907837eef1305
7
- data.tar.gz: 49c7bbeafda273737fafc8aba005eda1b5c13774932a143c7c85664ee32f4f84898999c1da2cea9f4b2ffb2eae490386bef0b8c744b76a798a9c90478f859000
6
+ metadata.gz: 5e7633bf2eccb141b29a8b0bb69910ceb3810badc570a9573f3a6ce069988af8a436ee7b91f2802bf8f305be92aac98c1f603d9570690f7bad5ecae4bf6bff5c
7
+ data.tar.gz: 5988d0a37ca6bf001019e94c19e11e97aeb52cc1bec66e75478d1c5bb04f231c43f77447702b579c3a468d9248c6515d62fa28337b93cd92725e33b47eec665b
data/config/default.yml CHANGED
@@ -53,6 +53,12 @@ PreCommit:
53
53
  required: true
54
54
  quiet: true
55
55
 
56
+ Brakeman:
57
+ enabled: false
58
+ description: 'Checking for security vulnerabilities'
59
+ include:
60
+ - '**/*.rb'
61
+
56
62
  BundleCheck:
57
63
  description: 'Checking Gemfile dependencies'
58
64
  include:
@@ -60,6 +66,11 @@ PreCommit:
60
66
  - 'Gemfile.lock'
61
67
  - '*.gemspec'
62
68
 
69
+ ChamberSecurity:
70
+ enabled: false
71
+ description: 'Checking that settings have been secured with Chamber'
72
+ include: 'config/settings.yml'
73
+
63
74
  CoffeeLint:
64
75
  description: 'Analyzing with coffeelint'
65
76
  include: '**/*.coffee'
@@ -91,10 +102,38 @@ PreCommit:
91
102
  description: 'Analyzing with JSHint'
92
103
  include: '**/*.js'
93
104
 
105
+ JsonSyntax:
106
+ description: 'Validating JSON syntax'
107
+ include: '**/*.json'
108
+
109
+ JsxHint:
110
+ description: 'Analyzing with JSXHint'
111
+ include: '**/*.jsx'
112
+
113
+ LocalPathsInGemfile:
114
+ description: 'Checking for references to local paths in your Gemfile'
115
+ include: '**/Gemfile'
116
+
117
+ MergeConflicts:
118
+ description: 'Checking for merge conflicts'
119
+
120
+ PryBinding:
121
+ description: 'Checking for instances of binding.pry'
122
+ include:
123
+ - '**/*.rb'
124
+ - '**/*.rake'
125
+
94
126
  PythonFlake8:
95
127
  description: 'Analyzing with flake8'
96
128
  include: '**/*.py'
97
129
 
130
+ RailsSchemaUpToDate:
131
+ description: 'Checking if database schema is up to date'
132
+ include:
133
+ - 'db/migrate/*.rb'
134
+ - 'db/schema.rb'
135
+ - 'db/structure.sql'
136
+
98
137
  Rubocop:
99
138
  description: 'Analyzing with Rubocop'
100
139
  include:
@@ -112,7 +112,7 @@ module Overcommit
112
112
  end
113
113
 
114
114
  def smart_merge(parent, child)
115
- parent.merge(child) do |key, old, new|
115
+ parent.merge(child) do |_key, old, new|
116
116
  case old
117
117
  when Array
118
118
  old + Array(new)
@@ -0,0 +1,24 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Check if local Berksfile.lock matches Berksfile when either changes, unless
3
+ # Berksfile.lock is ignored by git.
4
+ class BerksfileCheck < Base
5
+ LOCK_FILE = 'Berksfile.lock'
6
+
7
+ def run
8
+ unless in_path?('berks')
9
+ return :warn, 'Berkshelf not installed -- run `gem install berkshelf`'
10
+ end
11
+
12
+ # Ignore if Berksfile.lock is not tracked by git
13
+ ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
14
+ return :good if ignored_files.include?(LOCK_FILE)
15
+
16
+ result = execute(%w[berks list --quiet])
17
+ unless result.success?
18
+ return :bad, result.stderr
19
+ end
20
+
21
+ :good
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `brakeman` against any modified Ruby/Rails files.
3
+ class Brakeman < Base
4
+ def run
5
+ unless in_path?('brakeman')
6
+ return :warn, 'Run `gem install brakeman`'
7
+ end
8
+
9
+ result = execute(%w[brakeman --exit-on-warn --quiet --summary --only-files] +
10
+ applicable_files)
11
+ return :good if result.success?
12
+
13
+ [:bad, result.stdout]
14
+ end
15
+ end
16
+ end
@@ -10,7 +10,8 @@ module Overcommit::Hook::PreCommit
10
10
  end
11
11
 
12
12
  # Ignore if Gemfile.lock is not tracked by git
13
- return :good if execute(%w[git check-ignore] + [LOCK_FILE]).success?
13
+ ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
14
+ return :good if ignored_files.include?(LOCK_FILE)
14
15
 
15
16
  result = execute(%w[bundle check])
16
17
  unless result.success?
@@ -0,0 +1,15 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `chamber secure` against any modified Chamber settings files
3
+ class ChamberSecurity < Base
4
+ def run
5
+ unless in_path?('chamber')
6
+ return :warn, 'Run `gem install chamber`'
7
+ end
8
+
9
+ result = execute(%w[chamber secure --echo --files] + applicable_files)
10
+
11
+ return :good if result.stdout.empty?
12
+ [:bad, "These settings appear to need to be secured but were not: #{result.stdout}"]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Checks the syntax of any modified JSON files.
5
+ class JsonSyntax < Base
6
+ def run
7
+ output = []
8
+
9
+ applicable_files.each do |file|
10
+ begin
11
+ File.open(file) { |io| JSON.load(io) }
12
+ rescue JSON::ParserError => e
13
+ output << "#{e.message} parsing #{file}"
14
+ end
15
+ end
16
+
17
+ return :good if output.empty?
18
+
19
+ [:bad, output]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `jsxhint` against any modified JSX files.
3
+ class JsxHint < Base
4
+ def run
5
+ unless in_path?('jsxhint')
6
+ return :warn, 'jsxhint not installed -- run `npm install -g jsxhint`'
7
+ end
8
+
9
+ result = execute(%w[jsxhint] + applicable_files)
10
+ output = result.stdout
11
+
12
+ return :good if output.empty?
13
+
14
+ [:bad, output]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Checks for local paths in files and issues a warning
3
+ class LocalPathsInGemfile < Base
4
+ def run
5
+ result = execute(%w[grep -IHnE (\s*path:\s*)|(\s*:path\s*=>)] + applicable_files)
6
+
7
+ unless result.stdout.empty?
8
+ return :warn, "Avoid pointing to local paths in Gemfiles:\n#{result.stdout}"
9
+ end
10
+
11
+ :good
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Checks for unresolved merge conflicts
3
+ class MergeConflicts < Base
4
+ def run
5
+ result = execute(%w[grep -IHn ^<<<<<<<\s] + applicable_files)
6
+
7
+ unless result.stdout.empty?
8
+ return :bad, "Merge conflict markers detected:\n#{result.stdout}"
9
+ end
10
+
11
+ :good
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Adds a check to make sure no `binding.pry`'s have been left in the code
3
+ class PryBinding < Base
4
+ def run
5
+ result = execute(%w[grep -IHnE ^\s*binding\.pry] + applicable_files)
6
+
7
+ unless result.stdout.empty?
8
+ return :bad, "Found a `binding.pry` call left in:\n#{result.stdout}"
9
+ end
10
+
11
+ :good
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Check to see whether the schema file is in line with the migrations
3
+ class RailsSchemaUpToDate < Base
4
+ def run
5
+ if migration_files.any? && schema_files.none?
6
+ return :bad, "It looks like you're adding a migration, but did not update the schema file"
7
+ elsif migration_files.none? && schema_files.any?
8
+ return :bad, "You're trying to change the schema without adding a migration file"
9
+ elsif migration_files.any? && schema_files.any?
10
+ latest_version = migration_files.map { |file| file[/\d+/] }.sort.last
11
+ schema = schema_files.map { |file| File.read(file) }.join
12
+ up_to_date = schema.include?(latest_version)
13
+
14
+ unless up_to_date
15
+ return :bad, "The latest migration version you're committing is " \
16
+ "#{latest_version}, but your schema file " \
17
+ "#{schema_files.join(' or ')} is on a different version."
18
+ end
19
+ end
20
+
21
+ :good
22
+ end
23
+
24
+ private
25
+
26
+ def migration_files
27
+ @migration_files ||= applicable_files.select do |file|
28
+ file.match %r{db/migrate/.*\.rb}
29
+ end
30
+ end
31
+
32
+ def schema_files
33
+ @schema_files ||= applicable_files.select do |file|
34
+ file.match %r{db/schema\.rb|db/structure.*\.sql}
35
+ end
36
+ end
37
+ end
38
+ end
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
6
6
  return :warn, 'Rubocop not installed -- run `gem install rubocop`'
7
7
  end
8
8
 
9
- result = execute(%w[rubocop --format=emacs] + applicable_files)
9
+ result = execute(%w[rubocop --format=emacs --force-exclusion] + applicable_files)
10
10
  return :good if result.success?
11
11
 
12
12
  output = result.stdout + result.stderr
@@ -61,7 +61,7 @@ module Overcommit::HookContext
61
61
  #
62
62
  # By default, this returns an empty set. Subclasses should implement if
63
63
  # there is a concept of files changing for the type of hook being run.
64
- def modified_lines(file)
64
+ def modified_lines(_file)
65
65
  Set.new
66
66
  end
67
67
  end
@@ -28,7 +28,7 @@ module Overcommit::HookLoader
28
28
  return if modified_plugins.empty?
29
29
 
30
30
  log.bold_warning "The following #{@context.hook_script_name} plugins " \
31
- "have been added, changed, or had their configuration modified:"
31
+ 'have been added, changed, or had their configuration modified:'
32
32
  log.log
33
33
 
34
34
  modified_plugins.each do |signer|
@@ -3,6 +3,10 @@ module Overcommit
3
3
  class HookSigner
4
4
  attr_reader :hook_path, :hook_name
5
5
 
6
+ # We don't want to include the skip setting as it is set by Overcommit
7
+ # itself
8
+ IGNORED_CONFIG_KEYS = %w[skip]
9
+
6
10
  # @param hook_path [String] path to the actual hook definition
7
11
  # @param config [Overcommit::Configuration]
8
12
  # @param context [Overcommit::HookContext]
@@ -42,7 +46,9 @@ module Overcommit
42
46
  # This way, if either the plugin code changes or its configuration changes,
43
47
  # the hash will change and we can alert the user to this change.
44
48
  def signature
45
- hook_config = @config.for_hook(@hook_name, @context.hook_class_name)
49
+ hook_config = @config.for_hook(@hook_name, @context.hook_class_name).
50
+ dup.
51
+ tap { |config| IGNORED_CONFIG_KEYS.each { |k| config.delete(k) } }
46
52
 
47
53
  Digest::SHA256.hexdigest(hook_contents + hook_config.to_s)
48
54
  end
@@ -9,7 +9,7 @@ module Overcommit
9
9
  end
10
10
 
11
11
  # Get a string of input from the user (up to the next newline character).
12
- def get(&block)
12
+ def get
13
13
  @io.gets
14
14
  end
15
15
 
@@ -19,7 +19,7 @@ module Overcommit
19
19
  def reopen_tty
20
20
  # If the hook isn't interactive, we need to map STDIN to keyboard manually
21
21
  STDIN.reopen('/dev/tty') if STDIN.eof?
22
- rescue
22
+ rescue # rubocop:disable HandleExceptions
23
23
  # Happens in tests run with no console available
24
24
  end
25
25
  end
@@ -72,7 +72,7 @@ module Overcommit
72
72
 
73
73
  # Calls a block of code with a modified set of environment variables,
74
74
  # restoring them once the code has executed.
75
- def with_environment(env, &block)
75
+ def with_environment(env)
76
76
  old_env = {}
77
77
  env.each do |var, value|
78
78
  old_env[var] = ENV[var.to_s]
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module Overcommit
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  end
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.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-18 00:00:00.000000000 Z
12
+ date: 2014-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: 0.5.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '1.8'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '1.8'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rspec
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -85,22 +99,31 @@ files:
85
99
  - lib/overcommit/hook/post_checkout/base.rb
86
100
  - lib/overcommit/hook/base.rb
87
101
  - lib/overcommit/hook/pre_commit/author_email.rb
102
+ - lib/overcommit/hook/pre_commit/pry_binding.rb
88
103
  - lib/overcommit/hook/pre_commit/image_optim.rb
89
104
  - lib/overcommit/hook/pre_commit/css_lint.rb
105
+ - lib/overcommit/hook/pre_commit/jsx_hint.rb
106
+ - lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb
90
107
  - lib/overcommit/hook/pre_commit/travis_lint.rb
91
108
  - lib/overcommit/hook/pre_commit/bundle_check.rb
92
109
  - lib/overcommit/hook/pre_commit/yaml_syntax.rb
110
+ - lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb
111
+ - lib/overcommit/hook/pre_commit/berksfile_check.rb
112
+ - lib/overcommit/hook/pre_commit/merge_conflicts.rb
93
113
  - lib/overcommit/hook/pre_commit/trailing_whitespace.rb
94
114
  - lib/overcommit/hook/pre_commit/author_name.rb
95
115
  - lib/overcommit/hook/pre_commit/rubocop.rb
96
116
  - lib/overcommit/hook/pre_commit/python_flake8.rb
97
117
  - lib/overcommit/hook/pre_commit/js_hint.rb
118
+ - lib/overcommit/hook/pre_commit/chamber_security.rb
98
119
  - lib/overcommit/hook/pre_commit/hard_tabs.rb
99
120
  - lib/overcommit/hook/pre_commit/haml_lint.rb
100
121
  - lib/overcommit/hook/pre_commit/coffee_lint.rb
122
+ - lib/overcommit/hook/pre_commit/brakeman.rb
101
123
  - lib/overcommit/hook/pre_commit/jscs.rb
102
124
  - lib/overcommit/hook/pre_commit/scss_lint.rb
103
125
  - lib/overcommit/hook/pre_commit/base.rb
126
+ - lib/overcommit/hook/pre_commit/json_syntax.rb
104
127
  - lib/overcommit/hook_signer.rb
105
128
  - lib/overcommit/hook_context/pre_commit.rb
106
129
  - lib/overcommit/hook_context/commit_msg.rb