danger-l10nlint 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.bundle/config +2 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +148 -0
- data/.ruby-version +2 -0
- data/.travis.yml +10 -0
- data/Dangerfile +10 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +153 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +20 -0
- data/Rakefile +25 -0
- data/bin/danger-l10nlint +23 -0
- data/danger-l10nlint.gemspec +50 -0
- data/ext/l10nlint/l10nlint.rb +89 -0
- data/lib/danger_plugin.rb +178 -0
- data/lib/version.rb +6 -0
- data/spec/l10nlint_spec.rb +31 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/fixtures/github_pr.json +278 -0
- metadata +207 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d68a9a3efda594ed8050fcfec0ee12ed733ebec8867c8a3ed7350d27afdb366b
|
4
|
+
data.tar.gz: f52c7a6662c5316370afa32f1392575e109d4b88b31773d3965442ab2b9a7563
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8db3437b12ed5b61e3c97f9ec44abb29fadce5ceff947b68ca698cc928ac6cd6a284134ee19ae5fbd24049f18fc415887264b3a18b96bf82fba1c109214573c
|
7
|
+
data.tar.gz: 4ea82e1a07b6aff66389b5a92a1539daaf78193e478954e7dcbefb3c2624eea5922dd821ce1e9257f93d22eac60c9aa81cc76c64a5ab1cf0216465e70e28a073
|
data/.bundle/config
ADDED
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
# Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
2
|
+
|
3
|
+
# If you don't like these settings, just delete this file :)
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.7
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
# kind_of? is a good way to check a type
|
13
|
+
Style/ClassCheck:
|
14
|
+
EnforcedStyle: kind_of?
|
15
|
+
|
16
|
+
# specs sometimes have useless assignments, which is fine
|
17
|
+
Lint/UselessAssignment:
|
18
|
+
Exclude:
|
19
|
+
- '**/spec/**/*'
|
20
|
+
|
21
|
+
# We could potentially enable the 2 below:
|
22
|
+
Layout/FirstHashElementIndentation:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Layout/HashAlignment:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
# HoundCI doesn't like this rule
|
29
|
+
Layout/DotPosition:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
# We allow !! as it's an easy way to convert ot boolean
|
33
|
+
Style/DoubleNegation:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# Cop supports --auto-correct.
|
37
|
+
Lint/UnusedBlockArgument:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
# We want to allow class Fastlane::Class
|
41
|
+
Style/ClassAndModuleChildren:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Metrics/AbcSize:
|
45
|
+
Max: 60
|
46
|
+
|
47
|
+
# The %w might be confusing for new users
|
48
|
+
Style/WordArray:
|
49
|
+
MinSize: 19
|
50
|
+
|
51
|
+
# raise and fail are both okay
|
52
|
+
Style/SignalException:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
# Better too much 'return' than one missing
|
56
|
+
Style/RedundantReturn:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Having if in the same line might not always be good
|
60
|
+
Style/IfUnlessModifier:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
# and and or is okay
|
64
|
+
Style/AndOr:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
# Configuration parameters: CountComments.
|
68
|
+
Metrics/ClassLength:
|
69
|
+
Max: 350
|
70
|
+
|
71
|
+
Metrics/CyclomaticComplexity:
|
72
|
+
Max: 17
|
73
|
+
|
74
|
+
# Configuration parameters: AllowURI, URISchemes.
|
75
|
+
Layout/LineLength:
|
76
|
+
Max: 370
|
77
|
+
|
78
|
+
# Configuration parameters: CountKeywordArgs.
|
79
|
+
Metrics/ParameterLists:
|
80
|
+
Max: 10
|
81
|
+
|
82
|
+
Metrics/PerceivedComplexity:
|
83
|
+
Max: 18
|
84
|
+
|
85
|
+
# Sometimes it's easier to read without guards
|
86
|
+
Style/GuardClause:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
# something = if something_else
|
90
|
+
# that's confusing
|
91
|
+
Style/ConditionalAssignment:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
# Better to have too much self than missing a self
|
95
|
+
Style/RedundantSelf:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
Metrics/MethodLength:
|
99
|
+
Max: 60
|
100
|
+
|
101
|
+
# We're not there yet
|
102
|
+
Style/Documentation:
|
103
|
+
Enabled: false
|
104
|
+
|
105
|
+
# Adds complexity
|
106
|
+
Style/IfInsideElse:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# danger specific
|
110
|
+
|
111
|
+
Style/BlockComments:
|
112
|
+
Enabled: false
|
113
|
+
|
114
|
+
Layout/MultilineMethodCallIndentation:
|
115
|
+
EnforcedStyle: indented
|
116
|
+
|
117
|
+
# FIXME: 25
|
118
|
+
Metrics/BlockLength:
|
119
|
+
Max: 345
|
120
|
+
Exclude:
|
121
|
+
- "**/*_spec.rb"
|
122
|
+
|
123
|
+
Style/MixinGrouping:
|
124
|
+
Enabled: false
|
125
|
+
|
126
|
+
Naming/FileName:
|
127
|
+
Enabled: false
|
128
|
+
|
129
|
+
Layout/HeredocIndentation:
|
130
|
+
Enabled: false
|
131
|
+
|
132
|
+
Style/SpecialGlobalVars:
|
133
|
+
Enabled: false
|
134
|
+
|
135
|
+
Style/PercentLiteralDelimiters:
|
136
|
+
PreferredDelimiters:
|
137
|
+
"%": ()
|
138
|
+
"%i": ()
|
139
|
+
"%q": ()
|
140
|
+
"%Q": ()
|
141
|
+
"%r": "{}"
|
142
|
+
"%s": ()
|
143
|
+
"%w": ()
|
144
|
+
"%W": ()
|
145
|
+
"%x": ()
|
146
|
+
|
147
|
+
Security/YAMLLoad:
|
148
|
+
Enabled: false
|
data/.ruby-version
ADDED
data/.travis.yml
ADDED
data/Dangerfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Disable linting of Dangerfile.
|
2
|
+
# rubocop:disable all
|
3
|
+
|
4
|
+
has_app_changes = !git.modified_files.grep(/(bin|ext|lib)/).empty?
|
5
|
+
|
6
|
+
warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
|
7
|
+
|
8
|
+
warn("Big PR, try to keep changes smaller if you can") if git.lines_of_code > 500
|
9
|
+
|
10
|
+
rubocop.lint
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
danger-l10nlint (0.0.5)
|
5
|
+
danger-plugin-api (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.1)
|
11
|
+
public_suffix (>= 2.0.2, < 6.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
claide (1.1.0)
|
14
|
+
claide-plugins (0.9.2)
|
15
|
+
cork
|
16
|
+
nap
|
17
|
+
open4 (~> 1.3)
|
18
|
+
coderay (1.1.3)
|
19
|
+
colored2 (3.1.2)
|
20
|
+
cork (0.3.0)
|
21
|
+
colored2 (~> 3.1)
|
22
|
+
danger (9.2.0)
|
23
|
+
claide (~> 1.0)
|
24
|
+
claide-plugins (>= 0.9.2)
|
25
|
+
colored2 (~> 3.1)
|
26
|
+
cork (~> 0.1)
|
27
|
+
faraday (>= 0.9.0, < 3.0)
|
28
|
+
faraday-http-cache (~> 2.0)
|
29
|
+
git (~> 1.7)
|
30
|
+
kramdown (~> 2.3)
|
31
|
+
kramdown-parser-gfm (~> 1.0)
|
32
|
+
no_proxy_fix
|
33
|
+
octokit (~> 5.0)
|
34
|
+
terminal-table (>= 1, < 4)
|
35
|
+
danger-plugin-api (1.0.0)
|
36
|
+
danger (> 2.0)
|
37
|
+
diff-lcs (1.5.0)
|
38
|
+
faraday (2.7.4)
|
39
|
+
faraday-net_http (>= 2.0, < 3.1)
|
40
|
+
ruby2_keywords (>= 0.0.4)
|
41
|
+
faraday-http-cache (2.4.1)
|
42
|
+
faraday (>= 0.8)
|
43
|
+
faraday-net_http (3.0.2)
|
44
|
+
ffi (1.15.5)
|
45
|
+
formatador (1.1.0)
|
46
|
+
git (1.13.2)
|
47
|
+
addressable (~> 2.8)
|
48
|
+
rchardet (~> 1.8)
|
49
|
+
guard (2.18.0)
|
50
|
+
formatador (>= 0.2.4)
|
51
|
+
listen (>= 2.7, < 4.0)
|
52
|
+
lumberjack (>= 1.0.12, < 2.0)
|
53
|
+
nenv (~> 0.1)
|
54
|
+
notiffany (~> 0.0)
|
55
|
+
pry (>= 0.13.0)
|
56
|
+
shellany (~> 0.0)
|
57
|
+
thor (>= 0.18.1)
|
58
|
+
guard-compat (1.2.1)
|
59
|
+
guard-rspec (4.7.3)
|
60
|
+
guard (~> 2.1)
|
61
|
+
guard-compat (~> 1.1)
|
62
|
+
rspec (>= 2.99.0, < 4.0)
|
63
|
+
json (2.6.3)
|
64
|
+
kramdown (2.4.0)
|
65
|
+
rexml
|
66
|
+
kramdown-parser-gfm (1.1.0)
|
67
|
+
kramdown (~> 2.0)
|
68
|
+
listen (3.0.7)
|
69
|
+
rb-fsevent (>= 0.9.3)
|
70
|
+
rb-inotify (>= 0.9.7)
|
71
|
+
lumberjack (1.2.8)
|
72
|
+
method_source (1.0.0)
|
73
|
+
nap (1.1.0)
|
74
|
+
nenv (0.3.0)
|
75
|
+
no_proxy_fix (0.1.2)
|
76
|
+
notiffany (0.1.3)
|
77
|
+
nenv (~> 0.1)
|
78
|
+
shellany (~> 0.0)
|
79
|
+
octokit (5.6.1)
|
80
|
+
faraday (>= 1, < 3)
|
81
|
+
sawyer (~> 0.9)
|
82
|
+
open4 (1.3.4)
|
83
|
+
parallel (1.22.1)
|
84
|
+
parser (3.2.0.0)
|
85
|
+
ast (~> 2.4.1)
|
86
|
+
pry (0.14.2)
|
87
|
+
coderay (~> 1.1)
|
88
|
+
method_source (~> 1.0)
|
89
|
+
public_suffix (5.0.1)
|
90
|
+
rainbow (3.1.1)
|
91
|
+
rake (10.5.0)
|
92
|
+
rb-fsevent (0.11.2)
|
93
|
+
rb-inotify (0.10.1)
|
94
|
+
ffi (~> 1.0)
|
95
|
+
rchardet (1.8.0)
|
96
|
+
regexp_parser (2.6.2)
|
97
|
+
rexml (3.2.5)
|
98
|
+
rspec (3.12.0)
|
99
|
+
rspec-core (~> 3.12.0)
|
100
|
+
rspec-expectations (~> 3.12.0)
|
101
|
+
rspec-mocks (~> 3.12.0)
|
102
|
+
rspec-core (3.12.1)
|
103
|
+
rspec-support (~> 3.12.0)
|
104
|
+
rspec-expectations (3.12.2)
|
105
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
106
|
+
rspec-support (~> 3.12.0)
|
107
|
+
rspec-mocks (3.12.3)
|
108
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
109
|
+
rspec-support (~> 3.12.0)
|
110
|
+
rspec-support (3.12.0)
|
111
|
+
rubocop (1.44.1)
|
112
|
+
json (~> 2.3)
|
113
|
+
parallel (~> 1.10)
|
114
|
+
parser (>= 3.2.0.0)
|
115
|
+
rainbow (>= 2.2.2, < 4.0)
|
116
|
+
regexp_parser (>= 1.8, < 3.0)
|
117
|
+
rexml (>= 3.2.5, < 4.0)
|
118
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
119
|
+
ruby-progressbar (~> 1.7)
|
120
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
121
|
+
rubocop-ast (1.24.1)
|
122
|
+
parser (>= 3.1.1.0)
|
123
|
+
ruby-progressbar (1.11.0)
|
124
|
+
ruby2_keywords (0.0.5)
|
125
|
+
sawyer (0.9.2)
|
126
|
+
addressable (>= 2.3.5)
|
127
|
+
faraday (>= 0.17.3, < 3)
|
128
|
+
shellany (0.0.1)
|
129
|
+
terminal-table (3.0.2)
|
130
|
+
unicode-display_width (>= 1.1.1, < 3)
|
131
|
+
thor (1.2.1)
|
132
|
+
unicode-display_width (2.4.2)
|
133
|
+
webrick (1.7.0)
|
134
|
+
yard (0.9.28)
|
135
|
+
webrick (~> 1.7.0)
|
136
|
+
|
137
|
+
PLATFORMS
|
138
|
+
ruby
|
139
|
+
|
140
|
+
DEPENDENCIES
|
141
|
+
bundler (~> 2.0)
|
142
|
+
danger-l10nlint!
|
143
|
+
guard (~> 2.14)
|
144
|
+
guard-rspec (~> 4.7)
|
145
|
+
listen (= 3.0.7)
|
146
|
+
pry
|
147
|
+
rake (~> 10.0)
|
148
|
+
rspec (~> 3.4)
|
149
|
+
rubocop
|
150
|
+
yard
|
151
|
+
|
152
|
+
BUNDLED WITH
|
153
|
+
2.1.4
|
data/Guardfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A guardfile for making Danger Plugins
|
4
|
+
# For more info see https://github.com/guard/guard#readme
|
5
|
+
|
6
|
+
# To run, use `bundle exec guard`.
|
7
|
+
|
8
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
9
|
+
require "guard/rspec/dsl"
|
10
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
11
|
+
|
12
|
+
# RSpec files
|
13
|
+
rspec = dsl.rspec
|
14
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
15
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
16
|
+
watch(rspec.spec_files)
|
17
|
+
|
18
|
+
# Ruby files
|
19
|
+
ruby = dsl.ruby
|
20
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
21
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2023 Kazumasa Shimomura <kazu.devapp@gmail.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# danger-l10nlint
|
2
|
+
|
3
|
+
A description of danger-l10nlint.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install danger-l10nlint
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Methods and attributes from this plugin are available in
|
12
|
+
your `Dangerfile` under the `l10nlint` namespace.
|
13
|
+
|
14
|
+
## Development
|
15
|
+
|
16
|
+
1. Clone this repo
|
17
|
+
2. Run `bundle install` to setup dependencies.
|
18
|
+
3. Run `bundle exec rake spec` to run the tests.
|
19
|
+
4. Use `bundle exec guard` to automatically have tests run as you make changes.
|
20
|
+
5. Make your changes.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "rubocop/rake_task"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:specs)
|
8
|
+
|
9
|
+
task default: :specs
|
10
|
+
|
11
|
+
task :spec do
|
12
|
+
Rake::Task["specs"].invoke
|
13
|
+
Rake::Task["rubocop"].invoke
|
14
|
+
Rake::Task["spec_docs"].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run RuboCop on the lib/specs directory"
|
18
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
19
|
+
task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Ensure that the plugin passes `danger plugins lint`"
|
23
|
+
task :spec_docs do
|
24
|
+
sh "bundle exec danger plugins lint"
|
25
|
+
end
|
data/bin/danger-l10nlint
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
if $PROGRAM_NAME == __FILE__
|
5
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'thor'
|
9
|
+
require 'version'
|
10
|
+
|
11
|
+
class DangerL10nLintCLI < Thor
|
12
|
+
desc 'version', 'The version of the installed danger-l10nlint plugin'
|
13
|
+
def version
|
14
|
+
puts DangerL10nLint::VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'l10nlint_version', 'The L10nLint version used by the plugin'
|
18
|
+
def l10nlint_version
|
19
|
+
puts DangerL10nLint::L10NLINT_VERSION
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
DangerL10nLintCLI.start(ARGV)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "danger-l10nlint"
|
9
|
+
spec.version = DangerL10nLint::VERSION
|
10
|
+
spec.authors = ["Kazumasa Shimomura"]
|
11
|
+
spec.email = ["kazu.devapp@gmail.com"]
|
12
|
+
spec.description = "A short description of danger-l10nlint."
|
13
|
+
spec.summary = "A longer description of danger-l10nlint."
|
14
|
+
spec.homepage = "https://github.com/s2mr/danger-l10nlint"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
|
23
|
+
|
24
|
+
# General ruby development
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
|
28
|
+
# Testing support
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
30
|
+
|
31
|
+
# Linting code and docs
|
32
|
+
spec.add_development_dependency "rubocop"
|
33
|
+
spec.add_development_dependency "yard"
|
34
|
+
|
35
|
+
# Makes testing easy via `bundle exec guard`
|
36
|
+
spec.add_development_dependency "guard", "~> 2.14"
|
37
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
38
|
+
|
39
|
+
# If you want to work on older builds of ruby
|
40
|
+
spec.add_development_dependency "listen", "3.0.7"
|
41
|
+
|
42
|
+
# This gives you the chance to run a REPL inside your tests
|
43
|
+
# via:
|
44
|
+
#
|
45
|
+
# require 'pry'
|
46
|
+
# binding.pry
|
47
|
+
#
|
48
|
+
# This will stop test execution and let you inspect the results
|
49
|
+
spec.add_development_dependency "pry"
|
50
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class L10nLint
|
4
|
+
def initialize(l10nlint_path = nil)
|
5
|
+
@l10nlint_path = l10nlint_path
|
6
|
+
end
|
7
|
+
|
8
|
+
def installed?
|
9
|
+
File.exist?(l10nlint_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def l10nlint_path
|
13
|
+
@l10nlint_path || default_l10nlint_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_l10nlint_path
|
17
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'bin', 'l10nlint'))
|
18
|
+
end
|
19
|
+
|
20
|
+
# Shortcut for running the lint command
|
21
|
+
def lint(options, additional_l10nlint_args, env = nil)
|
22
|
+
run('lint', additional_l10nlint_args, options, env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def run(cmd = 'lint', additional_l10nlint_args = '', options = {}, env = nil)
|
26
|
+
# allow for temporary change to pwd before running l10nlint
|
27
|
+
pwd = options.delete(:pwd)
|
28
|
+
command = "#{l10nlint_path} #{cmd} #{l10nlint_arguments(options, additional_l10nlint_args)}"
|
29
|
+
|
30
|
+
# Add `env` to environment
|
31
|
+
update_env(env)
|
32
|
+
begin
|
33
|
+
# run l10nlint with provided options
|
34
|
+
if pwd
|
35
|
+
Dir.chdir(pwd) do
|
36
|
+
`#{command}`
|
37
|
+
end
|
38
|
+
else
|
39
|
+
`#{command}`
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
# Remove any ENV variables we might have added
|
43
|
+
restore_env()
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Parse options into shell arguments how swift expect it to be
|
48
|
+
# more information: https://github.com/Carthage/Commandant
|
49
|
+
# @param options (Hash) hash containing l10nlint options
|
50
|
+
def l10nlint_arguments(options, additional_l10nlint_args)
|
51
|
+
(options.
|
52
|
+
# filter not null
|
53
|
+
reject { |_key, value| value.nil? }.
|
54
|
+
# map booleans arguments equal true
|
55
|
+
map { |key, value| value.is_a?(TrueClass) ? [key, ''] : [key, value] }.
|
56
|
+
# map booleans arguments equal false
|
57
|
+
map { |key, value| value.is_a?(FalseClass) ? ["no-#{key}", ''] : [key, value] }.
|
58
|
+
# replace underscore by hyphen
|
59
|
+
map { |key, value| [key.to_s.tr('_', '-'), value] }.
|
60
|
+
# prepend '--' into the argument
|
61
|
+
map { |key, value| ["--#{key}", value] }.
|
62
|
+
# reduce everything into a single string
|
63
|
+
reduce('') { |args, option| "#{args} #{option[0]} #{option[1]}" } +
|
64
|
+
" #{additional_l10nlint_args}").
|
65
|
+
# strip leading spaces
|
66
|
+
strip
|
67
|
+
end
|
68
|
+
|
69
|
+
# Adds `env` to shell environment as variables
|
70
|
+
# @param env (Hash) hash containing environment variables to add
|
71
|
+
def update_env(env)
|
72
|
+
return if !env || env.empty?
|
73
|
+
# Keep the same @original_env if we've already set it, since that would mean
|
74
|
+
# that we're adding more variables, in which case, we want to make sure to
|
75
|
+
# keep the true original when we go to restore it.
|
76
|
+
@original_env = ENV.to_h if @original_env.nil?
|
77
|
+
# Add `env` to environment
|
78
|
+
ENV.update(env)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Restores shell environment to values in `@original_env`
|
82
|
+
# All environment variables not in `@original_env` will be removed
|
83
|
+
def restore_env()
|
84
|
+
if !@original_env.nil?
|
85
|
+
ENV.replace(@original_env)
|
86
|
+
@original_env = nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|