xcassetscop 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: 6392c29c38a1569c9dae8edab100e6da846ecd8cf4a90ade2f0a503a26afb795
4
- data.tar.gz: 2bec50f9927a83a4c9f8db12854a2fe9d8d55e10db972737b88a0bd196a10df7
3
+ metadata.gz: 612d8b2b930674cf4e0ebcea7e3f4b12223d5fb2f1d40cf2fea101c1808f3597
4
+ data.tar.gz: be3b2060014f5fdf05f38b0485b2770bfdce2936c3bdf28ee2fdf75261269442
5
5
  SHA512:
6
- metadata.gz: 591b55b55c1ea806189506308ab39620ba8b96080dc088deaa67810499fc4add36c91059ae509cb84f4b3ea9c2cefdd3d5646cfb731194c4be07ca5735e8a61c
7
- data.tar.gz: 927b59ca999b135a55238ce15001bc99f3e65d54179690bcc7a877379ecbf2a72c6cb57e0bc789ae1f838340f5b45eb8949e6da757cc29efe3707b9a85a2c8f5
6
+ metadata.gz: 5d9cb48ea22bbee17fbbff9635973430fe6825ba6c4ecdfc54202e0c278d28797c2760b19b51ec40afde06998db6751ed35911b683d5feef71c7fe16662ad548
7
+ data.tar.gz: b2135b6434ea185507a468e808e93b538cbb40295267bd050afcdd19cb525fe52466328380bfb70cabfb7185888f5d595df6eba27d886991cf632ee00ef4dea6
@@ -4,4 +4,4 @@
4
4
 
5
5
  require 'xcassetscop'
6
6
 
7
- XCAssetsCop::CLI.run ARGV
7
+ XCAssetsCop::CLI.start ARGV
@@ -8,3 +8,4 @@ require_relative './xcassetscop/linter'
8
8
  require_relative './xcassetscop/linter_rule'
9
9
  require_relative './xcassetscop/module'
10
10
  require_relative './xcassetscop/template_rendering_intent'
11
+ require_relative './xcassetscop/version'
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'thor'
3
4
  require_relative 'configfile_parser'
5
+ require_relative 'version'
4
6
 
5
7
  module XCAssetsCop
6
- module CLI
7
- def self.run(args)
8
- configfile_path = File.expand_path args[0]
8
+ class CLI < Thor
9
+ desc 'lint [CONFIG FILE]', 'lint files using the configuration file provided, looks for a xcassetscop.yml if no path is provided'
10
+ def lint(config_path = nil)
11
+ configfile_path = File.expand_path(config_path || './xcassetscop.yml')
9
12
  unless File.file? configfile_path
10
13
  puts "Can't find file on path: #{configfile_path}"
11
14
  return
@@ -25,5 +28,10 @@ module XCAssetsCop
25
28
  puts 'No errors found'
26
29
  end
27
30
  end
31
+
32
+ desc 'version', 'print version'
33
+ def version
34
+ puts Version.version
35
+ end
28
36
  end
29
37
  end
@@ -6,21 +6,24 @@ require_relative './image_scale'
6
6
 
7
7
  module XCAssetsCop
8
8
  class ConfigOptions
9
- attr_reader :file_extension, :image_scale, :same_file_and_asset_name, :template_rendering_intent
9
+ attr_reader :file_extension, :image_scale, :same_file_and_asset_name, :template_rendering_intent,
10
+ :preserves_vector_representation
10
11
 
11
12
  ALLOWED_KEYS = %i[
12
13
  file_extension
13
14
  image_scale
14
15
  same_file_and_asset_name
15
16
  template_rendering_intent
17
+ preserves_vector_representation
16
18
  ].freeze
17
19
 
18
20
  def initialize(obj)
19
21
  ensure_all_keys_are_allowed obj
20
22
  @file_extension = obj.sdig('file_extension')
21
23
  @image_scale = obj.sdig('image_scale')
22
- @same_file_and_asset_name = obj.sdig('same_file_and_asset_name') || false
24
+ @same_file_and_asset_name = obj.sdig('same_file_and_asset_name')
23
25
  @template_rendering_intent = obj.sdig('template_rendering_intent')
26
+ @preserves_vector_representation = obj.sdig('preserves_vector_representation')
24
27
  end
25
28
 
26
29
  private
@@ -11,6 +11,18 @@ module XCAssetsCop
11
11
  contents_json&.dig('images')&.first&.dig('filename')
12
12
  end
13
13
 
14
+ def self.get_file_extension(contents_json)
15
+ get_file_name(contents_json).split('.').last
16
+ end
17
+
18
+ def self.validate_file_extension(contents_json, expected)
19
+ file_extension = get_file_extension(contents_json)
20
+ return [] if expected.to_sym == file_extension.to_sym
21
+
22
+ file_name = get_file_name(contents_json)
23
+ ["Expected #{file_name} type to be #{expected}, got #{file_extension} instead"]
24
+ end
25
+
14
26
  def self.file_name_matches_asset_name(contents_json, file_path)
15
27
  asset_name = file_path.split('/').select { |str| str.include? '.imageset' }.first.split('.').first
16
28
  file_name = get_file_name(contents_json)&.split('.')&.first
@@ -44,12 +56,16 @@ module XCAssetsCop
44
56
  ["Expected #{file_name} to be rendered as '#{expected}', got '#{template_rendering_intent}' instead"]
45
57
  end
46
58
 
47
- def self.validate_file_extension(contents_json, expected)
59
+ def self.validate_preserves_vector_representation(contents_json, expected)
60
+ preserves_vector_representation = contents_json&.dig('properties')&.dig('preserves-vector-representation') || false
61
+ file_extension = get_file_extension(contents_json)
62
+
48
63
  file_name = get_file_name(contents_json)
49
- file_extension = file_name.split('.').last
50
- return [] if expected.to_sym == file_extension.to_sym
51
64
 
52
- ["Expected #{file_name} type to be #{expected}, got #{file_extension} instead"]
65
+ return ["#{file_name} should be a PDF file if you want to preserve vector data"] if (file_extension.to_sym != :pdf) && expected
66
+ return ["Expected #{file_name} to#{' NOT' unless expected} preserve vector representation"] unless preserves_vector_representation == expected
67
+
68
+ []
53
69
  end
54
70
 
55
71
  def self.lint_file(file_path, config)
@@ -58,15 +74,17 @@ module XCAssetsCop
58
74
 
59
75
  template_rendering_intent = config.template_rendering_intent
60
76
  image_scale = config.image_scale
61
- same_file_and_asset_name = config.same_file_and_asset_name || false
77
+ same_file_and_asset_name = config.same_file_and_asset_name
62
78
  file_extension = config.file_extension
79
+ preserves_vector_representation = config.preserves_vector_representation
63
80
 
64
81
  errors = []
65
82
 
66
83
  errors += validate_template_rendering_intent(contents_json, template_rendering_intent.to_sym) if template_rendering_intent
67
84
  errors += validate_image_scale(contents_json, image_scale.to_sym) if image_scale
68
- errors += file_name_matches_asset_name(contents_json, file_path) if same_file_and_asset_name
85
+ errors += validate_preserves_vector_representation(contents_json, file_path) if preserves_vector_representation
69
86
  errors += validate_file_extension(contents_json, file_extension.to_sym) if file_extension
87
+ errors += file_name_matches_asset_name(contents_json, file_path) if same_file_and_asset_name
70
88
 
71
89
  errors
72
90
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module XCAssetsCop
4
+ module Version
5
+ STRING = '0.0.2'
6
+
7
+ def self.version
8
+ STRING
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcassetscop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleph Retamal
@@ -29,6 +29,7 @@ files:
29
29
  - lib/xcassetscop/module.rb
30
30
  - lib/xcassetscop/template_rendering_intent.rb
31
31
  - lib/xcassetscop/utility.rb
32
+ - lib/xcassetscop/version.rb
32
33
  homepage: https://lalacode.io
33
34
  licenses:
34
35
  - MIT