danger-swiftlint 0.7.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed68d0e1ec0a4a39d786ae12d422503c7f875bcd
4
- data.tar.gz: 6b2b17fa94ec942717d81b531088604ced20d889
3
+ metadata.gz: f3b820ec6ebe7d24aa08c97887544ab8616e1bd0
4
+ data.tar.gz: 114dd0c769d754f3d93be4bcc0f30785d018694d
5
5
  SHA512:
6
- metadata.gz: d08daff295c07b77d94cae9d3c5f8b91706daf29b44693e49ec6c741c57d003ed6ec874d231fa20aeb10837684f7a0d3038d25d80f4b7707de97a79c74a2fdca
7
- data.tar.gz: 6ad1e948574373e337e481a6cc3bc3ddeef34708f2707572107c3dadedd20abe045eb7593277b0035dee9c35ebd6340ee14cee4fab036875ef928b54202536f9
6
+ metadata.gz: 774bbbdbed22fe7159db897f198df1eed4b381369b837108260d6dfa2838168e6fc1f216c8ad4d858803f0b312d620b782a116ca9f6cfd460fda62edb8aea2aa
7
+ data.tar.gz: 4e85ea6784227a0e1a714b6aa3373b8dc197fee3f62e4ec042160815b3676026bd327116f7159270962ef166ffef9fafe6cf9140ee0ed407170dd62091f3d34d
data/Changelog.md CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  - Nothing yet!
6
6
 
7
+ ## 0.8.0
8
+
9
+ - Fixes Directory not found error. See [#51](https://github.com/ashfurrow/danger-swiftlint/pull/51).
10
+ - Fixes issue with missing `.swiftlint.yml` file. See [#52](https://github.com/ashfurrow/danger-swiftlint/pull/52).
11
+ - Adds `fail_on_error` option. See [#55](https://github.com/ashfurrow/danger-swiftlint/pull/55)
12
+
7
13
  ## 0.7.0
8
14
 
9
15
  - Bump managed SwiftLint version to 0.20.1
data/README.md CHANGED
@@ -36,6 +36,12 @@ If you want the lint result shows in diff instead of comment, you can use `inlin
36
36
  swiftlint.lint_files inline_mode: true
37
37
  ```
38
38
 
39
+ If you want lint errors to fail Danger, you can use `fail_on_error` option.
40
+
41
+ ```rb
42
+ swiftlint.lint_files fail_on_error: true
43
+ ```
44
+
39
45
  You can use the `SWIFTLINT_VERSION` environment variable to override the default version installed via the `rake install` task.
40
46
 
41
47
  ## Attribution
data/lib/danger_plugin.rb CHANGED
@@ -36,22 +36,30 @@ module Danger
36
36
  # if nil, modified and added files from the diff will be used.
37
37
  # @return [void]
38
38
  #
39
- def lint_files(files=nil, inline_mode: false)
39
+ def lint_files(files=nil, inline_mode: false, fail_on_error: false)
40
40
  # Fails if swiftlint isn't installed
41
41
  raise "swiftlint is not installed" unless swiftlint.is_installed?
42
42
 
43
+ config = if config_file
44
+ config_file
45
+ elsif File.file?('.swiftlint.yml')
46
+ '.swiftlint.yml'
47
+ else
48
+ nil
49
+ end
50
+
43
51
  # Extract excluded paths
44
- excluded_paths = excluded_files_from_config(config_file)
52
+ excluded_paths = excluded_files_from_config(config)
45
53
 
46
54
  # Extract swift files (ignoring excluded ones)
47
55
  files = find_swift_files(files, excluded_paths)
48
56
 
49
57
  # Prepare swiftlint options
50
58
  options = {
51
- config: config_file,
59
+ config: config,
52
60
  reporter: 'json',
53
61
  quiet: true,
54
- pwd: directory || Dir.pwd
62
+ pwd: directory ? File.expand_path(directory) : Dir.pwd
55
63
  }
56
64
 
57
65
  # Lint each file and collect the results
@@ -72,6 +80,11 @@ module Danger
72
80
  message << markdown_issues(warnings, 'Warnings') unless warnings.empty?
73
81
  message << markdown_issues(errors, 'Errors') unless errors.empty?
74
82
  markdown message
83
+
84
+ # Fail Danger on errors
85
+ if fail_on_error && errors.count > 0
86
+ fail "Failed due to SwiftLint errors"
87
+ end
75
88
  end
76
89
  end
77
90
  end
@@ -120,7 +133,7 @@ module Danger
120
133
  # @return [Array] list of files excluded
121
134
  def excluded_files_from_config(filepath)
122
135
  config = if filepath
123
- YAML.load_file(config_file)
136
+ YAML.load_file(filepath)
124
137
  else
125
138
  {"excluded" => []}
126
139
  end
@@ -129,7 +142,7 @@ module Danger
129
142
 
130
143
  # Extract excluded paths
131
144
  return excluded_paths.
132
- map { |path| File.join(File.dirname(config_file), path) }.
145
+ map { |path| File.join(File.dirname(filepath), path) }.
133
146
  map { |path| File.expand_path(path) }.
134
147
  select { |path| File.exists?(path) || Dir.exists?(path) }
135
148
  end
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module DangerSwiftlint
2
- VERSION = "0.7.0".freeze
2
+ VERSION = "0.8.0".freeze
3
3
  SWIFTLINT_VERSION = "0.20.1".freeze
4
4
  end
@@ -71,7 +71,7 @@ module Danger
71
71
  @swiftlint.directory = 'some_dir'
72
72
 
73
73
  allow_any_instance_of(Swiftlint).to receive(:lint)
74
- .with(hash_including(:pwd => @swiftlint.directory))
74
+ .with(hash_including(:pwd => File.expand_path(@swiftlint.directory)))
75
75
  .and_return(@swiftlint_response)
76
76
 
77
77
  @swiftlint.lint_files("spec/fixtures/*.swift")
@@ -157,7 +157,7 @@ module Danger
157
157
  .with(hash_including(:path => File.expand_path('spec/fixtures/SwiftFile.swift')))
158
158
  .and_return(@swiftlint_response)
159
159
 
160
- @swiftlint.lint_files("spec/fixtures/*.swift", inline_mode: true)
160
+ @swiftlint.lint_files("spec/fixtures/*.swift", inline_mode: true, fail_on_error: false)
161
161
 
162
162
  status = @swiftlint.status_report
163
163
  expect(status[:errors]).to_not be_empty
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.7.0
4
+ version: 0.8.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-07-12 00:00:00.000000000 Z
15
+ date: 2017-09-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: danger
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.6.12
199
+ rubygems_version: 2.6.13
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: A Danger plugin for linting Swift with SwiftLint.