pre-commit 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac175b7e57416744f8dd4f44288c14dd7df0e4e8
4
- data.tar.gz: 0c7b2d185164ab133d07c3fb23fdee40a955a831
3
+ metadata.gz: 042b09e17f23f621e1faa6ea9932694fa6263e0a
4
+ data.tar.gz: 16934f896ce3e9e328bd883eae9408d396102be7
5
5
  SHA512:
6
- metadata.gz: 850f5a706f5cc3261b700d87fcf43c8af49dc87e58821dba225852db48491947c00b9fb8b3a836b8927651e0fe89b556792476b6b65f90e53d9e7c0a07491e1e
7
- data.tar.gz: de95b110f459871aeaeb3cf19ffa4e9e6fd220670e76e2c3bb75a61cf45574c9ed759e053d2260938812374273c4bc2fa3df2d09a6cd5ba7ca3566fbeebc3619
6
+ metadata.gz: b5802aa631fc983865d924f5b20e42a8431a0d685b414924315a61e698aa397ee858d7c581550d58a2efcc16b16675c09cad35c813a90e19d49d5f3a9dd9f26a
7
+ data.tar.gz: 7306cab5fd90c76570e10e80f4906fb02b207df6e6d09296be5a4b372cee7962409bbbc900b7de981e8159c459abca53bfd0e1eff2a1ece9e60a05bb77e9c79b
@@ -1,10 +1,23 @@
1
- require "pre-commit/configuration/top_level"
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
- !File.exist?(file) ||
82
+ first_pass = files.reject do |file|
83
+ repo_ignored?(file) ||
84
+ ignore_extension?(file) ||
46
85
  File.directory?(file) ||
47
- (
48
- size = File.size(file)
49
- size > 1_000_000 || (size > 20 && binary?(file))
50
- ) ||
51
- repo_ignores.any? { |ignore| File.fnmatch?(ignore, file) }
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.36.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-09-05 00:00:00.000000000 Z
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