danger-android_lint 0.0.3 → 0.0.4

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: 14a8b24ca402a1f8615991280e363bf0fe02eb9d
4
- data.tar.gz: 4be292fab2a1db392f729bda485a831f1533c611
3
+ metadata.gz: bc51ff27951c956c5534a2adc9219db6ef8b23ea
4
+ data.tar.gz: 162c31a66338d95c2d184864ad9cbbb02377668c
5
5
  SHA512:
6
- metadata.gz: f5842a73db7eaac24acc5a704c582bbbcd690b95499392f57214e45fb6bd9eb71dbd510cc17456017922823a1544bda1bf8ee63dd62371cd1c47bdbc06c48301
7
- data.tar.gz: 205b8756e1b4f3fdf34256b4baa551475fcec0e5ec239dc68fde22616856c6ae7052b44b66bd9898d6683c5aceeba93e44a7cef7d8427a715ef0f6d2fbada307
6
+ metadata.gz: e34ff70dab0f608b3bfd09aa5f3ec7e3a83812fa95f3597bbb88c67d6e3854991caf156f61ec652f7415509082731665c1bc8060dc912e98761e06f0a1728b6b
7
+ data.tar.gz: 53601dfb052fed83d66a369edfc6843759d47c9786f9bd477a65f84fb1208815f9c1a8cc66067b8de597755dfa3fb47848cff8f75ea08848737822f8d6e34374
data/CHANGELOG.md CHANGED
@@ -1,9 +1,13 @@
1
+ # 0.0.4
2
+ - Add `filtering` parameter, default to false, to run lint only on modified files ([@leonhartX](https://github.com/leonhartX))
3
+ - Add support for GitHub's inline comments ([@leonhartX](https://github.com/leonhartX))
4
+
1
5
  # 0.0.3
2
- - Add `report_file` parameter, so users can set a custom path for their report xmls (@churowa)
6
+ - Add `report_file` parameter, so users can set a custom path for their report xmls ([@churowa](https://github.com/churowa))
3
7
 
4
8
  ## 0.0.2
5
- - Fix check for inexistent report file (@barbosa)
6
- - Fix markdown message being printed without any issues reported (@barbosa)
9
+ - Fix check for inexistent report file ([@barbosa](https://github.com/barbosa))
10
+ - Fix markdown message being printed without any issues reported ([@barbosa](https://github.com/barbosa))
7
11
 
8
12
  ## 0.0.1
9
- - Initial version (@barbosa)
13
+ - Initial version ([@barbosa](https://github.com/barbosa))
data/README.md CHANGED
@@ -58,6 +58,21 @@ android_lint.severity = "Error"
58
58
  android_lint.lint
59
59
  ```
60
60
 
61
+ #### Lint only added/modified files
62
+
63
+ If you're dealing with a legacy project, with tons of warnings, you may want to lint only new/modified files. You can easily achieve that, setting the `filtering` parameter to `true`.
64
+
65
+ ```rb
66
+ android_lint.filtering = true
67
+ android_lint.lint
68
+ ```
69
+
70
+ #### Make Danger comment directly on the line instead of printing a Markdown table (GitHub only)
71
+
72
+ ```rb
73
+ android_lint.lint(inline_mode: true)
74
+ ```
75
+
61
76
  ## Development
62
77
 
63
78
  1. Clone this repo
@@ -68,4 +83,4 @@ android_lint.lint
68
83
 
69
84
  ## License
70
85
 
71
- MIT
86
+ [MIT](https://raw.githubusercontent.com/loadsmart/danger-android_lint/master/LICENSE.txt)
@@ -1,3 +1,3 @@
1
1
  module AndroidLint
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
@@ -50,13 +50,17 @@ module Danger
50
50
  # @return [String]
51
51
  attr_writer :severity
52
52
 
53
+ # Enable filtering
54
+ # Only show messages within changed files.
55
+ attr_accessor :filtering
56
+
53
57
  # Calls lint task of your gradle project.
54
58
  # It fails if `gradlew` cannot be found inside current directory.
55
59
  # It fails if `severity` level is not a valid option.
56
60
  # It fails if `xmlReport` configuration is not set to `true` in your `build.gradle` file.
57
61
  # @return [void]
58
62
  #
59
- def lint
63
+ def lint(inline_mode: false)
60
64
  unless gradlew_exists?
61
65
  fail("Could not find `gradlew` inside current directory")
62
66
  return
@@ -77,8 +81,13 @@ module Danger
77
81
  issues = read_issues_from_report
78
82
  filtered_issues = filter_issues_by_severity(issues)
79
83
 
80
- message = message_for_issues(filtered_issues)
81
- markdown(message) unless filtered_issues.empty?
84
+ if inline_mode
85
+ # Report with inline comment
86
+ send_inline_comment(filtered_issues)
87
+ else
88
+ message = message_for_issues(filtered_issues)
89
+ markdown(message) unless filtered_issues.empty?
90
+ end
82
91
  end
83
92
 
84
93
  # A getter for `severity`, returning "Warning" if value is nil.
@@ -120,6 +129,8 @@ module Danger
120
129
  end
121
130
 
122
131
  def parse_results(results, heading)
132
+ target_files = (git.modified_files - git.deleted_files) + git.added_files
133
+ dir = "#{Dir.pwd}/"
123
134
  message = "#### #{heading} (#{results.count})\n\n"
124
135
 
125
136
  message << "| File | Line | Reason |\n"
@@ -127,7 +138,8 @@ module Danger
127
138
 
128
139
  results.each do |r|
129
140
  location = r.xpath('location').first
130
- filename = location.get('file').split('/').last
141
+ filename = location.get('file').gsub(dir, "")
142
+ next unless !filtering || (target_files.include? filename)
131
143
  line = location.get('line') || 'N/A'
132
144
  reason = r.get('message')
133
145
 
@@ -137,6 +149,26 @@ module Danger
137
149
  message
138
150
  end
139
151
 
152
+
153
+ # Send inline comment with danger's warn or fail method
154
+ #
155
+ # @return [void]
156
+ def send_inline_comment (issues)
157
+ target_files = (git.modified_files - git.deleted_files) + git.added_files
158
+ dir = "#{Dir.pwd}/"
159
+ SEVERITY_LEVELS.reverse.each do |level|
160
+ filtered = issues.select{|issue| issue.get("severity") == level}
161
+ next if filtered.empty?
162
+ filtered.each do |r|
163
+ location = r.xpath('location').first
164
+ filename = location.get('file').gsub(dir, "")
165
+ next unless !filtering || (target_files.include? filename)
166
+ line = (location.get('line') || "0").to_i
167
+ send(level === "Warning" ? "warn" : "fail", r.get('message'), file: filename, line: line)
168
+ end
169
+ end
170
+ end
171
+
140
172
  def gradlew_exists?
141
173
  `ls gradlew`.strip.empty? == false
142
174
  end
@@ -10,6 +10,12 @@ module Danger
10
10
  before do
11
11
  @dangerfile = testing_dangerfile
12
12
  @android_lint = @dangerfile.android_lint
13
+ allow(@android_lint.git).to receive(:deleted_files).and_return([])
14
+ allow(@android_lint.git).to receive(:added_files).and_return([])
15
+ allow(@android_lint.git).to receive(:modified_files).and_return([
16
+ "/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/common/views/AvatarView.java",
17
+ "/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/analytics/Events.java"
18
+ ])
13
19
  end
14
20
 
15
21
  it "Fails if gradlew does not exist" do
@@ -94,13 +100,13 @@ module Danger
94
100
  expect(markdown).to include("AndroidLint found issues")
95
101
 
96
102
  expect(markdown).to include("Fatal (1)")
97
- expect(markdown).to include("`AvatarView.java` | 60 | Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead")
103
+ expect(markdown).to include("`/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/common/views/AvatarView.java` | 60 | Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead")
98
104
 
99
105
  expect(markdown).to include("Error (1)")
100
- expect(markdown).to include("`Events.java` | 21 | Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
106
+ expect(markdown).to include("`/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/analytics/Events.java` | 21 | Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
101
107
 
102
108
  expect(markdown).to include("Warning (1)")
103
- expect(markdown).to include("`Events.java` | 24 | Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
109
+ expect(markdown).to include("`/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/analytics/Events.java` | 24 | Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
104
110
  end
105
111
 
106
112
  it 'Doesn`t print anything if no errors were found' do
@@ -124,6 +130,37 @@ module Danger
124
130
  expect(markdown).to be_nil
125
131
  end
126
132
 
133
+ it 'Send inline comment instead of markdown' do
134
+ fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
135
+ allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
136
+
137
+ @android_lint.lint inline_mode: true
138
+ error = @android_lint.status_report[:errors]
139
+ expect(error).to include("Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead")
140
+ expect(error).to include("Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
141
+
142
+ warn = @android_lint.status_report[:warnings]
143
+ expect(warn).to include("Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
144
+ end
145
+
146
+ it 'Only show comment in changed files' do
147
+ allow(@android_lint.git).to receive(:modified_files).and_return([
148
+ "/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/common/views/AvatarView.java",
149
+ ])
150
+
151
+ fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
152
+ allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
153
+
154
+ @android_lint.filtering = true
155
+ @android_lint.lint inline_mode: true
156
+ error = @android_lint.status_report[:errors]
157
+ expect(error).to include("Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead")
158
+ expect(error).not_to include("Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
159
+
160
+ warn = @android_lint.status_report[:warnings]
161
+ expect(warn).not_to include("Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
162
+ end
163
+
127
164
  end
128
165
 
129
166
  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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Barbosa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-30 00:00:00.000000000 Z
11
+ date: 2017-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga