pre-commit 0.14.1 → 0.15.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 +2 -1
- data/lib/plugins/pre_commit/checks/coffeelint.rb +9 -1
- data/lib/plugins/pre_commit/checks/jshint.rb +7 -3
- data/lib/plugins/pre_commit/checks/rubocop.rb +10 -15
- data/lib/plugins/pre_commit/configuration/providers/env.rb +26 -0
- data/lib/pre-commit/checks/plugin.rb +20 -0
- data/lib/pre-commit/checks/plugin/config_file.rb +68 -0
- metadata +25 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b3925dbdc545f62cd3ac2f1ecc78e95f79ba2be
|
4
|
+
data.tar.gz: 3fb7a0973a89765ac6ddd1898c8a2d379759ad6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 052c70e54f7833c4adb7094cdfd73ea90664046f8af25d9a8c2cb50a933de025bad522a7872c23e08639ba485f5a43d36ec037117d3d6297a2f422daa13938e6
|
7
|
+
data.tar.gz: e6d37cbb422edd64b9714947904452963e9e1272dccbb2a98886646e8b75e2a6846ba67fcac40aa20e1a95025242d8565289b2b6be250a5f2053d941052cc2ed
|
data/README.md
CHANGED
@@ -86,10 +86,11 @@ Example `config/pre_commit.yml`:
|
|
86
86
|
|
87
87
|
## Configuration providers
|
88
88
|
|
89
|
-
`pre-commit` comes with
|
89
|
+
`pre-commit` comes with 4 configuration providers:
|
90
90
|
|
91
91
|
- `default` - basic settings, read only
|
92
92
|
- `git` - reads configuration from `git config pre-commit.*`, allow local update
|
93
93
|
- `yaml` - reads configuration from `/etc/pre-commit.yml`, `$HOME/.pre-commit.yml` and `config/pre-commit.yml`, allows `config/pre-commit.yml` updates
|
94
|
+
- `env` - reads configuration from environment variables
|
94
95
|
|
95
96
|
## [Contributing](CONTRIBUTING.md)
|
@@ -9,12 +9,20 @@ module PreCommit
|
|
9
9
|
staged_files = staged_files.grep(/\.coffee$/)
|
10
10
|
return if staged_files.empty?
|
11
11
|
|
12
|
-
args = staged_files.join(' ')
|
12
|
+
args = (config_file_flag + staged_files).join(' ')
|
13
13
|
|
14
14
|
stdout, stderr, result = Open3.capture3("coffeelint #{args}")
|
15
15
|
stdout + stderr unless result.success?
|
16
16
|
end
|
17
17
|
|
18
|
+
def config_file_flag
|
19
|
+
config_file ? ['-f', config_file] : []
|
20
|
+
end
|
21
|
+
|
22
|
+
def alternate_config_file
|
23
|
+
'coffeelint.json'
|
24
|
+
end
|
25
|
+
|
18
26
|
def self.description
|
19
27
|
"Runs coffeelint to detect errors"
|
20
28
|
end
|
@@ -4,8 +4,8 @@ module PreCommit
|
|
4
4
|
module Checks
|
5
5
|
class Jshint < Js
|
6
6
|
|
7
|
-
def
|
8
|
-
if config_file
|
7
|
+
def js_config
|
8
|
+
if config_file
|
9
9
|
ExecJS.exec("return (#{File.read(config_file)});")
|
10
10
|
else
|
11
11
|
{}
|
@@ -14,13 +14,17 @@ module PreCommit
|
|
14
14
|
|
15
15
|
def run_check(file)
|
16
16
|
context = ExecJS.compile(File.read(linter_src))
|
17
|
-
context.call("JSHINT", File.read(file),
|
17
|
+
context.call("JSHINT", File.read(file), js_config, js_config["globals"])
|
18
18
|
end
|
19
19
|
|
20
20
|
def linter_src
|
21
21
|
File.expand_path("../../../../pre-commit/support/jshint/jshint.js", __FILE__)
|
22
22
|
end
|
23
23
|
|
24
|
+
def alternate_config_file
|
25
|
+
".jshintrc"
|
26
|
+
end
|
27
|
+
|
24
28
|
def self.description
|
25
29
|
"Checks javascript files with JSHint."
|
26
30
|
end
|
@@ -20,21 +20,8 @@ module PreCommit
|
|
20
20
|
else
|
21
21
|
staged_files = staged_files.grep(/\.rb$/)
|
22
22
|
return if staged_files.empty?
|
23
|
-
|
24
|
-
|
25
|
-
args = staged_files
|
26
|
-
if !config_file.empty?
|
27
|
-
if !File.exist? config_file
|
28
|
-
$stderr.puts "Warning: rubocop config file '" + config_file + "' does not exist"
|
29
|
-
$stderr.puts "Set the path to the config file using:"
|
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"
|
33
|
-
$stderr.puts "rubocop will use its default configuration or look for a .rubocop.yml file\n\n"
|
34
|
-
else
|
35
|
-
args = ['-c', config_file] + args
|
36
|
-
end
|
37
|
-
end
|
23
|
+
|
24
|
+
args = config_file_flag + staged_files
|
38
25
|
|
39
26
|
success, captured = capture { ::Rubocop::CLI.new.run(args) == 0 }
|
40
27
|
captured unless success
|
@@ -50,6 +37,14 @@ module PreCommit
|
|
50
37
|
$stderr = stderr
|
51
38
|
end
|
52
39
|
|
40
|
+
def config_file_flag
|
41
|
+
config_file ? ['-c', config_file] : []
|
42
|
+
end
|
43
|
+
|
44
|
+
def alternate_config_file
|
45
|
+
'.rubocop.yml'
|
46
|
+
end
|
47
|
+
|
53
48
|
def self.description
|
54
49
|
"Runs rubocop to detect errors."
|
55
50
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PreCommit
|
2
|
+
class Configuration
|
3
|
+
class Providers
|
4
|
+
|
5
|
+
class Env
|
6
|
+
def self.priority
|
7
|
+
30
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](name)
|
11
|
+
ENV[key(name)]
|
12
|
+
end
|
13
|
+
|
14
|
+
def update(name, value)
|
15
|
+
ENV[key(name)] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def key(name)
|
21
|
+
name.to_s.upcase.split('.').join('_')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,6 +1,11 @@
|
|
1
|
+
require 'plugins/pluginator/extensions/conversions'
|
2
|
+
require 'pre-commit/checks/plugin/config_file'
|
3
|
+
|
1
4
|
module PreCommit
|
2
5
|
module Checks
|
3
6
|
class Plugin
|
7
|
+
include Pluginator::Extensions::Conversions
|
8
|
+
|
4
9
|
attr_accessor :pluginator, :config
|
5
10
|
|
6
11
|
def initialize(pluginator, config, list)
|
@@ -8,6 +13,21 @@ module PreCommit
|
|
8
13
|
@config = config
|
9
14
|
@list = list
|
10
15
|
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
class2string(class2name(self.class))
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def config_file
|
24
|
+
@config_file ||= ConfigFile.new(name, config, alternate_config_file)
|
25
|
+
@config_file.location
|
26
|
+
end
|
27
|
+
|
28
|
+
def alternate_config_file
|
29
|
+
''
|
30
|
+
end
|
11
31
|
end
|
12
32
|
end
|
13
33
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module PreCommit
|
2
|
+
module Checks
|
3
|
+
class Plugin
|
4
|
+
class ConfigFile
|
5
|
+
def initialize(name, config, alternate_location)
|
6
|
+
@name = name
|
7
|
+
@config = config
|
8
|
+
@alternate_location = alternate_location
|
9
|
+
end
|
10
|
+
|
11
|
+
def location
|
12
|
+
return @location if defined?(@location)
|
13
|
+
|
14
|
+
@location = location_from_config || location_from_alternate
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
attr_reader :name, :config, :alternate_location
|
19
|
+
|
20
|
+
def location_from_config
|
21
|
+
location_from(config_location, true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def location_from_alternate
|
25
|
+
location_from(alternate_location)
|
26
|
+
end
|
27
|
+
|
28
|
+
def location_from(location, show_usage = false)
|
29
|
+
if location && !location.empty?
|
30
|
+
if File.exist?(location)
|
31
|
+
location
|
32
|
+
else
|
33
|
+
usage if show_usage
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def config_location
|
40
|
+
@config_location ||= config.get(property_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def property_name
|
44
|
+
"#{name}.config"
|
45
|
+
end
|
46
|
+
|
47
|
+
def environment_variable_name
|
48
|
+
"#{name.upcase}_CONFIG"
|
49
|
+
end
|
50
|
+
|
51
|
+
def yaml_property_name
|
52
|
+
property_name.gsub(/_/, '.')
|
53
|
+
end
|
54
|
+
|
55
|
+
def usage
|
56
|
+
$stderr.puts "Warning: #{name} config file '#{config_location}' does not exist"
|
57
|
+
$stderr.puts "Set the path to the config file using:"
|
58
|
+
$stderr.puts "\tgit config pre-commit.#{property_name} 'path/relative/to/git/dir/#{name}.config'"
|
59
|
+
$stderr.puts "Or in 'config/pre-commit.yml':"
|
60
|
+
$stderr.puts "\t#{yaml_property_name}: path/relative/to/git/dir/#{name}.config"
|
61
|
+
$stderr.puts "Or set the environment variable:"
|
62
|
+
$stderr.puts "\texport #{environment_variable_name}='path/relative/to/git/dir/#{name}.config'"
|
63
|
+
$stderr.puts "#{name} will look for a configuration file in the project root or use its default behavior.\n\n"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shajith Chacko, Josh Lubaway
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pluginator
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: guard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '4.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '4.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: minitest-reporters
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: A git pre-commit hook written in ruby with a few more tricks up its sleeve
|
@@ -102,7 +102,6 @@ extensions: []
|
|
102
102
|
extra_rdoc_files:
|
103
103
|
- README.md
|
104
104
|
files:
|
105
|
-
- README.md
|
106
105
|
- bin/pre-commit
|
107
106
|
- lib/plugins/pluginator/extensions/find_check.rb
|
108
107
|
- lib/plugins/pre_commit/checks/before_all.rb
|
@@ -130,19 +129,20 @@ files:
|
|
130
129
|
- lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb
|
131
130
|
- lib/plugins/pre_commit/checks/tabs.rb
|
132
131
|
- lib/plugins/pre_commit/checks/whitespace.rb
|
133
|
-
- lib/plugins/pre_commit/configuration/providers/README.md
|
134
132
|
- lib/plugins/pre_commit/configuration/providers/default.rb
|
133
|
+
- lib/plugins/pre_commit/configuration/providers/env.rb
|
135
134
|
- lib/plugins/pre_commit/configuration/providers/git.rb
|
136
135
|
- lib/plugins/pre_commit/configuration/providers/git_old.rb
|
136
|
+
- lib/plugins/pre_commit/configuration/providers/README.md
|
137
137
|
- lib/plugins/pre_commit/configuration/providers/yaml.rb
|
138
|
-
- lib/pre-commit.rb
|
139
|
-
- lib/pre-commit/checks.rb
|
140
138
|
- lib/pre-commit/checks/grep.rb
|
141
139
|
- lib/pre-commit/checks/js.rb
|
140
|
+
- lib/pre-commit/checks/plugin/config_file.rb
|
142
141
|
- lib/pre-commit/checks/plugin.rb
|
142
|
+
- lib/pre-commit/checks.rb
|
143
143
|
- lib/pre-commit/cli.rb
|
144
|
-
- lib/pre-commit/configuration.rb
|
145
144
|
- lib/pre-commit/configuration/providers.rb
|
145
|
+
- lib/pre-commit/configuration.rb
|
146
146
|
- lib/pre-commit/installer.rb
|
147
147
|
- lib/pre-commit/list_evaluator.rb
|
148
148
|
- lib/pre-commit/plugins_list.rb
|
@@ -153,32 +153,34 @@ files:
|
|
153
153
|
- lib/pre-commit/support/jslint/lint.js
|
154
154
|
- lib/pre-commit/utils/git_conversions.rb
|
155
155
|
- lib/pre-commit/utils/staged_files.rb
|
156
|
+
- lib/pre-commit.rb
|
156
157
|
- templates/hooks/automatic
|
157
158
|
- templates/hooks/default
|
158
159
|
- templates/hooks/manual
|
160
|
+
- README.md
|
159
161
|
homepage: http://github.com/jish/pre-commit
|
160
162
|
licenses:
|
161
163
|
- Apache 2.0
|
162
164
|
metadata: {}
|
163
165
|
post_install_message:
|
164
166
|
rdoc_options:
|
165
|
-
-
|
167
|
+
- --main
|
166
168
|
- README.md
|
167
169
|
require_paths:
|
168
170
|
- lib
|
169
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
170
172
|
requirements:
|
171
|
-
- -
|
173
|
+
- - '>='
|
172
174
|
- !ruby/object:Gem::Version
|
173
175
|
version: '0'
|
174
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
177
|
requirements:
|
176
|
-
- -
|
178
|
+
- - '>='
|
177
179
|
- !ruby/object:Gem::Version
|
178
180
|
version: '0'
|
179
181
|
requirements: []
|
180
182
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.1.11
|
182
184
|
signing_key:
|
183
185
|
specification_version: 3
|
184
186
|
summary: A slightly better git pre-commit hook
|