pre-commit 0.36.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pre-commit/utils/staged_files.rb +49 -8
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 042b09e17f23f621e1faa6ea9932694fa6263e0a
|
4
|
+
data.tar.gz: 16934f896ce3e9e328bd883eae9408d396102be7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5802aa631fc983865d924f5b20e42a8431a0d685b414924315a61e698aa397ee858d7c581550d58a2efcc16b16675c09cad35c813a90e19d49d5f3a9dd9f26a
|
7
|
+
data.tar.gz: 7306cab5fd90c76570e10e80f4906fb02b207df6e6d09296be5a4b372cee7962409bbbc900b7de981e8159c459abca53bfd0e1eff2a1ece9e60a05bb77e9c79b
|
@@ -1,10 +1,23 @@
|
|
1
|
-
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require 'pre-commit/configuration/top_level'
|
2
4
|
|
3
5
|
module PreCommit
|
4
6
|
module Utils
|
5
7
|
module StagedFiles
|
6
8
|
include PreCommit::Configuration::TopLevel
|
7
9
|
|
10
|
+
BINARIES = [
|
11
|
+
".dmg", ".gz", ".img", ".iso", ".rar", ".tar", ".xz", ".zip"
|
12
|
+
].freeze
|
13
|
+
IMAGES = [".gif", ".ico", ".jpeg", ".jpg", ".pdf", ".png"].freeze
|
14
|
+
IGNORED_EXTENSIONS = BINARIES + IMAGES
|
15
|
+
|
16
|
+
SOURCE_FILES = [
|
17
|
+
".coffee", ".css", ".erb", ".feature", ".html", ".js", ".json",
|
18
|
+
".liquid", ".md", ".rb", ".sass", ".scss", ".slim", ".yml"
|
19
|
+
].freeze
|
20
|
+
|
8
21
|
def set_staged_files(*args)
|
9
22
|
case args[0].to_s
|
10
23
|
when "all" then staged_files_all
|
@@ -30,6 +43,31 @@ module PreCommit
|
|
30
43
|
@staged_files = filter_files(staged_from_git_all)
|
31
44
|
end
|
32
45
|
|
46
|
+
# Definitely include this file in the checks.
|
47
|
+
def source_file?(filename)
|
48
|
+
SOURCE_FILES.include?(File.extname(filename))
|
49
|
+
end
|
50
|
+
|
51
|
+
# Try to bail out quickly based on filename.
|
52
|
+
#
|
53
|
+
# If the extension is `.jpg` this is likely not a source code file.
|
54
|
+
# So let's not waste time checking to see if it's "binary" (as best we
|
55
|
+
# can guess) and let's not run any checks on it.
|
56
|
+
def ignore_extension?(filename)
|
57
|
+
IGNORED_EXTENSIONS.include?(File.extname(filename))
|
58
|
+
end
|
59
|
+
|
60
|
+
# Make a best guess to determine if this is a binary file.
|
61
|
+
# This is not an exact science ;)
|
62
|
+
def appears_binary?(filename)
|
63
|
+
size = File.size(filename)
|
64
|
+
size > 1_000_000 || (size > 20 && binary?(filename))
|
65
|
+
end
|
66
|
+
|
67
|
+
def repo_ignored?(filename)
|
68
|
+
repo_ignores.any? { |ignore| File.fnmatch?(ignore, filename) }
|
69
|
+
end
|
70
|
+
|
33
71
|
private
|
34
72
|
# from https://github.com/djberg96/ptools/blob/master/lib/ptools.rb#L90
|
35
73
|
def binary?(file)
|
@@ -41,14 +79,17 @@ module PreCommit
|
|
41
79
|
end
|
42
80
|
|
43
81
|
def filter_files(files)
|
44
|
-
files.reject do |file|
|
45
|
-
|
82
|
+
first_pass = files.reject do |file|
|
83
|
+
repo_ignored?(file) ||
|
84
|
+
ignore_extension?(file) ||
|
46
85
|
File.directory?(file) ||
|
47
|
-
(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
86
|
+
!File.exists?(file)
|
87
|
+
end
|
88
|
+
|
89
|
+
# If it's a source file, definitely check it.
|
90
|
+
# Otherwise, attempt to guess if the file is binary or not.
|
91
|
+
first_pass.select do |file|
|
92
|
+
source_file?(file) || !appears_binary?(file)
|
52
93
|
end
|
53
94
|
end
|
54
95
|
|
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.37.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: 2017-
|
11
|
+
date: 2017-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pluginator
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: benchmark-ips
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|