Skip to content

Commit dc07b5e

Browse files
davidstosiksds
authored andcommitted
Fix Rubocop errors
1 parent 9e9201c commit dc07b5e

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed
+41-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# frozen_string_literal: true
2+
13
module Overcommit::Hook::PreCommit
4+
# Checks for oversized files before committing.
25
class FileSize < Base
36
DEFAULT_SIZE_LIMIT_BYTES = 1_000_000 # 1MB
47

@@ -12,43 +15,51 @@ def run
1215

1316
private
1417

15-
def oversized_files
16-
@_oversized_files ||= build_oversized_file_list
17-
end
18+
def oversized_files
19+
@oversized_files ||= build_oversized_file_list
20+
end
1821

19-
def build_oversized_file_list
20-
applicable_files.select do |file|
21-
file_size(file) > size_limit_bytes
22-
end
22+
def build_oversized_file_list
23+
applicable_files.select do |file|
24+
file_size(file) > size_limit_bytes
2325
end
26+
end
2427

25-
def size_limit_bytes
26-
config.fetch("size_limit_bytes", DEFAULT_SIZE_LIMIT_BYTES)
27-
end
28+
def size_limit_bytes
29+
config.fetch('size_limit_bytes', DEFAULT_SIZE_LIMIT_BYTES)
30+
end
2831

29-
def error_message_for(file)
30-
Overcommit::Hook::Message.new(
31-
:error,
32-
file,
33-
nil,
34-
error_text_for(file)
35-
)
36-
end
32+
def error_message_for(file)
33+
Overcommit::Hook::Message.new(
34+
:error,
35+
file,
36+
nil,
37+
error_text_for(file)
38+
)
39+
end
3740

38-
def error_text_for(file)
39-
"#{relative_path_for(file)} is over the file size limit of #{size_limit_bytes} bytes (is #{file_size(file)} bytes)"
40-
end
41+
def error_text_for(file)
42+
error_text_format % {
43+
path: relative_path_for(file),
44+
limit: size_limit_bytes,
45+
size: file_size(file)
46+
}
47+
end
4148

42-
def file_size(file)
43-
File.size(file)
44-
end
49+
def error_text_format
50+
'%<path>s is over the file size limit of %<limit>s bytes (is %<size>s bytes)'
51+
end
4552

46-
def relative_path_for(file)
47-
Pathname.new(file).relative_path_from(repo_root_path)
48-
end
53+
def file_size(file)
54+
File.size(file)
55+
end
4956

50-
def repo_root_path
51-
@_repo_root_path ||= Pathname.new(Overcommit::Utils.repo_root)
52-
end
57+
def relative_path_for(file)
58+
Pathname.new(file).relative_path_from(repo_root_path)
59+
end
60+
61+
def repo_root_path
62+
@repo_root_path ||= Pathname.new(Overcommit::Utils.repo_root)
63+
end
5364
end
5465
end

0 commit comments

Comments
 (0)