danger-swiftlint 0.5.1 → 0.6.0

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: 40757cebea3dbc6624dba8273588487d0cdde1f7
4
- data.tar.gz: 6c95846be51abaeec3ee99ed87eeb3c082fdd70a
3
+ metadata.gz: 42941a3250343254bbbd9b0a3e845e3189ebb157
4
+ data.tar.gz: 47b56832f6257a32b49d37a9235da7cf2d239fe6
5
5
  SHA512:
6
- metadata.gz: 736318a6287be021e6d95a537cb4d067a15892e9e884ee0ca4a607626f75200b68d68258a9f47de55f65977268f9e87052597f45ac689fb0da7a7843abf8bebc
7
- data.tar.gz: d22f58da0bec13124cfbb29b142ed2b0dcfac6a25ebcd3a88fcd21768e781c18dd87d8279e185ccd623ee5158b8b8c18202775abb4377928b11264dc37cdee6e
6
+ metadata.gz: 10dbebfab42898a4da68918d98cbe2a4fb230697b7d46a0dc081f96689b1337b37e7bd7f7c29e8d099723438eda74997f82025c4675dc7718747cbe0db75ca7c
7
+ data.tar.gz: 27a6f1a2a1769462f543e200cc64a75c4cfcc5e488519607394d05d580ab6ca94222ead20b8a65b0f31bb98d806da2451beaae9eb8500b4c51f5db6e77293c46
@@ -4,6 +4,10 @@
4
4
 
5
5
  - Nothing yet!
6
6
 
7
+ ## 0.6.0
8
+
9
+ - Fixes problem with differing swiftlint paths. See [#44](https://github.com/ashfurrow/danger-swiftlint/issues/44).
10
+
7
11
  ## 0.5.1
8
12
 
9
13
  - Fixed excluded files containing characters that need escaping. See [#40](https://github.com/ashfurrow/danger-swiftlint/pull/40).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-swiftlint (0.5.0)
4
+ danger-swiftlint (0.6.0)
5
5
  danger
6
6
  rake (> 10)
7
7
  thor (~> 0.19)
@@ -12,7 +12,7 @@ GEM
12
12
  addressable (2.5.1)
13
13
  public_suffix (~> 2.0, >= 2.0.2)
14
14
  bacon (1.2.0)
15
- claide (1.0.1)
15
+ claide (1.0.2)
16
16
  claide-plugins (0.9.2)
17
17
  cork
18
18
  nap
@@ -21,7 +21,7 @@ GEM
21
21
  colored2 (3.1.2)
22
22
  cork (0.3.0)
23
23
  colored2 (~> 3.1)
24
- danger (5.2.1)
24
+ danger (5.3.3)
25
25
  claide (~> 1.0)
26
26
  claide-plugins (>= 0.9.2)
27
27
  colored2 (~> 3.1)
@@ -30,7 +30,7 @@ GEM
30
30
  faraday-http-cache (~> 1.0)
31
31
  git (~> 1)
32
32
  kramdown (~> 1.5)
33
- octokit (~> 4.2)
33
+ octokit (~> 4.7)
34
34
  terminal-table (~> 1)
35
35
  diff-lcs (1.3)
36
36
  faraday (0.12.1)
@@ -54,7 +54,7 @@ GEM
54
54
  guard (~> 2.1)
55
55
  guard-compat (~> 1.1)
56
56
  rspec (>= 2.99.0, < 4.0)
57
- kramdown (1.13.2)
57
+ kramdown (1.14.0)
58
58
  listen (3.0.7)
59
59
  rb-fsevent (>= 0.9.3)
60
60
  rb-inotify (>= 0.9.7)
@@ -106,7 +106,7 @@ GEM
106
106
  terminal-table (1.8.0)
107
107
  unicode-display_width (~> 1.1, >= 1.1.1)
108
108
  thor (0.19.4)
109
- unicode-display_width (1.2.1)
109
+ unicode-display_width (1.3.0)
110
110
 
111
111
  PLATFORMS
112
112
  ruby
@@ -125,4 +125,4 @@ DEPENDENCIES
125
125
  rspec (~> 3.4)
126
126
 
127
127
  BUNDLED WITH
128
- 1.14.6
128
+ 1.15.0
data/README.md CHANGED
@@ -26,6 +26,7 @@ That's going to lint all your Swift files. It would be better to only lint the c
26
26
 
27
27
  ```rb
28
28
  swiftlint.config_file = '.swiftlint.yml'
29
+ swiftlint.binary_path = '/path/to/swiftlint'
29
30
  swiftlint.lint_files
30
31
  ```
31
32
 
@@ -1,58 +1,60 @@
1
1
 
2
2
  class Swiftlint
3
- class << self
4
- # Runs swiftlint
5
- # @param key (Symbol) the key which is used as command paramters or key in the fastlane tools
6
- # @param env_name (String) the name of the environment variable, which is only used if no other values were found
7
- # @param description (String) A description shown to the user
8
- # @param sensitive (Boolean) Set if the variable is sensitive, such as a password or API token, to prevent echoing when prompted for the parameter
9
- def run(cmd='lint', options={})
10
-
11
- # change pwd before run swiftlint
12
- if options.has_key? :pwd
13
- Dir.chdir options.delete(:pwd)
14
- end
15
-
16
- # run swiftlint with provided options
17
- `#{swiftlint_path} #{cmd} #{swiftlint_arguments(options)}`
18
- end
3
+ def initialize(swiftlint_path=nil)
4
+ @swiftlint_path = swiftlint_path
5
+ end
19
6
 
20
- # Shortcut for running the lint command
21
- def lint(options)
22
- run('lint', options)
7
+ # Runs swiftlint
8
+ def run(cmd='lint', options={})
9
+ # change pwd before run swiftlint
10
+ if options.has_key? :pwd
11
+ Dir.chdir options.delete(:pwd)
23
12
  end
24
13
 
25
- # Return true if swiftlint is installed or false otherwise
26
- def is_installed?
27
- File.exist?(swiftlint_path)
28
- end
14
+ # run swiftlint with provided options
15
+ `#{swiftlint_path} #{cmd} #{swiftlint_arguments(options)}`
16
+ end
29
17
 
30
- private
31
-
32
- # Parse options into shell arguments how swift expect it to be
33
- # more information: https://github.com/Carthage/Commandant
34
- # @param options (Hash) hash containing swiftlint options
35
- def swiftlint_arguments options
36
- options.
37
- # filter not null
38
- select {|key, value| !value.nil?}.
39
- # map booleans arguments equal true
40
- map { |key, value| value.is_a?(TrueClass) ? [key, ''] : [key, value] }.
41
- # map booleans arguments equal false
42
- map { |key, value| value.is_a?(FalseClass) ? ["no-#{key}", ''] : [key, value] }.
43
- # replace underscore by hyphen
44
- map { |key, value| [key.to_s.tr('_', '-'), value] }.
45
- # prepend '--' into the argument
46
- map { |key, value| ["--#{key}", value] }.
47
- # reduce everything into a single string
48
- reduce('') { |args, option| "#{args} #{option[0]} #{option[1]}" }.
49
- # strip leading spaces
50
- strip
51
- end
18
+ # Shortcut for running the lint command
19
+ def lint(options)
20
+ run('lint', options)
21
+ end
52
22
 
53
- # Path where swiftlint should be found
54
- def swiftlint_path
55
- File.expand_path(File.join(File.dirname(__FILE__), 'bin', 'swiftlint'))
56
- end
23
+ # Return true if swiftlint is installed or false otherwise
24
+ def is_installed?
25
+ File.exist?(swiftlint_path)
26
+ end
27
+
28
+ # Return swiftlint execution path
29
+ def swiftlint_path
30
+ @swiftlint_path or default_swiftlint_path
31
+ end
32
+
33
+ private
34
+
35
+ # Parse options into shell arguments how swift expect it to be
36
+ # more information: https://github.com/Carthage/Commandant
37
+ # @param options (Hash) hash containing swiftlint options
38
+ def swiftlint_arguments options
39
+ options.
40
+ # filter not null
41
+ select {|key, value| !value.nil?}.
42
+ # map booleans arguments equal true
43
+ map { |key, value| value.is_a?(TrueClass) ? [key, ''] : [key, value] }.
44
+ # map booleans arguments equal false
45
+ map { |key, value| value.is_a?(FalseClass) ? ["no-#{key}", ''] : [key, value] }.
46
+ # replace underscore by hyphen
47
+ map { |key, value| [key.to_s.tr('_', '-'), value] }.
48
+ # prepend '--' into the argument
49
+ map { |key, value| ["--#{key}", value] }.
50
+ # reduce everything into a single string
51
+ reduce('') { |args, option| "#{args} #{option[0]} #{option[1]}" }.
52
+ # strip leading spaces
53
+ strip
54
+ end
55
+
56
+ # Path where swiftlint should be found
57
+ def default_swiftlint_path
58
+ File.expand_path(File.join(File.dirname(__FILE__), 'bin', 'swiftlint'))
57
59
  end
58
60
  end
@@ -19,6 +19,8 @@ module Danger
19
19
  # @tags swift
20
20
  #
21
21
  class DangerSwiftlint < Plugin
22
+ # The path to SwiftLint's execution
23
+ attr_accessor :binary_path
22
24
 
23
25
  # The path to SwiftLint's configuration file
24
26
  attr_accessor :config_file
@@ -36,7 +38,7 @@ module Danger
36
38
  #
37
39
  def lint_files(files=nil, inline_mode: false)
38
40
  # Fails if swiftlint isn't installed
39
- raise "swiftlint is not installed" unless Swiftlint.is_installed?
41
+ raise "swiftlint is not installed" unless swiftlint.is_installed?
40
42
 
41
43
  # Extract excluded paths
42
44
  excluded_paths = excluded_files_from_config(config_file)
@@ -80,7 +82,7 @@ module Danger
80
82
  def run_swiftlint(files, options)
81
83
  files
82
84
  .map { |file| options.merge({path: file})}
83
- .map { |full_options| Swiftlint.lint(full_options)}
85
+ .map { |full_options| swiftlint.lint(full_options)}
84
86
  .reject { |s| s == '' }
85
87
  .map { |s| JSON.parse(s).flatten }
86
88
  .flatten
@@ -162,5 +164,12 @@ module Danger
162
164
  send(method, r['reason'], file: filename, line: r['line'])
163
165
  end
164
166
  end
167
+
168
+ # Make SwiftLint object for binary_path
169
+ #
170
+ # @return [SwiftLint]
171
+ def swiftlint
172
+ Swiftlint.new(binary_path)
173
+ end
165
174
  end
166
175
  end
@@ -1,4 +1,4 @@
1
1
  module DangerSwiftlint
2
- VERSION = "0.5.1".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  SWIFTLINT_VERSION = "0.18.1".freeze
4
4
  end
@@ -13,18 +13,29 @@ module Danger
13
13
  end
14
14
 
15
15
  it "handles swiftlint not being installed" do
16
- allow(Swiftlint).to receive(:is_installed?).and_return(false)
16
+ allow_any_instance_of(Swiftlint).to receive(:is_installed?).and_return(false)
17
17
  expect { @swiftlint.lint_files }.to raise_error("swiftlint is not installed")
18
18
  end
19
19
 
20
20
  it 'does not markdown an empty message' do
21
- allow(Swiftlint).to receive(:lint).and_return('[]')
21
+ allow_any_instance_of(Swiftlint).to receive(:lint).and_return('[]')
22
22
  expect(@swiftlint.status_report[:markdowns].first).to be_nil
23
23
  end
24
24
 
25
+ context 'with binary_path' do
26
+ let(:binary_path) { '/path/to/swiftlint' }
27
+ it 'passes binary_path to constructor' do
28
+ @swiftlint.binary_path = binary_path
29
+ swiftlint = double('swiftlint')
30
+ allow(Swiftlint).to receive(:new).with(binary_path).and_return(swiftlint)
31
+
32
+ expect(@swiftlint.swiftlint).to eql(swiftlint)
33
+ end
34
+ end
35
+
25
36
  describe :lint_files do
26
37
  before do
27
- allow(Swiftlint).to receive(:is_installed?).and_return(true)
38
+ allow_any_instance_of(Swiftlint).to receive(:is_installed?).and_return(true)
28
39
  allow(@swiftlint.git).to receive(:added_files).and_return([])
29
40
  allow(@swiftlint.git).to receive(:modified_files).and_return([])
30
41
 
@@ -32,7 +43,7 @@ module Danger
32
43
  end
33
44
 
34
45
  it 'accept files as arguments' do
35
- expect(Swiftlint).to receive(:lint)
46
+ expect_any_instance_of(Swiftlint).to receive(:lint)
36
47
  .with(hash_including(:path => File.expand_path('spec/fixtures/SwiftFile.swift')))
37
48
  .and_return(@swiftlint_response)
38
49
 
@@ -46,7 +57,7 @@ module Danger
46
57
  it 'uses git diff when files are not provided' do
47
58
  allow(@swiftlint.git).to receive(:modified_files).and_return(['spec/fixtures/SwiftFile.swift'])
48
59
  allow(@swiftlint.git).to receive(:added_files).and_return([])
49
- allow(Swiftlint).to receive(:lint)
60
+ allow_any_instance_of(Swiftlint).to receive(:lint)
50
61
  .with(hash_including(:path => File.expand_path('spec/fixtures/SwiftFile.swift')))
51
62
  .and_return(@swiftlint_response)
52
63
 
@@ -59,7 +70,7 @@ module Danger
59
70
  it 'uses a custom directory' do
60
71
  @swiftlint.directory = 'some_dir'
61
72
 
62
- allow(Swiftlint).to receive(:lint)
73
+ allow_any_instance_of(Swiftlint).to receive(:lint)
63
74
  .with(hash_including(:pwd => @swiftlint.directory))
64
75
  .and_return(@swiftlint_response)
65
76
 
@@ -82,7 +93,7 @@ module Danger
82
93
  # would then become an empty string, which cannot be parsed into a
83
94
  # JSON object.
84
95
 
85
- allow(Swiftlint).to receive(:lint).and_return('')
96
+ allow_any_instance_of(Swiftlint).to receive(:lint).and_return('')
86
97
 
87
98
  expect { @swiftlint.lint_files }.not_to raise_error
88
99
  end
@@ -95,10 +106,10 @@ module Danger
95
106
  'spec/fixtures/excluded_dir/SwiftFile WithEscaped+CharactersThatShouldNotBeIncluded.swift'
96
107
  ])
97
108
 
98
- expect(Swiftlint).to receive(:lint)
109
+ expect_any_instance_of(Swiftlint).to receive(:lint)
99
110
  .with(hash_including(:path => File.expand_path('spec/fixtures/SwiftFile.swift')))
100
- .and_return(@swiftlint_response)
101
111
  .once
112
+ .and_return(@swiftlint_response)
102
113
 
103
114
  @swiftlint.config_file = 'spec/fixtures/some_config.yml'
104
115
  @swiftlint.lint_files
@@ -110,10 +121,10 @@ module Danger
110
121
  'spec/fixtures/SwiftFile.swift',
111
122
  ])
112
123
 
113
- expect(Swiftlint).to receive(:lint)
124
+ expect_any_instance_of(Swiftlint).to receive(:lint)
114
125
  .with(hash_including(:path => File.expand_path('spec/fixtures/SwiftFile.swift')))
115
- .and_return(@swiftlint_response)
116
126
  .once
127
+ .and_return(@swiftlint_response)
117
128
 
118
129
  @swiftlint.config_file = 'spec/fixtures/empty_excluded.yml'
119
130
  @swiftlint.lint_files
@@ -133,16 +144,16 @@ module Danger
133
144
  'spec/fixtures/DeletedFile.swift'
134
145
  ])
135
146
 
136
- expect(Swiftlint).to receive(:lint)
147
+ expect_any_instance_of(Swiftlint).to receive(:lint)
137
148
  .with(hash_including(:path => File.expand_path('spec/fixtures/SwiftFile.swift')))
138
- .and_return(@swiftlint_response)
139
149
  .once
150
+ .and_return(@swiftlint_response)
140
151
 
141
152
  @swiftlint.lint_files
142
153
  end
143
154
 
144
155
  it 'generates errors instead of markdown when use inline mode' do
145
- allow(Swiftlint).to receive(:lint)
156
+ allow_any_instance_of(Swiftlint).to receive(:lint)
146
157
  .with(hash_including(:path => File.expand_path('spec/fixtures/SwiftFile.swift')))
147
158
  .and_return(@swiftlint_response)
148
159
 
@@ -2,24 +2,37 @@ require File.expand_path('../spec_helper', __FILE__)
2
2
  require_relative '../ext/swiftlint/swiftlint'
3
3
 
4
4
  describe Swiftlint do
5
+ let(:swiftlint) { Swiftlint.new }
5
6
  it 'is_installed? works based on bin/swiftlint file' do
6
7
  expect(File).to receive(:exist?).with(/bin\/swiftlint/).and_return(true)
7
- expect(Swiftlint.is_installed?).to be_truthy
8
+ expect(swiftlint.is_installed?).to be_truthy
8
9
 
9
10
  expect(File).to receive(:exist?).with(/bin\/swiftlint/).and_return(false)
10
- expect(Swiftlint.is_installed?).to be_falsy
11
+ expect(swiftlint.is_installed?).to be_falsy
12
+ end
13
+
14
+ context 'with binary_path' do
15
+ let(:binary_path) { '/path/to/swiftlint' }
16
+ let(:swiftlint) { Swiftlint.new(binary_path) }
17
+ it 'is_installed? works based on specific path' do
18
+ expect(File).to receive(:exist?).with(binary_path).and_return(true)
19
+ expect(swiftlint.is_installed?).to be_truthy
20
+
21
+ expect(File).to receive(:exist?).with(binary_path).and_return(false)
22
+ expect(swiftlint.is_installed?).to be_falsy
23
+ end
11
24
  end
12
25
 
13
26
  it 'runs lint by default with options being optional' do
14
- expect(Swiftlint).to receive(:`).with(including('swiftlint lint'))
15
- Swiftlint.run()
27
+ expect(swiftlint).to receive(:`).with(including('swiftlint lint'))
28
+ swiftlint.run()
16
29
  end
17
30
 
18
31
  it 'runs accepting symbolized options' do
19
32
  cmd = 'swiftlint lint --no-use-stdin --cache-path /path --enable-all-rules'
20
- expect(Swiftlint).to receive(:`).with(including(cmd))
33
+ expect(swiftlint).to receive(:`).with(including(cmd))
21
34
 
22
- Swiftlint.run('lint',
35
+ swiftlint.run('lint',
23
36
  use_stdin: false,
24
37
  cache_path: '/path',
25
38
  enable_all_rules: true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-swiftlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash Furrow
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-05-24 00:00:00.000000000 Z
15
+ date: 2017-07-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: danger