pre-commit 0.12.0 → 0.13.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -16
  3. data/bin/pre-commit +1 -12
  4. data/lib/plugins/pluginator/extensions/find_check.rb +26 -0
  5. data/lib/plugins/pre_commit/checks/before_all.rb +23 -7
  6. data/lib/plugins/pre_commit/checks/ci.rb +10 -3
  7. data/lib/plugins/pre_commit/checks/closure.rb +12 -4
  8. data/lib/plugins/pre_commit/checks/coffeelint.rb +9 -4
  9. data/lib/plugins/pre_commit/checks/common.rb +17 -0
  10. data/lib/plugins/pre_commit/checks/console_log.rb +23 -7
  11. data/lib/plugins/pre_commit/checks/csslint.rb +32 -0
  12. data/lib/plugins/pre_commit/checks/debugger.rb +14 -10
  13. data/lib/plugins/pre_commit/checks/gemfile_path.rb +18 -7
  14. data/lib/plugins/pre_commit/checks/jshint.rb +10 -4
  15. data/lib/plugins/pre_commit/checks/jslint.rb +11 -5
  16. data/lib/plugins/pre_commit/checks/local.rb +10 -2
  17. data/lib/plugins/pre_commit/checks/merge_conflict.rb +15 -6
  18. data/lib/plugins/pre_commit/checks/migration.rb +32 -26
  19. data/lib/plugins/pre_commit/checks/nb_space.rb +10 -2
  20. data/lib/plugins/pre_commit/checks/php.rb +10 -4
  21. data/lib/plugins/pre_commit/checks/pry.rb +15 -6
  22. data/lib/plugins/pre_commit/checks/rails.rb +17 -0
  23. data/lib/plugins/pre_commit/checks/rspec_focus.rb +19 -7
  24. data/lib/plugins/pre_commit/checks/rubocop.rb +20 -8
  25. data/lib/plugins/pre_commit/checks/ruby.rb +17 -0
  26. data/lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb +17 -8
  27. data/lib/plugins/pre_commit/checks/tabs.rb +15 -8
  28. data/lib/plugins/pre_commit/checks/whitespace.rb +28 -5
  29. data/lib/plugins/pre_commit/configuration/providers/README.md +10 -0
  30. data/lib/plugins/pre_commit/configuration/providers/default.rb +34 -0
  31. data/lib/plugins/pre_commit/configuration/providers/git.rb +26 -0
  32. data/lib/plugins/pre_commit/configuration/providers/git_old.rb +28 -0
  33. data/lib/plugins/pre_commit/configuration/providers/yaml.rb +67 -0
  34. data/lib/pre-commit.rb +28 -1
  35. data/lib/pre-commit/checks.rb +1 -98
  36. data/lib/pre-commit/checks/grep.rb +57 -0
  37. data/lib/{plugins/pre_commit → pre-commit}/checks/js.rb +15 -7
  38. data/lib/pre-commit/checks/plugin.rb +13 -0
  39. data/lib/pre-commit/cli.rb +46 -19
  40. data/lib/pre-commit/configuration.rb +54 -0
  41. data/lib/pre-commit/configuration/providers.rb +53 -0
  42. data/lib/pre-commit/installer.rb +54 -0
  43. data/lib/pre-commit/list_evaluator.rb +85 -0
  44. data/lib/pre-commit/plugins_list.rb +87 -0
  45. data/lib/pre-commit/runner.rb +54 -9
  46. data/lib/pre-commit/support/csslint/csslint.js +9259 -0
  47. data/lib/pre-commit/utils/git_conversions.rb +56 -0
  48. data/lib/pre-commit/utils/staged_files.rb +21 -0
  49. metadata +47 -30
  50. data/lib/pre-commit/support/templates/automatic_hook +0 -35
  51. data/lib/pre-commit/support/templates/default_hook +0 -35
  52. data/lib/pre-commit/support/templates/manual_hook +0 -14
  53. data/lib/pre-commit/utils.rb +0 -27
@@ -1,13 +1,14 @@
1
- require 'plugins/pre_commit/checks/js'
1
+ require 'pre-commit/checks/js'
2
2
 
3
3
  module PreCommit
4
4
  module Checks
5
5
  class Jslint < Js
6
- def self.supports(name)
7
- [ :js_lint, :js_lint_all, :js_lint_new ].include?(name)
6
+
7
+ def self.aliases
8
+ [ :js_lint, :js_lint_all, :js_lint_new ]
8
9
  end
9
10
 
10
- def self.run_check(file)
11
+ def run_check(file)
11
12
  context = ExecJS.compile(File.read(linter_src))
12
13
  if !(context.call('JSLINT', File.read(file)))
13
14
  context.exec('return JSLINT.errors;')
@@ -16,9 +17,14 @@ module PreCommit
16
17
  end
17
18
  end
18
19
 
19
- def self.linter_src
20
+ def linter_src
20
21
  File.expand_path("../../../../pre-commit/support/jslint/lint.js", __FILE__)
21
22
  end
23
+
24
+ def self.description
25
+ "Checks javascript files with JSLint."
26
+ end
27
+
22
28
  end
23
29
  end
24
30
  end
@@ -1,13 +1,21 @@
1
+ require 'pre-commit/checks/plugin'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class Local
5
+ class Local < Plugin
6
+
4
7
  DEFAULT_LOCATION = "config/pre-commit.rb"
5
8
 
6
- def self.call(staged_files, script=DEFAULT_LOCATION)
9
+ def call(staged_files, script=Local::DEFAULT_LOCATION)
7
10
  return unless File.exist?(script)
8
11
  output = `ruby #{script} #{staged_files.join(" ")} 2>&1`
9
12
  "#{script} failed:\n#{output}" unless $?.success?
10
13
  end
14
+
15
+ def self.description
16
+ "Executes 'ruby #{DEFAULT_LOCATION}'."
17
+ end
18
+
11
19
  end
12
20
  end
13
21
  end
@@ -1,12 +1,21 @@
1
+ require 'pre-commit/checks/grep'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class MergeConflict
4
- def self.call(staged_files)
5
- return if staged_files.empty?
6
- errors = `#{PreCommit::Utils.grep} '<<<<<<<' #{staged_files.join(" ")}`.strip
7
- return unless $?.success?
8
- "detected a merge conflict\n#{errors}"
5
+ class MergeConflict < Grep
6
+
7
+ def message
8
+ "detected a merge conflict\n"
9
9
  end
10
+
11
+ def pattern
12
+ "'<<<<<<<'"
13
+ end
14
+
15
+ def self.description
16
+ "Finds files with unresolved merge conflicts."
17
+ end
18
+
10
19
  end
11
20
  end
12
21
  end
@@ -1,38 +1,44 @@
1
+ require 'pre-commit/checks/plugin'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class Migration
4
- def self.supports(name)
5
- name == :migrations
5
+ class Migration < Plugin
6
+ def self.aliases
7
+ [:migrations]
6
8
  end
7
- class << self
8
- def call(staged_files)
9
- migration_files = migration_files(staged_files)
10
- schema_files = schema_files(staged_files)
11
-
12
- if migration_files.any? && schema_files.none?
13
- "It looks like you're adding a migration, but did not update the schema file"
14
- elsif migration_files.none? && schema_files.any?
15
- "You're trying to change the schema without adding a migration file"
16
- elsif migration_files.any? && schema_files.any?
17
- versions = migration_files.map { |f| f[/\d+/] }
18
- schema = schema_files.map { |f| File.read(f) }.join
19
- missing_versions = versions.select { |version| !schema.include?(version) }
20
- if missing_versions.any?
21
- "You did not add the schema versions for #{versions.join(', ')} to #{schema_files.join(' or ')}"
22
- end
9
+
10
+ def call(staged_files)
11
+ migration_files = migration_files(staged_files)
12
+ schema_files = schema_files(staged_files)
13
+
14
+ if migration_files.any? && schema_files.none?
15
+ "It looks like you're adding a migration, but did not update the schema file"
16
+ elsif migration_files.none? && schema_files.any?
17
+ "You're trying to change the schema without adding a migration file"
18
+ elsif migration_files.any? && schema_files.any?
19
+ versions = migration_files.map { |f| f[/\d+/] }
20
+ schema = schema_files.map { |f| File.read(f) }.join
21
+ missing_versions = versions.select { |version| !schema.include?(version) }
22
+ if missing_versions.any?
23
+ "You did not add the schema versions for #{versions.join(', ')} to #{schema_files.join(' or ')}"
23
24
  end
24
25
  end
26
+ end
25
27
 
26
- private
28
+ private
27
29
 
28
- def migration_files(staged_files)
29
- staged_files.grep(/db\/migrate\/.*\.rb/)
30
- end
30
+ def migration_files(staged_files)
31
+ staged_files.grep(/db\/migrate\/.*\.rb/)
32
+ end
31
33
 
32
- def schema_files(staged_files)
33
- staged_files.select { |f| File.basename(f) =~ /schema\.rb|structure.*\.sql/ }
34
- end
34
+ def schema_files(staged_files)
35
+ staged_files.select { |f| File.basename(f) =~ /schema\.rb|structure.*\.sql/ }
35
36
  end
37
+
38
+ def self.description
39
+ "Detects rails database migrations and schema incompatibilities."
40
+ end
41
+
36
42
  end
37
43
  end
38
44
  end
@@ -1,8 +1,11 @@
1
1
  # encoding: utf-8
2
+ require 'pre-commit/checks/plugin'
3
+
2
4
  module PreCommit
3
5
  module Checks
4
- class NbSpace
5
- def self.call(staged_files)
6
+ class NbSpace < Plugin
7
+
8
+ def call(staged_files)
6
9
  nb_space = " "
7
10
  raise "you messed that up" unless nb_space.bytes.to_a == [194, 160]
8
11
 
@@ -18,6 +21,11 @@ module PreCommit
18
21
  return if bad.empty?
19
22
  "Detected non-breaking space in #{bad.map { |f,l,c| "#{f}:#{l+1} character:#{c+1}" }.join(" and")}, remove it!"
20
23
  end
24
+
25
+ def self.description
26
+ "Detected non-breaking spaces 194, 160."
27
+ end
28
+
21
29
  end
22
30
  end
23
31
  end
@@ -1,9 +1,10 @@
1
- require 'pre-commit/utils'
1
+ require 'pre-commit/checks/plugin'
2
2
 
3
3
  module PreCommit
4
4
  module Checks
5
- class Php
6
- def self.call(staged_files)
5
+ class Php < Plugin
6
+
7
+ def call(staged_files)
7
8
  staged_files = staged_files.grep /\.(php|engine|theme|install|inc|module|test)$/
8
9
  return if staged_files.empty?
9
10
 
@@ -13,7 +14,7 @@ module PreCommit
13
14
  errors.join("\n")
14
15
  end
15
16
 
16
- def self.run_check(file)
17
+ def run_check(file)
17
18
  # We force PHP to display errors otherwise they will likely end up in the
18
19
  # error_log and not in stdout.
19
20
  result = `php -d display_errors=1 -l #{file} 2>&1`
@@ -22,6 +23,11 @@ module PreCommit
22
23
  # If PHP exited non-zero then there was a parse error.
23
24
  result.strip unless $? == 0
24
25
  end
26
+
27
+ def self.description
28
+ "Detects PHP errors."
29
+ end
30
+
25
31
  end
26
32
  end
27
33
  end
@@ -1,12 +1,21 @@
1
+ require 'pre-commit/checks/grep'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class Pry
4
- def self.call(staged_files)
5
- return if staged_files.empty?
6
- result = `#{PreCommit::Utils.grep} binding.pry #{staged_files.join(" ")}`.strip
7
- return unless $?.success?
8
- "binding.pry found:\n#{result}"
5
+ class Pry < Grep
6
+
7
+ def message
8
+ "binding.pry found:\n"
9
9
  end
10
+
11
+ def pattern
12
+ "binding\.pry"
13
+ end
14
+
15
+ def self.description
16
+ "Finds files with 'binding.pry'."
17
+ end
18
+
10
19
  end
11
20
  end
12
21
  end
@@ -0,0 +1,17 @@
1
+ require 'pre-commit/checks/plugin'
2
+
3
+ module PreCommit
4
+ module Checks
5
+ class Rails < Plugin
6
+
7
+ def self.includes
8
+ [:ruby, :jshint, :console_log, :migration]
9
+ end
10
+
11
+ def self.description
12
+ "Plugins common for ruby on rails."
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -1,13 +1,25 @@
1
+ require 'pre-commit/checks/grep'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class RspecFocus
4
- def self.call(staged_files)
5
- staged_files = staged_files.grep(/_spec\.rb$/)
6
- return if staged_files.empty?
7
- result = `#{PreCommit::Utils.grep} ':focus' #{staged_files.join(" ")}`.strip
8
- return unless $?.success?
9
- ":focus found in specs:\n#{result}"
5
+ class RspecFocus < Grep
6
+
7
+ def files_filter(staged_files)
8
+ staged_files.grep(/_spec\.rb$/)
10
9
  end
10
+
11
+ def message
12
+ ":focus found in specs:\n"
13
+ end
14
+
15
+ def pattern
16
+ "':focus'"
17
+ end
18
+
19
+ def self.description
20
+ "Finds ruby specs with ':focus'."
21
+ end
22
+
11
23
  end
12
24
  end
13
25
  end
@@ -1,20 +1,26 @@
1
- require 'pre-commit/utils'
2
1
  require 'stringio'
2
+ require 'pre-commit/checks/plugin'
3
3
 
4
4
  module PreCommit
5
5
  module Checks
6
- class Rubocop
7
- def self.supports(name)
8
- [ :rubocop_all, :rubocop_new ].include?(name)
6
+ class Rubocop < Plugin
7
+
8
+ def self.aliases
9
+ [ :rubocop_all, :rubocop_new ]
10
+ end
11
+
12
+ def self.excludes
13
+ [ :ruby_symbol_hashrocket ]
9
14
  end
10
- def self.call(staged_files)
15
+
16
+ def call(staged_files)
11
17
  require 'rubocop'
12
18
  rescue LoadError => e
13
19
  $stderr.puts "Could not find rubocop: #{e}"
14
20
  else
15
21
  staged_files = staged_files.grep(/\.rb$/)
16
22
  return if staged_files.empty?
17
- config_file = `git config pre-commit.rubocop.config`.chomp
23
+ config_file = config.get_combined('rubocop.config')
18
24
 
19
25
  args = staged_files
20
26
  if !config_file.empty?
@@ -22,17 +28,19 @@ module PreCommit
22
28
  $stderr.puts "Warning: rubocop config file '" + config_file + "' does not exist"
23
29
  $stderr.puts "Set the path to the config file using:"
24
30
  $stderr.puts "\tgit config pre-commit.rubocop.config 'path/relative/to/git/dir/rubocop.yml'"
31
+ $stderr.puts "Or in 'config/pre-commit.yml':"
32
+ $stderr.puts "\trubocop.config: path/relative/to/git/dir/rubocop.yml"
25
33
  $stderr.puts "rubocop will use its default configuration or look for a .rubocop.yml file\n\n"
26
34
  else
27
35
  args = ['-c', config_file] + args
28
36
  end
29
37
  end
30
38
 
31
- success, captured = capture { Rubocop::CLI.new.run(args) == 0 }
39
+ success, captured = capture { ::Rubocop::CLI.new.run(args) == 0 }
32
40
  captured unless success
33
41
  end
34
42
 
35
- def self.capture
43
+ def capture
36
44
  $stdout, stdout = StringIO.new, $stdout
37
45
  $stderr, stderr = StringIO.new, $stderr
38
46
  result = yield
@@ -41,6 +49,10 @@ module PreCommit
41
49
  $stdout = stdout
42
50
  $stderr = stderr
43
51
  end
52
+
53
+ def self.description
54
+ "Runs rubocop to detect errors."
55
+ end
44
56
  end
45
57
  end
46
58
  end
@@ -0,0 +1,17 @@
1
+ require 'pre-commit/checks/plugin'
2
+
3
+ module PreCommit
4
+ module Checks
5
+ class Ruby < Plugin
6
+
7
+ def self.includes
8
+ [:pry, :local]
9
+ end
10
+
11
+ def self.description
12
+ "Plugins common for ruby."
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -1,16 +1,25 @@
1
- require 'pre-commit/utils'
1
+ require 'pre-commit/checks/grep'
2
2
 
3
3
  module PreCommit
4
4
  module Checks
5
- class RubySymbolHashrockets
6
- HASHROCKET_PATTERN = '[^:](:{1}(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*)'
5
+ class RubySymbolHashrockets < Grep
7
6
 
8
- def self.call(staged_files)
9
- return if staged_files.empty?
10
- lines = `#{PreCommit::Utils.grep} '#{HASHROCKET_PATTERN}' #{staged_files.join(" ")}`.strip
11
- return unless $?.success?
12
- "detected :symbol => value hashrocket:\n#{lines}"
7
+ def files_filter(staged_files)
8
+ staged_files.grep(/\.rb$/)
13
9
  end
10
+
11
+ def message
12
+ "detected :symbol => value hashrocket:\n"
13
+ end
14
+
15
+ def pattern
16
+ '\'[^:](:{1}(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*)\''
17
+ end
18
+
19
+ def self.description
20
+ "Finds ruby 1.8 '=>' hash definitions."
21
+ end
22
+
14
23
  end
15
24
  end
16
25
  end
@@ -1,14 +1,21 @@
1
+ require 'pre-commit/checks/grep'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class Tabs
4
- LEADING_TAB_PATTERN = '^ *\t'
5
-
6
- def self.call(staged_files)
7
- return if staged_files.empty?
8
- errors = `#{PreCommit::Utils.grep} '#{LEADING_TAB_PATTERN}' #{staged_files.join(" ")}`.strip
9
- return unless $?.success?
10
- "detected tab before initial space:\n#{errors}"
5
+ class Tabs < Grep
6
+
7
+ def message
8
+ "detected tab before initial space:\n"
9
+ end
10
+
11
+ def pattern
12
+ "'^ *\t'"
11
13
  end
14
+
15
+ def self.description
16
+ "Finds ruby files with tabulation character before text in line."
17
+ end
18
+
12
19
  end
13
20
  end
14
21
  end