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.
- checksums.yaml +4 -4
- data/README.md +39 -16
- data/bin/pre-commit +1 -12
- data/lib/plugins/pluginator/extensions/find_check.rb +26 -0
- data/lib/plugins/pre_commit/checks/before_all.rb +23 -7
- data/lib/plugins/pre_commit/checks/ci.rb +10 -3
- data/lib/plugins/pre_commit/checks/closure.rb +12 -4
- data/lib/plugins/pre_commit/checks/coffeelint.rb +9 -4
- data/lib/plugins/pre_commit/checks/common.rb +17 -0
- data/lib/plugins/pre_commit/checks/console_log.rb +23 -7
- data/lib/plugins/pre_commit/checks/csslint.rb +32 -0
- data/lib/plugins/pre_commit/checks/debugger.rb +14 -10
- data/lib/plugins/pre_commit/checks/gemfile_path.rb +18 -7
- data/lib/plugins/pre_commit/checks/jshint.rb +10 -4
- data/lib/plugins/pre_commit/checks/jslint.rb +11 -5
- data/lib/plugins/pre_commit/checks/local.rb +10 -2
- data/lib/plugins/pre_commit/checks/merge_conflict.rb +15 -6
- data/lib/plugins/pre_commit/checks/migration.rb +32 -26
- data/lib/plugins/pre_commit/checks/nb_space.rb +10 -2
- data/lib/plugins/pre_commit/checks/php.rb +10 -4
- data/lib/plugins/pre_commit/checks/pry.rb +15 -6
- data/lib/plugins/pre_commit/checks/rails.rb +17 -0
- data/lib/plugins/pre_commit/checks/rspec_focus.rb +19 -7
- data/lib/plugins/pre_commit/checks/rubocop.rb +20 -8
- data/lib/plugins/pre_commit/checks/ruby.rb +17 -0
- data/lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb +17 -8
- data/lib/plugins/pre_commit/checks/tabs.rb +15 -8
- data/lib/plugins/pre_commit/checks/whitespace.rb +28 -5
- data/lib/plugins/pre_commit/configuration/providers/README.md +10 -0
- data/lib/plugins/pre_commit/configuration/providers/default.rb +34 -0
- data/lib/plugins/pre_commit/configuration/providers/git.rb +26 -0
- data/lib/plugins/pre_commit/configuration/providers/git_old.rb +28 -0
- data/lib/plugins/pre_commit/configuration/providers/yaml.rb +67 -0
- data/lib/pre-commit.rb +28 -1
- data/lib/pre-commit/checks.rb +1 -98
- data/lib/pre-commit/checks/grep.rb +57 -0
- data/lib/{plugins/pre_commit → pre-commit}/checks/js.rb +15 -7
- data/lib/pre-commit/checks/plugin.rb +13 -0
- data/lib/pre-commit/cli.rb +46 -19
- data/lib/pre-commit/configuration.rb +54 -0
- data/lib/pre-commit/configuration/providers.rb +53 -0
- data/lib/pre-commit/installer.rb +54 -0
- data/lib/pre-commit/list_evaluator.rb +85 -0
- data/lib/pre-commit/plugins_list.rb +87 -0
- data/lib/pre-commit/runner.rb +54 -9
- data/lib/pre-commit/support/csslint/csslint.js +9259 -0
- data/lib/pre-commit/utils/git_conversions.rb +56 -0
- data/lib/pre-commit/utils/staged_files.rb +21 -0
- metadata +47 -30
- data/lib/pre-commit/support/templates/automatic_hook +0 -35
- data/lib/pre-commit/support/templates/default_hook +0 -35
- data/lib/pre-commit/support/templates/manual_hook +0 -14
- data/lib/pre-commit/utils.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 782f5d2ee7b13c81a4d4382a7c12490b04f1c17b
|
4
|
+
data.tar.gz: d6a4fb5f128b0ab9bb04a4b3964d11c96334576d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
##
|
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
|
-
|
46
|
+
## Default checks
|
47
47
|
|
48
|
-
|
48
|
+
Use `pre-commit list` to see the list of default and enabled checks and warnings.
|
49
49
|
|
50
|
-
|
51
|
-
$ git config "pre-commit.checks" "white_space, tabs"
|
50
|
+
## Enabling / Disabling Checks / Warnings
|
52
51
|
|
53
|
-
|
52
|
+
### 0.12.0 and lower
|
54
53
|
|
55
|
-
|
56
|
-
$ git config "pre-commit.checks" "white_space, console_log, debugger"
|
54
|
+
git config pre-commit.checks "whitespace, jshint, debugger"
|
57
55
|
|
58
|
-
|
56
|
+
To disable, simply leave one off the list
|
59
57
|
|
60
|
-
|
58
|
+
git config pre-commit.checks "whitespace, jshint"
|
61
59
|
|
62
|
-
|
60
|
+
### 0.13.0 and higher
|
63
61
|
|
64
|
-
|
65
|
-
|
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
|
-
|
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
|
-
|
71
|
-
|
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
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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
|
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.
|
8
|
-
|
9
|
+
def self.aliases
|
10
|
+
[:closure_syntax_check]
|
9
11
|
end
|
10
|
-
|
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
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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/
|
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
|
-
|
11
|
-
|
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
|
-
|
15
|
+
def pattern
|
16
|
+
'debugger'
|
14
17
|
end
|
15
18
|
|
16
|
-
def self.
|
17
|
-
files
|
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/
|
1
|
+
require 'pre-commit/checks/grep'
|
2
2
|
|
3
3
|
module PreCommit
|
4
4
|
module Checks
|
5
|
-
class GemfilePath
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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 '
|
1
|
+
require 'pre-commit/checks/js'
|
2
2
|
|
3
3
|
module PreCommit
|
4
4
|
module Checks
|
5
5
|
class Jshint < Js
|
6
|
-
|
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
|
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
|
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
|