img-lint 0.0.16 → 0.0.17
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/cli.rb +13 -3
- data/lib/img_lint/constants.rb +3 -0
- data/lib/img_lint/linter.rb +10 -9
- data/lib/img_lint/rake_task.rb +2 -1
- data/lib/img_lint/version.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59e8ea52589642c88577a1c2ed8448884c17cb79
|
4
|
+
data.tar.gz: f0afc1f20220878d0fe98c7c0ca134826b1eab63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01b30b58d3bb1cfdfac948121b3217c698210eebd20c242fb5799b698714e7ad6e99398b0e62c2a82381919c93f5d926e7a052ce8ef5ab1c053faed774764faf
|
7
|
+
data.tar.gz: 02a5c48975b61013fce63ace7a5736ef62578b9c7ae2c57cec49ebdedf8f5c424177a31078eb0470b71c10f01cc06adef1cc990739bb2969ab67a62c1151455d
|
data/lib/img_lint/cli.rb
CHANGED
@@ -7,7 +7,13 @@ require "optparse"
|
|
7
7
|
$LOAD_PATH << File.expand_path(__dir__)
|
8
8
|
|
9
9
|
module IMGLint
|
10
|
-
# CLI class
|
10
|
+
# CLI class is responsible for handling command-line arguments.
|
11
|
+
#
|
12
|
+
# If the first argument is an "install" command, then we just copying
|
13
|
+
# default config to project's root folder and exit.
|
14
|
+
#
|
15
|
+
# Otherwise we'd extract path/max image size/image format arguments and run
|
16
|
+
# linter.
|
11
17
|
#
|
12
18
|
class CLI
|
13
19
|
def run(args = [])
|
@@ -29,14 +35,18 @@ module IMGLint
|
|
29
35
|
path = config.delete("path")
|
30
36
|
|
31
37
|
linter = IMGLint::Linter.new(config: config)
|
32
|
-
|
38
|
+
heavy_images = linter.lint(path: path)
|
33
39
|
|
34
|
-
|
40
|
+
heavy_images.empty? ? 0 : 2
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
private
|
39
45
|
|
46
|
+
# This method is needed to unindent
|
47
|
+
# ["here document"](https://en.wikibooks.org/wiki/Ruby_Programming/Here_documents)
|
48
|
+
# help description.
|
49
|
+
#
|
40
50
|
def unindent(str)
|
41
51
|
str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, "")
|
42
52
|
end
|
data/lib/img_lint/constants.rb
CHANGED
data/lib/img_lint/linter.rb
CHANGED
@@ -4,6 +4,7 @@ module IMGLint
|
|
4
4
|
# Linter class is responsible for checking images (only formats specified
|
5
5
|
# in config) if they exceed a curtain size. It also prints out list of
|
6
6
|
# suspicious images.
|
7
|
+
#
|
7
8
|
class Linter
|
8
9
|
attr_accessor :config
|
9
10
|
|
@@ -14,16 +15,16 @@ module IMGLint
|
|
14
15
|
def lint(path: Dir.pwd, verbose: true)
|
15
16
|
path ||= Dir.pwd
|
16
17
|
|
17
|
-
|
18
|
+
heavy_images = find_heavy_images(path, verbose)
|
18
19
|
|
19
|
-
print_report(path,
|
20
|
+
print_report(path, heavy_images, verbose)
|
20
21
|
|
21
|
-
|
22
|
+
heavy_images
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
def
|
27
|
+
def find_heavy_images(path, verbose)
|
27
28
|
images = Dir.glob(%(#{path}/**/*.{#{config['image_formats']}}))
|
28
29
|
|
29
30
|
puts "No images found in #{path}" if verbose && images.empty?
|
@@ -53,15 +54,15 @@ module IMGLint
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
def print_report(path,
|
57
|
-
return if
|
57
|
+
def print_report(path, heavy_images, verbose)
|
58
|
+
return if heavy_images.empty? || !verbose
|
58
59
|
|
59
60
|
puts "Suspicious images:"
|
60
61
|
|
61
|
-
longest_image_path =
|
62
|
-
longest_file_size =
|
62
|
+
longest_image_path = heavy_images.keys.max { |k| k.size }.size
|
63
|
+
longest_file_size = heavy_images.values.max { |v| v.to_s.size }.size
|
63
64
|
|
64
|
-
|
65
|
+
heavy_images.sort_by(&:last).reverse.each do |image, file_size|
|
65
66
|
image = image.sub(Dir.pwd, "") if Dir.pwd == path
|
66
67
|
|
67
68
|
puts [image.ljust(longest_image_path), "#{file_size}Kb".rjust(longest_file_size)].join("\t")
|
data/lib/img_lint/rake_task.rb
CHANGED
@@ -5,7 +5,8 @@ require "rake/tasklib"
|
|
5
5
|
require "img_lint/cli"
|
6
6
|
|
7
7
|
module IMGLint
|
8
|
-
# Rake
|
8
|
+
# Simple rake task to either add "rake img_lint" to the project's Rake tasks
|
9
|
+
# and use in CI for example.
|
9
10
|
#
|
10
11
|
class RakeTask < Rake::TaskLib
|
11
12
|
def initialize(name = :img_lint)
|
data/lib/img_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: img-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoli Makarevich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.5.1
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: IMG linter
|