img-lint 0.0.7 → 0.0.8
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 +4 -4
- data/lib/img_lint/config.rb +5 -1
- data/lib/img_lint/constants.rb +1 -1
- data/lib/img_lint/linter.rb +20 -7
- data/lib/img_lint/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b572b2ab3cbb809acfc3f0679fc268055e454b97
|
4
|
+
data.tar.gz: e039f988782ceefde38c4970d024e440a1b4f976
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3d9a569e5d9bfbb022af56f034d6e2823ad63cca3c8fb615c7ca958246e97b7cd196a7cdb786da4a2687d58aeb7657fb3b7ad76a43984541019c465b68093c1
|
7
|
+
data.tar.gz: 728fed8c31c2fae34349571ae0da8fb7c8045b102ac497d101ab033a3a9af9da51d3a70227df343f8228445068a4daf59947b5fd61877b6b5b0523c13e2ca1d1
|
data/lib/img_lint/config.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "yaml"
|
2
4
|
|
3
5
|
module IMGLint
|
6
|
+
# Config class is responsible to load img-lint either a user defined config
|
7
|
+
# or a default one (config/default.yml)
|
4
8
|
class Config
|
5
|
-
FILE_NAME = ".img-lint.yml"
|
9
|
+
FILE_NAME = ".img-lint.yml".freeze
|
6
10
|
DEFAULT_FILE = File.join(IMG_LINT_HOME, "config", "default.yml")
|
7
11
|
|
8
12
|
class << self
|
data/lib/img_lint/constants.rb
CHANGED
data/lib/img_lint/linter.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module IMGLint
|
4
|
+
# Linter class is responsible for checking images (only formats specified
|
5
|
+
# in config) if they exceed a curtain size. It also prints out list of
|
6
|
+
# suspicious images.
|
2
7
|
class Linter
|
3
8
|
attr_accessor :config
|
4
9
|
|
@@ -9,17 +14,27 @@ module IMGLint
|
|
9
14
|
def lint(path: Dir.pwd, verbose: true)
|
10
15
|
path ||= Dir.pwd
|
11
16
|
|
12
|
-
|
17
|
+
fat_images = find_fat_images(path, verbose)
|
18
|
+
|
19
|
+
print_report(path, fat_images, verbose)
|
20
|
+
|
21
|
+
fat_images
|
22
|
+
end
|
13
23
|
|
14
|
-
|
24
|
+
private
|
25
|
+
|
26
|
+
def find_fat_images(path, verbose)
|
27
|
+
images = Dir.glob(%(#{path}/**/*.{#{config['image_formats']}}))
|
15
28
|
|
16
29
|
puts "No images found in #{path}" if verbose && images.empty?
|
17
30
|
|
18
|
-
|
19
|
-
File.new(file).size > max_file_size * 1024
|
31
|
+
images.select do |file|
|
32
|
+
File.new(file).size > config["max_file_size"] * 1024
|
20
33
|
end
|
34
|
+
end
|
21
35
|
|
22
|
-
|
36
|
+
def print_report(path, fat_images, verbose)
|
37
|
+
if !fat_images.empty? && verbose
|
23
38
|
puts "Suspicious images:"
|
24
39
|
|
25
40
|
fat_images.each do |image|
|
@@ -30,8 +45,6 @@ module IMGLint
|
|
30
45
|
puts [image, "#{file_size}Kb"].join("\t")
|
31
46
|
end
|
32
47
|
end
|
33
|
-
|
34
|
-
fat_images
|
35
48
|
end
|
36
49
|
end
|
37
50
|
end
|
data/lib/img_lint/version.rb
CHANGED