xcassetscop 0.0.1 → 0.0.2
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/bin/xcassetscop +1 -1
- data/lib/xcassetscop.rb +1 -0
- data/lib/xcassetscop/cli.rb +11 -3
- data/lib/xcassetscop/config_options.rb +5 -2
- data/lib/xcassetscop/linter.rb +24 -6
- data/lib/xcassetscop/version.rb +11 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 612d8b2b930674cf4e0ebcea7e3f4b12223d5fb2f1d40cf2fea101c1808f3597
|
4
|
+
data.tar.gz: be3b2060014f5fdf05f38b0485b2770bfdce2936c3bdf28ee2fdf75261269442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d9cb48ea22bbee17fbbff9635973430fe6825ba6c4ecdfc54202e0c278d28797c2760b19b51ec40afde06998db6751ed35911b683d5feef71c7fe16662ad548
|
7
|
+
data.tar.gz: b2135b6434ea185507a468e808e93b538cbb40295267bd050afcdd19cb525fe52466328380bfb70cabfb7185888f5d595df6eba27d886991cf632ee00ef4dea6
|
data/bin/xcassetscop
CHANGED
data/lib/xcassetscop.rb
CHANGED
data/lib/xcassetscop/cli.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
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')
|
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
|
data/lib/xcassetscop/linter.rb
CHANGED
@@ -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.
|
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
|
-
["
|
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
|
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 +=
|
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
|
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.
|
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
|