pre-commit 0.19.0 → 0.20.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 +10 -0
- data/lib/plugins/pre_commit/checks/before_all.rb +3 -3
- data/lib/plugins/pre_commit/checks/ci.rb +3 -1
- data/lib/plugins/pre_commit/checks/coffeelint.rb +6 -2
- data/lib/plugins/pre_commit/checks/console_log.rb +3 -3
- data/lib/plugins/pre_commit/checks/debugger.rb +2 -2
- data/lib/plugins/pre_commit/checks/gemfile_path.rb +3 -3
- data/lib/plugins/pre_commit/checks/jshint.rb +20 -10
- data/lib/plugins/pre_commit/checks/local.rb +10 -4
- data/lib/plugins/pre_commit/checks/merge_conflict.rb +2 -2
- data/lib/plugins/pre_commit/checks/pry.rb +1 -1
- data/lib/plugins/pre_commit/checks/rspec_focus.rb +2 -2
- data/lib/plugins/pre_commit/checks/rubocop.rb +5 -1
- data/lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb +2 -2
- data/lib/plugins/pre_commit/checks/scss_lint.rb +6 -2
- data/lib/plugins/pre_commit/checks/tabs.rb +2 -2
- data/lib/plugins/pre_commit/configuration/providers/yaml.rb +3 -5
- data/lib/pre-commit/checks/grep.rb +33 -10
- data/lib/pre-commit/checks/plugin.rb +12 -0
- data/lib/pre-commit/checks/shell.rb +17 -4
- data/lib/pre-commit/cli.rb +1 -1
- data/lib/pre-commit/configuration/top_level.rb +11 -0
- data/lib/pre-commit/error_list.rb +23 -0
- data/lib/pre-commit/installer.rb +8 -2
- data/lib/pre-commit/line.rb +22 -0
- data/lib/pre-commit/message.rb +17 -0
- data/lib/pre-commit/runner.rb +7 -2
- data/lib/pre-commit/support/jshint/jshint.js +10388 -3977
- data/lib/pre-commit/utils/staged_files.rb +20 -5
- 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: 0b7eca26aaae49efaf8967fb7a02d01521f272cc
|
4
|
+
data.tar.gz: 7e36f001ca2d85847d5038b757f442ffbb411a4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21965abc93d4cec2c941d53b519aa8bcf0416334a329784e061d8791108651f289184d7e0504e54da1b57e5b93d5395992753f856fbde69f08735c7810940e9
|
7
|
+
data.tar.gz: df10779b7b8a0be223b55b6f70a0cd476b080bc75074b39832a3b4409da5c966aefcd55f28ff5b95e8010142525e3e6fe611ca736247f0409b966e68f3dc2e54
|
data/README.md
CHANGED
@@ -107,4 +107,14 @@ pre-commit run <file-list> # run on the list of files, patterns not supported
|
|
107
107
|
- `yaml` - reads configuration from `/etc/pre_commit.yml`, `$HOME/.pre_commit.yml` and `config/pre_commit.yml`, allows `config/pre_commit.yml` updates
|
108
108
|
- `env` - reads configuration from environment variables
|
109
109
|
|
110
|
+
## Excluding files from checks
|
111
|
+
|
112
|
+
`pre-commit` uses `git` to get list of files to check, you can ignore
|
113
|
+
the list of git files to check with:
|
114
|
+
|
115
|
+
1. `.gitignore` - git supported file shared beteen all checkouts
|
116
|
+
2. `.git/info/exclude` - git supported file only for this checkout
|
117
|
+
3. `.pre_commit.ignore` - `pre-commit` specific list can be shared,
|
118
|
+
[Allowed filters](http://www.ruby-doc.org/core-2.1.3/File.html#method-c-fnmatch)
|
119
|
+
|
110
120
|
## [Contributing](CONTRIBUTING.md)
|
@@ -9,15 +9,15 @@ module PreCommit
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def extra_grep
|
12
|
-
|
12
|
+
%w{-v //}
|
13
13
|
end
|
14
14
|
|
15
15
|
def message
|
16
|
-
"before(:all) found
|
16
|
+
"before(:all) found:"
|
17
17
|
end
|
18
18
|
|
19
19
|
def pattern
|
20
|
-
|
20
|
+
"before.*:all"
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.description
|
@@ -7,7 +7,9 @@ module PreCommit
|
|
7
7
|
|
8
8
|
def call(_)
|
9
9
|
return if system("rake #{Ci::CI_TASK_NAME} --silent")
|
10
|
-
|
10
|
+
PreCommit::ErrorList.new(
|
11
|
+
"your test suite has failed, for the full output run `#{CI_TASK_NAME}`"
|
12
|
+
)
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.description
|
@@ -8,9 +8,13 @@ module PreCommit
|
|
8
8
|
staged_files = staged_files.grep(/\.coffee$/)
|
9
9
|
return if staged_files.empty?
|
10
10
|
|
11
|
-
|
11
|
+
result =
|
12
|
+
in_groups(staged_files).map do |files|
|
13
|
+
args = %w{coffeelint} + config_file_flag + files
|
14
|
+
execute(args)
|
15
|
+
end.compact
|
12
16
|
|
13
|
-
|
17
|
+
result.empty? ? nil : result.join("\n")
|
14
18
|
end
|
15
19
|
|
16
20
|
def config_file_flag
|
@@ -9,15 +9,15 @@ module PreCommit
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def extra_grep
|
12
|
-
|
12
|
+
%w{-v //}
|
13
13
|
end
|
14
14
|
|
15
15
|
def message
|
16
|
-
"console.log found
|
16
|
+
"console.log found:"
|
17
17
|
end
|
18
18
|
|
19
19
|
def pattern
|
20
|
-
|
20
|
+
"console\\.log"
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.description
|
@@ -9,15 +9,15 @@ module PreCommit
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def message
|
12
|
-
"local path found in Gemfile
|
12
|
+
"local path found in Gemfile:"
|
13
13
|
end
|
14
14
|
|
15
15
|
def pattern
|
16
|
-
"
|
16
|
+
"path:|:path\\s*=>"
|
17
17
|
end
|
18
18
|
|
19
19
|
def extra_grep
|
20
|
-
|
20
|
+
%w{-v #}
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.description
|
@@ -4,17 +4,8 @@ module PreCommit
|
|
4
4
|
module Checks
|
5
5
|
class Jshint < Js
|
6
6
|
|
7
|
-
def js_config
|
8
|
-
if config_file
|
9
|
-
ExecJS.exec("return (#{File.read(config_file)});")
|
10
|
-
else
|
11
|
-
{}
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
7
|
def run_check(file)
|
16
|
-
context
|
17
|
-
context.call("JSHINT", File.read(file), js_config, js_config["globals"])
|
8
|
+
context.call("JSHINT._getErrors", File.read(file), js_config, js_config["globals"])
|
18
9
|
end
|
19
10
|
|
20
11
|
def linter_src
|
@@ -29,6 +20,25 @@ module PreCommit
|
|
29
20
|
"Checks javascript files with JSHint."
|
30
21
|
end
|
31
22
|
|
23
|
+
private
|
24
|
+
|
25
|
+
def context
|
26
|
+
@context ||= ExecJS.compile(File.read(linter_src) << <<-JAVASCRIPT)
|
27
|
+
;JSHINT._getErrors = function(source, options, globals) {
|
28
|
+
JSHINT(source, options, globals);
|
29
|
+
return JSHINT.errors;
|
30
|
+
}
|
31
|
+
JAVASCRIPT
|
32
|
+
end
|
33
|
+
|
34
|
+
def js_config
|
35
|
+
@js_config ||= if config_file
|
36
|
+
ExecJS.exec("return (#{File.read(config_file)});")
|
37
|
+
else
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
@@ -4,16 +4,22 @@ module PreCommit
|
|
4
4
|
module Checks
|
5
5
|
class Local < Plugin
|
6
6
|
|
7
|
-
|
7
|
+
attr_writer :script
|
8
8
|
|
9
|
-
def call(staged_files
|
10
|
-
return unless
|
9
|
+
def call(staged_files)
|
10
|
+
return unless script
|
11
11
|
output = `ruby #{script} #{staged_files.join(" ")} 2>&1`
|
12
12
|
"#{script} failed:\n#{output}" unless $?.success?
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.description
|
16
|
-
"Executes
|
16
|
+
"Executes a custom script located at config/pre_commit.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def script
|
20
|
+
@script ||= ["config/pre_commit.rb", "config/pre-commit.rb"].detect do |file|
|
21
|
+
File.exist?(file)
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
end
|
@@ -9,11 +9,11 @@ module PreCommit
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def message
|
12
|
-
":focus found in specs
|
12
|
+
":focus found in specs:"
|
13
13
|
end
|
14
14
|
|
15
15
|
def pattern
|
16
|
-
"
|
16
|
+
"(describe|context|it).*(:focus|focus:).*do"
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.description
|
@@ -21,7 +21,7 @@ module PreCommit
|
|
21
21
|
staged_files = staged_files.grep(/\.rb$/)
|
22
22
|
return if staged_files.empty?
|
23
23
|
|
24
|
-
args = config_file_flag + ["--force-exclusion"] + staged_files
|
24
|
+
args = config_file_flag + user_supplied_flags + ["--force-exclusion"] + staged_files
|
25
25
|
|
26
26
|
success, captured = capture { ::RuboCop::CLI.new.run(args) == 0 }
|
27
27
|
captured unless success
|
@@ -41,6 +41,10 @@ module PreCommit
|
|
41
41
|
config_file ? ['-c', config_file] : []
|
42
42
|
end
|
43
43
|
|
44
|
+
def user_supplied_flags
|
45
|
+
Array(config.get('rubocop.flags')).reject(&:empty?)
|
46
|
+
end
|
47
|
+
|
44
48
|
def alternate_config_file
|
45
49
|
'.rubocop.yml'
|
46
50
|
end
|
@@ -9,11 +9,11 @@ module PreCommit
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def message
|
12
|
-
"detected :symbol => value hashrocket
|
12
|
+
"detected :symbol => value hashrocket:"
|
13
13
|
end
|
14
14
|
|
15
15
|
def pattern
|
16
|
-
'
|
16
|
+
'[^:](:{1}(?:\$|@|@@|[_A-Za-z])?\w*[=!?]?\s*=>\s*)'
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.description
|
@@ -8,9 +8,13 @@ module PreCommit
|
|
8
8
|
staged_files = staged_files.grep(/\.scss$/)
|
9
9
|
return if staged_files.empty?
|
10
10
|
|
11
|
-
|
11
|
+
result =
|
12
|
+
in_groups(staged_files).map do |files|
|
13
|
+
args = %w{scss-lint} + config_file_flag + files
|
14
|
+
execute(args)
|
15
|
+
end.compact
|
12
16
|
|
13
|
-
|
17
|
+
result.empty? ? nil : result.join("\n")
|
14
18
|
end
|
15
19
|
|
16
20
|
def config_file_flag
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require "pre-commit/configuration/top_level"
|
2
3
|
|
3
4
|
module PreCommit
|
4
5
|
class Configuration
|
5
6
|
class Providers
|
6
7
|
|
7
8
|
class Yaml
|
9
|
+
include PreCommit::Configuration::TopLevel
|
10
|
+
|
8
11
|
def self.priority
|
9
12
|
20
|
10
13
|
end
|
@@ -55,11 +58,6 @@ module PreCommit
|
|
55
58
|
File.join(top_level, 'config', 'pre_commit.yml')
|
56
59
|
end
|
57
60
|
|
58
|
-
def top_level
|
59
|
-
top_level = `git rev-parse --show-toplevel`.chomp.strip
|
60
|
-
raise "no git repo!" if top_level == ""
|
61
|
-
top_level
|
62
|
-
end
|
63
61
|
end
|
64
62
|
|
65
63
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'pre-commit/checks/
|
2
|
-
require '
|
1
|
+
require 'pre-commit/checks/shell'
|
2
|
+
require 'pre-commit/error_list'
|
3
|
+
require 'pre-commit/line'
|
3
4
|
|
4
5
|
module PreCommit
|
5
6
|
module Checks
|
6
|
-
class Grep <
|
7
|
+
class Grep < Shell
|
7
8
|
class PaternNotSet < StandardError
|
8
9
|
def message
|
9
10
|
"Please define 'pattern' method."
|
@@ -17,7 +18,7 @@ module PreCommit
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def extra_grep
|
20
|
-
@extra_grep or
|
21
|
+
@extra_grep or []
|
21
22
|
end
|
22
23
|
|
23
24
|
def message
|
@@ -31,21 +32,43 @@ module PreCommit
|
|
31
32
|
# general code:
|
32
33
|
|
33
34
|
def call(staged_files)
|
34
|
-
staged_files = files_filter(staged_files)
|
35
|
+
staged_files = files_filter(staged_files)
|
35
36
|
return if staged_files.empty?
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
|
38
|
+
result =
|
39
|
+
in_groups(staged_files).map do |files|
|
40
|
+
args = grep + [pattern] + files
|
41
|
+
args += ["|", "grep"] + extra_grep if !extra_grep.nil? and !extra_grep.empty?
|
42
|
+
execute(args, success_status: false)
|
43
|
+
end.compact
|
44
|
+
|
45
|
+
result.empty? ? nil : parse_errors(message, result)
|
39
46
|
end
|
40
47
|
|
41
48
|
private
|
42
49
|
|
50
|
+
def parse_errors(message, list)
|
51
|
+
result = PreCommit::ErrorList.new(message)
|
52
|
+
result.errors +=
|
53
|
+
list.map do |group|
|
54
|
+
group.split(/\n/)
|
55
|
+
end.flatten.compact.map do |line|
|
56
|
+
PreCommit::Line.new(nil, *parse_error(line))
|
57
|
+
end
|
58
|
+
result
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_error(line)
|
62
|
+
matches = /^([^:]+):([[:digit:]]+):(.*)$/.match(line)
|
63
|
+
matches and matches.captures
|
64
|
+
end
|
65
|
+
|
43
66
|
def grep(grep_version = nil)
|
44
67
|
grep_version ||= detect_grep_version
|
45
68
|
if grep_version =~ /FreeBSD/
|
46
|
-
|
69
|
+
%w{grep -EnIH}
|
47
70
|
else
|
48
|
-
|
71
|
+
%w{grep -PnIH}
|
49
72
|
end
|
50
73
|
end
|
51
74
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'plugins/pluginator/extensions/conversions'
|
2
2
|
require 'pre-commit/checks/plugin/config_file'
|
3
|
+
require 'pre-commit/line'
|
3
4
|
|
4
5
|
module PreCommit
|
5
6
|
module Checks
|
@@ -28,6 +29,17 @@ module PreCommit
|
|
28
29
|
def alternate_config_file
|
29
30
|
''
|
30
31
|
end
|
32
|
+
|
33
|
+
# group files in packs smaller then 127kB (1000 files)
|
34
|
+
# 127k based on http://www.in-ulm.de/~mascheck/various/argmax/
|
35
|
+
# and 262144 limit on OSX - my env size /2 to be safe
|
36
|
+
# assuming mean file length shorter then 127 chars splitting to
|
37
|
+
# groups of 1000 files, each_slice for simplicity, doing real
|
38
|
+
# check could be to time consuming
|
39
|
+
def in_groups(files, group_size = 1000)
|
40
|
+
files.each_slice(group_size)
|
41
|
+
end
|
42
|
+
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'pre-commit/checks/plugin'
|
2
|
-
require '
|
2
|
+
require 'shellwords'
|
3
3
|
|
4
4
|
module PreCommit
|
5
5
|
module Checks
|
@@ -7,9 +7,22 @@ module PreCommit
|
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
def execute(
|
11
|
-
|
12
|
-
|
10
|
+
def execute(*args)
|
11
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
12
|
+
args = build_command(*args)
|
13
|
+
execute_raw(args, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_command(*args)
|
17
|
+
args.flatten.map do |arg|
|
18
|
+
arg = arg.shellescape if arg != '|' && arg != '&&' && arg != '||'
|
19
|
+
arg
|
20
|
+
end.join(" ")
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute_raw(command, options = {})
|
24
|
+
result = `#{command} 2>&1`
|
25
|
+
$?.success? == (options.fetch(:success_status, true)) ? nil : result
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|