danger-android_lint 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,4 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 9ada934a0418e182a4f33db8040b2ac2686b51062d9298bcafeec2641333c794
4
- data.tar.gz: f083ac782badad37b3013f29326723662c6e30fa87d1f553e9049edb0d4308b0
5
2
  SHA512:
6
- metadata.gz: 9ad11c214c69b8705766e879b6bd37c436b9ab5f5c812a5f0defedcbdd14c8d1cc012f16b16461a1426eedbd5659bd6c89aa85c4b3dcb2162984831e369ddaaa
7
- data.tar.gz: cca847253edd672cd61da0142cabdb6fb768315cf5fa44a824b0471f9f335df47700452f0b8deabe5a4fee80cec109bbfe4f8d193b695f56f8e30bedcd259460
3
+ metadata.gz: ee6bc1e76ca2a7d11670cf1d0d50438a05aa62e93c6d81b289b48e4b2c2709181a234d6f6664439dc1aa531e5b1467722aa71752934662495cf992188227381c
4
+ data.tar.gz: 0f0e99183aea7bbbda95cddeb56c29d9f939d948f627e8da60b2bf2711dd0d8a794d7349c534cf9c5fa3d6e940abbc7c1ef38e6c599792f4ee8ee5b2689b2643
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.5
1
+ 3.0.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.10
2
+
3
+ - Fix `filtering_lines` parameter to also apply to when `inline_mode` is `false` ([@petitJAM](https://github.com/petitJAM))
4
+
1
5
  # 0.0.9
2
6
  - Add `filtering_lines` parameter, to show lint issues only on modified lines ([@ShivamPokhriyal](https://github.com/ShivamPokhriyal))
3
7
 
data/Gemfile.lock CHANGED
@@ -146,6 +146,7 @@ GEM
146
146
 
147
147
  PLATFORMS
148
148
  universal-darwin-20
149
+ x86_64-linux
149
150
 
150
151
  DEPENDENCIES
151
152
  bundler (>= 2.2.10)
data/README.md CHANGED
@@ -85,6 +85,13 @@ android_lint.filtering = true
85
85
  android_lint.lint
86
86
  ```
87
87
 
88
+ Additionally, you can further filter to only the modified lines by setting the `filtering_lines` parameter to `true`.
89
+
90
+ ```rb
91
+ android_lint.filtering_lines = true
92
+ android_lint.lint
93
+ ```
94
+
88
95
  #### Make Danger comment directly on the line instead of printing a Markdown table (GitHub only)
89
96
 
90
97
  ```rb
@@ -1,3 +1,3 @@
1
1
  module AndroidLint
2
- VERSION = "0.0.9".freeze
2
+ VERSION = "0.0.10".freeze
3
3
  end
@@ -169,9 +169,13 @@ module Danger
169
169
  results.each do |r|
170
170
  location = r.xpath('location').first
171
171
  filename = location.get('file').gsub(dir, "")
172
- next unless !filtering || (target_files.include? filename)
173
- line = location.get('line') || 'N/A'
172
+ next unless (!filtering && !filtering_lines) || (target_files.include? filename)
173
+ line = location.get('line').to_i || 'N/A'
174
174
  reason = r.get('message')
175
+ if filtering_lines
176
+ added_lines = parse_added_line_numbers(git.diff[filename].patch)
177
+ next unless added_lines.include? line
178
+ end
175
179
  count = count + 1
176
180
  message << "`#{filename}` | #{line} | #{reason} \n"
177
181
  end
@@ -189,7 +193,7 @@ module Danger
189
193
  # Send inline comment with danger's warn or fail method
190
194
  #
191
195
  # @return [void]
192
- def send_inline_comment (issues)
196
+ def send_inline_comment(issues)
193
197
  target_files = (git.modified_files - git.deleted_files) + git.added_files
194
198
  dir = "#{Dir.pwd}/"
195
199
  SEVERITY_LEVELS.reverse.each do |level|
@@ -201,7 +205,7 @@ module Danger
201
205
  next unless (!filtering && !filtering_lines) || (target_files.include? filename)
202
206
  line = (location.get('line') || "0").to_i
203
207
  if filtering_lines
204
- added_lines = parseDiff(git.diff[filename].patch)
208
+ added_lines = parse_added_line_numbers(git.diff[filename].patch)
205
209
  next unless added_lines.include? line
206
210
  end
207
211
  send(level === "Warning" ? "warn" : "fail", r.get('message'), file: filename, line: line)
@@ -209,10 +213,10 @@ module Danger
209
213
  end
210
214
  end
211
215
 
212
- # parses git diff of a file and retuns an array of added line numbers.
213
- def parseDiff(diff)
216
+ # Parses git diff of a file and retuns an array of added line numbers.
217
+ def parse_added_line_numbers(diff)
214
218
  current_line_number = nil
215
- added_lines = []
219
+ added_line_numbers = []
216
220
  diff_lines = diff.strip.split("\n")
217
221
  diff_lines.each_with_index do |line, index|
218
222
  if m = /\+(\d+)(?:,\d+)? @@/.match(line)
@@ -222,7 +226,7 @@ module Danger
222
226
  if !current_line_number.nil?
223
227
  if line.start_with?('+')
224
228
  # added line
225
- added_lines.push current_line_number
229
+ added_line_numbers.push current_line_number
226
230
  current_line_number += 1
227
231
  elsif !line.start_with?('-')
228
232
  # unmodified line
@@ -231,7 +235,7 @@ module Danger
231
235
  end
232
236
  end
233
237
  end
234
- added_lines
238
+ added_line_numbers
235
239
  end
236
240
 
237
241
  def gradlew_exists?
@@ -193,7 +193,7 @@ module Danger
193
193
  allow(Dir).to receive(:pwd).and_return("/Users/shivampokhriyal/Documents/projects/Commcare/commcare-android")
194
194
 
195
195
  allow(@android_lint.git).to receive(:modified_files).and_return([
196
- "app/build.gradle",
196
+ "app/build.gradle",
197
197
  ])
198
198
 
199
199
  fake_patch = File.read("spec/fixtures/pr-diff.diff")
@@ -207,28 +207,57 @@ module Danger
207
207
  allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
208
208
  end
209
209
 
210
- it 'with filtering_lines, only show issues in modified lines' do
211
- @android_lint.filtering_lines = true
212
- @android_lint.lint inline_mode: true
210
+ context 'when inline_mode: true' do
211
+ it 'with filtering_lines, only show issues in modified lines' do
212
+ @android_lint.filtering_lines = true
213
+ @android_lint.lint inline_mode: true
213
214
 
214
- error = @android_lint.status_report[:errors]
215
- expect(error).to include("fake message three")
215
+ error = @android_lint.status_report[:errors]
216
+ expect(error).to include("fake message three")
216
217
 
217
- expect(error).not_to include("fake message one")
218
- expect(error).not_to include("fake message two")
219
- expect(error).not_to include("fake message in unmodified file")
218
+ expect(error).not_to include("fake message one")
219
+ expect(error).not_to include("fake message two")
220
+ expect(error).not_to include("fake message in unmodified file")
221
+ end
222
+
223
+ it 'with filtering, show all issues in modified files' do
224
+ @android_lint.filtering = true
225
+ @android_lint.lint inline_mode: true
226
+
227
+ error = @android_lint.status_report[:errors]
228
+ expect(error).to include("fake message one")
229
+ expect(error).to include("fake message two")
230
+ expect(error).to include("fake message three")
231
+
232
+ expect(error).not_to include("fake message in unmodified file")
233
+ end
220
234
  end
221
235
 
222
- it 'with filtering, show all issues in modified files' do
223
- @android_lint.filtering = true
224
- @android_lint.lint inline_mode: true
236
+ context 'when inline_mode: false' do
237
+ it 'with filtering_lines, only show issues in modified lines' do
238
+ @android_lint.filtering_lines = true
239
+ @android_lint.lint inline_mode: false
240
+
241
+ puts @android_lint.status_report[:markdowns]
242
+ message = @android_lint.status_report[:markdowns][0].to_s
243
+ expect(message).to include("fake message three")
244
+
245
+ expect(message).not_to include("fake message one")
246
+ expect(message).not_to include("fake message two")
247
+ expect(message).not_to include("fake message in unmodified file")
248
+ end
249
+
250
+ it 'with filtering, show all issues in modified files' do
251
+ @android_lint.filtering = true
252
+ @android_lint.lint inline_mode: false
225
253
 
226
- error = @android_lint.status_report[:errors]
227
- expect(error).to include("fake message one")
228
- expect(error).to include("fake message two")
229
- expect(error).to include("fake message three")
254
+ message = @android_lint.status_report[:markdowns][0].to_s
255
+ expect(message).to include("fake message one")
256
+ expect(message).to include("fake message two")
257
+ expect(message).to include("fake message three")
230
258
 
231
- expect(error).not_to include("fake message in unmodified file")
259
+ expect(message).not_to include("fake message in unmodified file")
260
+ end
232
261
  end
233
262
  end
234
263
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-android_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Barbosa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2022-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga
@@ -200,7 +200,7 @@ homepage: https://github.com/loadsmart/danger-android_lint
200
200
  licenses:
201
201
  - MIT
202
202
  metadata: {}
203
- post_install_message:
203
+ post_install_message:
204
204
  rdoc_options: []
205
205
  require_paths:
206
206
  - lib
@@ -215,8 +215,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  requirements: []
218
- rubygems_version: 3.0.3
219
- signing_key:
218
+ rubygems_version: 3.0.9
219
+ signing_key:
220
220
  specification_version: 4
221
221
  summary: Lint files of a gradle based Android project. This is done using the Android's
222
222
  Lint tool. Results are passed out as tables in markdown.