pre-commit 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7355c40a01a77e3e1a80b3aa54e0fad68f14384
4
- data.tar.gz: 523aafecb538cb6ee6212a8aec9b3bb272475c53
3
+ metadata.gz: 782f5d2ee7b13c81a4d4382a7c12490b04f1c17b
4
+ data.tar.gz: d6a4fb5f128b0ab9bb04a4b3964d11c96334576d
5
5
  SHA512:
6
- metadata.gz: 442f543f6a1c50f4346bbb7ff94e0340c255ba81baff3f7a24ed9159f183173302ada1b5dfe92186c86fa587c2501c8318b6483dfbf94f65d032612ed9546f1c
7
- data.tar.gz: 066024f84516424170d618568f1177d8ce34c3293131f348772af247143787033e0082341a9979aa6621470cb6b29b8aae88736e9068f60b0068efff0ec733ab
6
+ metadata.gz: 50cdddbe3e934bb06d4730d50e616d1676e4f36017308e1ce30d549d2054a04cf8cfdcca0b18646e682668baed30eb7d82bf27c5f05ea7e9b42ee12177b14706
7
+ data.tar.gz: b8bc8820e844b36a4344bff7afb97788a9ea72f81369be45b2f972ab3c05de5cc24cabafd05516f346f4c1b8946b2f4641c29a8950ffe6f70e02034733073502
data/README.md CHANGED
@@ -20,7 +20,7 @@ Use the pre-commit command to generate a stub pre-commit hook
20
20
 
21
21
  This creates a .git/hooks/pre-commit script which will check your git config and run checks that are enabled.
22
22
 
23
- ## Configuration
23
+ ## Available checks
24
24
 
25
25
  These are the available checks:
26
26
 
@@ -43,29 +43,52 @@ These are the available checks:
43
43
  * before_all (Check your RSpec tests for the use of `before(:all)`)
44
44
  * coffeelint (Check your coffeescript files using the [coffeelint gem.](https://github.com/clutchski/coffeelint))
45
45
 
46
- To configure which checks you would like to run, simply set the `pre-commit.checks` git configuration setting.
46
+ ## Default checks
47
47
 
48
- To enable `white_space` and `tab` checks:
48
+ Use `pre-commit list` to see the list of default and enabled checks and warnings.
49
49
 
50
- # From your git repo
51
- $ git config "pre-commit.checks" "white_space, tabs"
50
+ ## Enabling / Disabling Checks / Warnings
52
51
 
53
- To enable `white_space`, `console_log` and `debugger` checks:
52
+ ### 0.12.0 and lower
54
53
 
55
- # From your git repo
56
- $ git config "pre-commit.checks" "white_space, console_log, debugger"
54
+ git config pre-commit.checks "whitespace, jshint, debugger"
57
55
 
58
- Note: If no checks are configured, a default set of checks is run:
56
+ To disable, simply leave one off the list
59
57
 
60
- white_space, console_log, debugger, pry, tabs, jshint, migrations, merge_conflict, local
58
+ git config pre-commit.checks "whitespace, jshint"
61
59
 
62
- You may also enable checks that will produce warnings if detected but NOT stop the commit:
60
+ ### 0.13.0 and higher
63
61
 
64
- # From your git repo
65
- $ git config "pre-commit.warnings" "jshint, ruby_symbol_hashrockets"
62
+ ```ssh
63
+ pre-commit <enable|disbale> <git|yaml> <checks|warnings> check1 [check2...]
64
+ ```
66
65
 
66
+ The `git` provider can be used for local machine configuration, the `yaml` can be used for shared
67
+ project configuration.
67
68
 
68
- For the rubocop check, you can tell it what config file to use by setting a path relative to the repo:
69
+ Example move `jshint` from `checks` to `warnings` in `yaml` provider and save configuration to git:
70
+ ```bash
71
+ pre-commit disbale yaml checks jshint
72
+ pre-commit enable yaml warnings jshint
73
+ git add config/pre-commit.yml
74
+ git commit -m "pre-commit: move jshint from checks to warnings"
75
+ ```
69
76
 
70
- # From your git repo
71
- $ git config "pre-commit.rubocop.config" "config/rubocop.yml"
77
+ Example `config/pre_commit.yml`:
78
+ ```yaml
79
+ ---
80
+ :warnings_remove: []
81
+ :warnings_add:
82
+ - :jshint
83
+ - :tabs
84
+ ```
85
+
86
+ ## Configuration providers
87
+
88
+ `pre-commit` comes with 3 configuration providers:
89
+
90
+ - `default` - basic settings, read only
91
+ - `git` - reads configuration from `git config pre-commit.*`, allow local update
92
+ - `yaml` - reads configuration from `/etc/pre-commit.yml`, `$HOME/.pre-commit.yml` and `config/pre-commit.yml`, allows `config/pre-commit.yml` updates
93
+
94
+ ## [Contributing](CONTRIBUTING.md)
data/bin/pre-commit CHANGED
@@ -2,19 +2,8 @@
2
2
 
3
3
  require 'pre-commit/cli'
4
4
 
5
- if ARGV[0] != "install"
6
- abort "Usage: pre-commit install"
7
- end
8
-
9
5
  if !File.exists?(".git")
10
6
  abort "No .git directory found."
11
7
  end
12
8
 
13
- begin
14
- PreCommit::Cli.new.install(ARGV[1])
15
- rescue PreCommit::TemplateNotFound => e
16
- abort e.message
17
- end
18
-
19
- puts "Installed hook: #{PreCommit::Cli::PRE_COMMIT_HOOK_PATH}"
20
- puts
9
+ PreCommit::Cli.new(*ARGV).execute or exit 1
@@ -0,0 +1,26 @@
1
+ require "plugins/pluginator/extensions/conversions"
2
+
3
+ module Pluginator::Extensions
4
+ # Extension to find class or first plugin that answers the question with true or to print warning
5
+ module FindCheck
6
+ include Conversions
7
+
8
+ def find_check(name)
9
+ klass = string2class(name)
10
+ @plugins["checks"].detect do |plugin|
11
+ class2name(plugin) == klass ||
12
+ plugin.respond_to?(:aliases) && plugin.public_send(:aliases).include?(name.to_sym)
13
+ end ||
14
+ begin
15
+ $stderr.puts "Could not find plugin supporting #{name} / #{klass},
16
+ available plugins: #{available_plugins}"
17
+ nil
18
+ end
19
+ end
20
+
21
+ def available_plugins
22
+ @plugins["checks"].map{|plugin| class2name(plugin) }.join(", ")
23
+ end
24
+
25
+ end
26
+ end
@@ -1,13 +1,29 @@
1
+ require 'pre-commit/checks/grep'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class BeforeAll
4
- def self.call(staged_files)
5
- staged_files.reject! { |f| File.extname(f) != ".rb" }
6
- return if staged_files.empty?
7
- errors = `#{PreCommit::Utils.grep} -e "before.*:all" #{staged_files.join(" ")} | grep -v \/\/`.strip
8
- return unless $?.success?
9
- "before(:all) found:\n#{errors}"
5
+ class BeforeAll < Grep
6
+
7
+ def files_filter(staged_files)
8
+ staged_files.grep(/\.rb$/)
10
9
  end
10
+
11
+ def extra_grep
12
+ " | grep -v \/\/"
13
+ end
14
+
15
+ def message
16
+ "before(:all) found:\n"
17
+ end
18
+
19
+ def pattern
20
+ '-e "before.*:all"'
21
+ end
22
+
23
+ def self.description
24
+ "Find ruby files with 'before :all' pattern"
25
+ end
26
+
11
27
  end
12
28
  end
13
29
  end
@@ -1,12 +1,19 @@
1
+ require 'pre-commit/checks/plugin'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class Ci
5
+ class Ci < Plugin
4
6
  CI_TASK_NAME = 'pre_commit:ci'
5
7
 
6
- def self.call(_)
7
- return if system("rake #{CI_TASK_NAME} --silent")
8
+ def call(_)
9
+ return if system("rake #{Ci::CI_TASK_NAME} --silent")
8
10
  "your test suite has failed, for the full output run `#{CI_TASK_NAME}`"
9
11
  end
12
+
13
+ def self.description
14
+ "Runs 'rake #{CI_TASK_NAME} --silent'"
15
+ end
16
+
10
17
  end
11
18
  end
12
19
  end
@@ -1,19 +1,27 @@
1
+ require 'pre-commit/checks/plugin'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class Closure
5
+ class Closure < Plugin
4
6
  #TODO: add pluginator assets support
5
7
  CLOSURE_PATH = File.expand_path("../../../../pre-commit/support/closure/compiler.jar", __FILE__)
6
8
 
7
- def self.supports(name)
8
- name == :closure_syntax_check
9
+ def self.aliases
10
+ [:closure_syntax_check]
9
11
  end
10
- def self.call(staged_files)
12
+
13
+ def call(staged_files)
11
14
  return if staged_files.empty?
12
15
  js_args = staged_files.map {|arg| "--js #{arg}"}.join(' ')
13
16
  errors = `java -jar #{CLOSURE_PATH} #{js_args} --js_output_file /tmp/jammit.js 2>&1`.strip
14
17
  return if errors.empty?
15
18
  errors
16
19
  end
20
+
21
+ def self.description
22
+ "Runs closure compiler to detect errors"
23
+ end
24
+
17
25
  end
18
26
  end
19
27
  end
@@ -1,11 +1,11 @@
1
- require 'pre-commit/utils'
2
- require 'stringio'
3
1
  require 'open3'
2
+ require 'pre-commit/checks/plugin'
4
3
 
5
4
  module PreCommit
6
5
  module Checks
7
- class Coffeelint
8
- def self.call(staged_files)
6
+ class Coffeelint < Plugin
7
+
8
+ def call(staged_files)
9
9
  staged_files = staged_files.grep(/\.coffee$/)
10
10
  return if staged_files.empty?
11
11
 
@@ -14,6 +14,11 @@ module PreCommit
14
14
  stdout, stderr, result = Open3.capture3("coffeelint #{args}")
15
15
  stdout + stderr unless result.success?
16
16
  end
17
+
18
+ def self.description
19
+ "Runs coffeelint to detect errors"
20
+ end
21
+
17
22
  end
18
23
  end
19
24
  end
@@ -0,0 +1,17 @@
1
+ require 'pre-commit/checks/plugin'
2
+
3
+ module PreCommit
4
+ module Checks
5
+ class Common < Plugin
6
+
7
+ def self.includes
8
+ [:tabs, :nb_space, :whitespace, :merge_conflict, :debugger]
9
+ end
10
+
11
+ def self.description
12
+ "Plugins common for all languages."
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -1,13 +1,29 @@
1
+ require 'pre-commit/checks/grep'
2
+
1
3
  module PreCommit
2
4
  module Checks
3
- class ConsoleLog
4
- def self.call(staged_files)
5
- staged_files.reject! { |f| File.extname(f) != ".js" }
6
- return if staged_files.empty?
7
- errors = `#{PreCommit::Utils.grep} -e "console\\.log" #{staged_files.join(" ")} | grep -v \/\/`.strip
8
- return unless $?.success?
9
- "console.log found:\n#{errors}"
5
+ class ConsoleLog < Grep
6
+
7
+ def files_filter(staged_files)
8
+ staged_files.grep(/\.js$/)
10
9
  end
10
+
11
+ def extra_grep
12
+ " | grep -v \/\/"
13
+ end
14
+
15
+ def message
16
+ "console.log found:\n"
17
+ end
18
+
19
+ def pattern
20
+ '-e "console\\.log"'
21
+ end
22
+
23
+ def self.description
24
+ "Finds javascript files with 'console.log'."
25
+ end
26
+
11
27
  end
12
28
  end
13
29
  end
@@ -0,0 +1,32 @@
1
+ require 'pre-commit/checks/js'
2
+
3
+ module PreCommit
4
+ module Checks
5
+ class Csslint < Js
6
+
7
+ SOURCE = "https://github.com/stubbornella/csslint/blob/v0.10.0/release/csslint.js"
8
+
9
+ def run_check(file)
10
+ context = ExecJS.compile(File.read(linter_src))
11
+ context.call("CSSLint.verify", File.read(file))["messages"]
12
+ end
13
+
14
+ def linter_src
15
+ File.expand_path("../../../../pre-commit/support/csslint/csslint.js", __FILE__)
16
+ end
17
+
18
+ def error_selector
19
+ 'message'
20
+ end
21
+
22
+ def files_filter(staged_files)
23
+ staged_files.grep(/\.css$/)
24
+ end
25
+
26
+ def self.description
27
+ "Checks CSS files with CSSLint."
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,21 +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 Debugger
6
- def self.call(staged_files)
7
- files = files_to_check(staged_files)
8
- return if files.empty?
5
+ class Debugger < Grep
9
6
 
10
- errors = `#{PreCommit::Utils.grep} debugger #{files.join(" ")}`.strip
11
- return unless $?.success?
7
+ def files_filter(staged_files)
8
+ staged_files.reject { |file| File.basename(file) =~ /^Gemfile/ }
9
+ end
10
+
11
+ def message
12
+ "debugger statement(s) found:\n"
13
+ end
12
14
 
13
- "debugger statement(s) found:\n#{errors}"
15
+ def pattern
16
+ 'debugger'
14
17
  end
15
18
 
16
- def self.files_to_check(files)
17
- files.reject { |file| File.basename(file) =~ /^Gemfile/ }
19
+ def self.description
20
+ "Finds files with 'debuger'."
18
21
  end
22
+
19
23
  end
20
24
  end
21
25
  end
@@ -1,14 +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 GemfilePath
6
- def self.call(staged_files)
7
- return unless staged_files.include?("Gemfile")
8
- errors = `#{PreCommit::Utils.grep} 'path:|:path\\s*=>' Gemfile`.strip
9
- return unless $?.success?
10
- "local path found in Gemfile:\n#{errors}"
5
+ class GemfilePath < Grep
6
+
7
+ def files_filter(staged_files)
8
+ staged_files.grep(/^Gemfile$/)
9
+ end
10
+
11
+ def message
12
+ "local path found in Gemfile:\n"
13
+ end
14
+
15
+ def pattern
16
+ "'path:|:path\\s*=>'"
17
+ end
18
+
19
+ def self.description
20
+ "Checks 'Gemfile' for local paths."
11
21
  end
22
+
12
23
  end
13
24
  end
14
25
  end
@@ -1,9 +1,10 @@
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 Jshint < Js
6
- def self.config
6
+
7
+ def config
7
8
  if config_file = [ENV['JSHINT_CONFIG'], ".jshintrc"].compact.detect { |f| File.exist?(f) }
8
9
  ExecJS.exec("return (#{File.read(config_file)});")
9
10
  else
@@ -11,14 +12,19 @@ module PreCommit
11
12
  end
12
13
  end
13
14
 
14
- def self.run_check(file)
15
+ def run_check(file)
15
16
  context = ExecJS.compile(File.read(linter_src))
16
17
  context.call("JSHINT", File.read(file), config, config["globals"])
17
18
  end
18
19
 
19
- def self.linter_src
20
+ def linter_src
20
21
  File.expand_path("../../../../pre-commit/support/jshint/jshint.js", __FILE__)
21
22
  end
23
+
24
+ def self.description
25
+ "Checks javascript files with JSHint."
26
+ end
27
+
22
28
  end
23
29
  end
24
30
  end