pre-commit 0.15.0 → 0.16.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 +5 -2
- data/lib/plugins/pre_commit/checks/coffeelint.rb +3 -5
- data/lib/plugins/pre_commit/checks/console_log.rb +1 -1
- data/lib/plugins/pre_commit/checks/json.rb +28 -0
- data/lib/plugins/pre_commit/checks/scss_lint.rb +30 -0
- data/lib/plugins/pre_commit/checks/yaml.rb +48 -0
- data/lib/pre-commit/checks/shell.rb +16 -0
- data/lib/pre-commit/cli.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db8f765f2e06da8499568ce2e7c3bd3904a167d
|
4
|
+
data.tar.gz: b597ec14fa63e579dd63caf6edffac6937110ba5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ade68622b31830c6a7a5cb2cb03f211fff4065682b280ba58e2a9d308ca6ec9db11cf2544e5d861f966cbaff831dc0d34f9a546788d15a3734608e8485d00663
|
7
|
+
data.tar.gz: 1c92273dd73c2ce6da7224eacf7b3021f98604c59549231b5cab0ec6dead89d6071c5e5259a71b4db66c54c86baefb8d613262fa32ac0a713335bd5a3517dab7
|
data/README.md
CHANGED
@@ -43,6 +43,9 @@ 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
|
* go (Runs go fmt on a go source file and fail if formatting is incorrect, then runs go build and fails if can't compile)
|
46
|
+
* scss_lint (Check your SCSS files using the [scss-lint gem](https://github.com/causes/scss-lint))
|
47
|
+
* yaml (Check that your YAML is parsable)
|
48
|
+
* json (Checks if JSON is parsable)
|
46
49
|
|
47
50
|
## Default checks
|
48
51
|
|
@@ -61,7 +64,7 @@ To disable, simply leave one off the list
|
|
61
64
|
### CLI configuration
|
62
65
|
|
63
66
|
```ssh
|
64
|
-
pre-commit <enable|
|
67
|
+
pre-commit <enable|disable> <git|yaml> <checks|warnings> check1 [check2...]
|
65
68
|
```
|
66
69
|
|
67
70
|
The `git` provider can be used for local machine configuration, the `yaml` can be used for shared
|
@@ -69,7 +72,7 @@ project configuration.
|
|
69
72
|
|
70
73
|
Example move `jshint` from `checks` to `warnings` in `yaml` provider and save configuration to git:
|
71
74
|
```bash
|
72
|
-
pre-commit
|
75
|
+
pre-commit disable yaml checks jshint
|
73
76
|
pre-commit enable yaml warnings jshint
|
74
77
|
git add config/pre-commit.yml
|
75
78
|
git commit -m "pre-commit: move jshint from checks to warnings"
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require 'pre-commit/checks/plugin'
|
1
|
+
require 'pre-commit/checks/shell'
|
3
2
|
|
4
3
|
module PreCommit
|
5
4
|
module Checks
|
6
|
-
class Coffeelint <
|
5
|
+
class Coffeelint < Shell
|
7
6
|
|
8
7
|
def call(staged_files)
|
9
8
|
staged_files = staged_files.grep(/\.coffee$/)
|
@@ -11,8 +10,7 @@ module PreCommit
|
|
11
10
|
|
12
11
|
args = (config_file_flag + staged_files).join(' ')
|
13
12
|
|
14
|
-
|
15
|
-
stdout + stderr unless result.success?
|
13
|
+
execute("coffeelint #{args}")
|
16
14
|
end
|
17
15
|
|
18
16
|
def config_file_flag
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pre-commit/checks/plugin'
|
3
|
+
|
4
|
+
module PreCommit
|
5
|
+
module Checks
|
6
|
+
class Json < Plugin
|
7
|
+
def call(staged_files)
|
8
|
+
staged_files = staged_files.grep(/\.json$/)
|
9
|
+
return if staged_files.empty?
|
10
|
+
|
11
|
+
errors = staged_files.map {|file| load_file(file)}.compact
|
12
|
+
|
13
|
+
errors.join("\n") + "\n" unless errors.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_file(file)
|
17
|
+
File.open(file) {|io| JSON.load(io)}
|
18
|
+
nil
|
19
|
+
rescue JSON::ParserError => e
|
20
|
+
"#{e.message} parsing #{file}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.description
|
24
|
+
'Runs json to detect errors.'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'pre-commit/checks/shell'
|
2
|
+
|
3
|
+
module PreCommit
|
4
|
+
module Checks
|
5
|
+
class ScssLint < Shell
|
6
|
+
|
7
|
+
def call(staged_files)
|
8
|
+
staged_files = staged_files.grep(/\.scss$/)
|
9
|
+
return if staged_files.empty?
|
10
|
+
|
11
|
+
args = (config_file_flag + staged_files).join(' ')
|
12
|
+
|
13
|
+
execute("scss-lint #{args}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def config_file_flag
|
17
|
+
config_file ? ['-c', config_file] : []
|
18
|
+
end
|
19
|
+
|
20
|
+
def alternate_config_file
|
21
|
+
'.scss-lint.yml'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.description
|
25
|
+
"Runs scss lint to detect errors"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'pre-commit/checks/plugin'
|
3
|
+
|
4
|
+
module PreCommit
|
5
|
+
module Checks
|
6
|
+
class Yaml < Plugin
|
7
|
+
def call(staged_files)
|
8
|
+
staged_files = staged_files.grep(/\.(yml|yaml)$/)
|
9
|
+
return if staged_files.empty?
|
10
|
+
|
11
|
+
errors = staged_files.map {|file| load_file(file)}.compact
|
12
|
+
|
13
|
+
errors.join("\n") + "\n" unless errors.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_file(file)
|
17
|
+
if YAML.respond_to?(:safe_load)
|
18
|
+
safe_load_file(file)
|
19
|
+
else
|
20
|
+
normal_load_file(file)
|
21
|
+
end
|
22
|
+
|
23
|
+
rescue Psych::SyntaxError => e
|
24
|
+
e.message
|
25
|
+
end
|
26
|
+
|
27
|
+
def safe_load_file(file)
|
28
|
+
YAML.safe_load(File.read(file), [], [], true, file)
|
29
|
+
|
30
|
+
nil
|
31
|
+
rescue Psych::DisallowedClass
|
32
|
+
$stdout.puts "Warning: Skipping '#{file}' because it contains serialized ruby objects."
|
33
|
+
end
|
34
|
+
|
35
|
+
def normal_load_file(file)
|
36
|
+
YAML.load_file(file)
|
37
|
+
|
38
|
+
nil
|
39
|
+
rescue ArgumentError
|
40
|
+
$stdout.puts "Warning: Skipping '#{file}' because it contains serialized ruby objects."
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.description
|
44
|
+
'Runs yaml to detect errors.'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'pre-commit/checks/plugin'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module PreCommit
|
5
|
+
module Checks
|
6
|
+
class Shell < Plugin
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def execute(command)
|
11
|
+
_, stdout, stderr, process = Open3.popen3(command)
|
12
|
+
stdout.read + stderr.read unless process.value.success?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/pre-commit/cli.rb
CHANGED
@@ -27,7 +27,7 @@ module PreCommit
|
|
27
27
|
warn "Usage: pre-commit install"
|
28
28
|
warn "Usage: pre-commit list"
|
29
29
|
warn "Usage: pre-commit plugins"
|
30
|
-
warn "Usage: pre-commit <enable|
|
30
|
+
warn "Usage: pre-commit <enable|disable> <git|yaml> <checks|warnings> check1 [check2...]"
|
31
31
|
args.empty? # return status, it's ok if user requested help
|
32
32
|
end
|
33
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.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-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pluginator
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/plugins/pre_commit/checks/go.rb
|
117
117
|
- lib/plugins/pre_commit/checks/jshint.rb
|
118
118
|
- lib/plugins/pre_commit/checks/jslint.rb
|
119
|
+
- lib/plugins/pre_commit/checks/json.rb
|
119
120
|
- lib/plugins/pre_commit/checks/local.rb
|
120
121
|
- lib/plugins/pre_commit/checks/merge_conflict.rb
|
121
122
|
- lib/plugins/pre_commit/checks/migration.rb
|
@@ -127,8 +128,10 @@ files:
|
|
127
128
|
- lib/plugins/pre_commit/checks/rubocop.rb
|
128
129
|
- lib/plugins/pre_commit/checks/ruby.rb
|
129
130
|
- lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb
|
131
|
+
- lib/plugins/pre_commit/checks/scss_lint.rb
|
130
132
|
- lib/plugins/pre_commit/checks/tabs.rb
|
131
133
|
- lib/plugins/pre_commit/checks/whitespace.rb
|
134
|
+
- lib/plugins/pre_commit/checks/yaml.rb
|
132
135
|
- lib/plugins/pre_commit/configuration/providers/default.rb
|
133
136
|
- lib/plugins/pre_commit/configuration/providers/env.rb
|
134
137
|
- lib/plugins/pre_commit/configuration/providers/git.rb
|
@@ -139,6 +142,7 @@ files:
|
|
139
142
|
- lib/pre-commit/checks/js.rb
|
140
143
|
- lib/pre-commit/checks/plugin/config_file.rb
|
141
144
|
- lib/pre-commit/checks/plugin.rb
|
145
|
+
- lib/pre-commit/checks/shell.rb
|
142
146
|
- lib/pre-commit/checks.rb
|
143
147
|
- lib/pre-commit/cli.rb
|
144
148
|
- lib/pre-commit/configuration/providers.rb
|