img-lint 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c40d6bbcc1ec9690a2d4ca2a41d1e814838dbd11
4
- data.tar.gz: e14e808b66b8dfb712a99e66a88a368c244cbbdc
3
+ metadata.gz: 59e8ea52589642c88577a1c2ed8448884c17cb79
4
+ data.tar.gz: f0afc1f20220878d0fe98c7c0ca134826b1eab63
5
5
  SHA512:
6
- metadata.gz: 6c5ff65e4f72daeae5c723f1a5c4f0c96fa78d261fe39bbfdc7de1ad93fbc34e8aca35f6a89fd339c52e0333e62886e529ca79ad7925a0f6f48a8558cfadaab7
7
- data.tar.gz: 8b45ddbfecd0337696f450a48ecce58db87bbc5074fd192bcc99cef8a721a6a94ce7db8dac3714b6ff5732fea24f5851c3225e5d9b60720b35a26b56ecbc7721
6
+ metadata.gz: 01b30b58d3bb1cfdfac948121b3217c698210eebd20c242fb5799b698714e7ad6e99398b0e62c2a82381919c93f5d926e7a052ce8ef5ab1c053faed774764faf
7
+ data.tar.gz: 02a5c48975b61013fce63ace7a5736ef62578b9c7ae2c57cec49ebdedf8f5c424177a31078eb0470b71c10f01cc06adef1cc990739bb2969ab67a62c1151455d
@@ -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
- fat_images = linter.lint(path: path)
38
+ heavy_images = linter.lint(path: path)
33
39
 
34
- fat_images.empty? ? 0 : 2
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
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # This is a module to keep constants like a path to the gem's directory
4
+ # to easily reference a default config file.
5
+ #
3
6
  module IMGLint
4
7
  IMG_LINT_HOME = File.realpath(File.join(__dir__, "..", ".."))
5
8
  end
@@ -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
- fat_images = find_fat_images(path, verbose)
18
+ heavy_images = find_heavy_images(path, verbose)
18
19
 
19
- print_report(path, fat_images, verbose)
20
+ print_report(path, heavy_images, verbose)
20
21
 
21
- fat_images
22
+ heavy_images
22
23
  end
23
24
 
24
25
  private
25
26
 
26
- def find_fat_images(path, verbose)
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, fat_images, verbose)
57
- return if fat_images.empty? || !verbose
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 = fat_images.keys.max { |k| k.size }.size
62
- longest_file_size = fat_images.values.max { |v| v.to_s.size }.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
- fat_images.sort_by(&:last).reverse.each do |image, file_size|
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")
@@ -5,7 +5,8 @@ require "rake/tasklib"
5
5
  require "img_lint/cli"
6
6
 
7
7
  module IMGLint
8
- # Rake task
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)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Module to keep the gem's version in. Make sure to bump it before release.
4
+ #
3
5
  module IMGLint
4
- VERSION = "0.0.16".freeze
6
+ VERSION = "0.0.17".freeze
5
7
  end
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.16
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-20 00:00:00.000000000 Z
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.2.5
107
+ rubygems_version: 2.5.1
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: IMG linter