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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b3925dbdc545f62cd3ac2f1ecc78e95f79ba2be
4
- data.tar.gz: 3fb7a0973a89765ac6ddd1898c8a2d379759ad6b
3
+ metadata.gz: 0db8f765f2e06da8499568ce2e7c3bd3904a167d
4
+ data.tar.gz: b597ec14fa63e579dd63caf6edffac6937110ba5
5
5
  SHA512:
6
- metadata.gz: 052c70e54f7833c4adb7094cdfd73ea90664046f8af25d9a8c2cb50a933de025bad522a7872c23e08639ba485f5a43d36ec037117d3d6297a2f422daa13938e6
7
- data.tar.gz: e6d37cbb422edd64b9714947904452963e9e1272dccbb2a98886646e8b75e2a6846ba67fcac40aa20e1a95025242d8565289b2b6be250a5f2053d941052cc2ed
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|disbale> <git|yaml> <checks|warnings> check1 [check2...]
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 disbale yaml checks jshint
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 'open3'
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 < Plugin
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
- stdout, stderr, result = Open3.capture3("coffeelint #{args}")
15
- stdout + stderr unless result.success?
13
+ execute("coffeelint #{args}")
16
14
  end
17
15
 
18
16
  def config_file_flag
@@ -5,7 +5,7 @@ module PreCommit
5
5
  class ConsoleLog < Grep
6
6
 
7
7
  def files_filter(staged_files)
8
- staged_files.grep(/\.js$/)
8
+ staged_files.grep(/\.(js|coffee)$/)
9
9
  end
10
10
 
11
11
  def extra_grep
@@ -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
@@ -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|disbale> <git|yaml> <checks|warnings> check1 [check2...]"
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.15.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-03-11 00:00:00.000000000 Z
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