danger-android_lint 0.0.1 → 0.0.2

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: f282c21919c8285f09b44d4466a690e9d3208db8
4
- data.tar.gz: ea242b17a6681032b7f611894ec0e548044eb24a
3
+ metadata.gz: 6032c641b6bfe75156ded93357b0108d7f52cd37
4
+ data.tar.gz: 4e3a4911b701879fa141df99552cbaed3dee7da7
5
5
  SHA512:
6
- metadata.gz: da1f099f47ecdd976e212c1469b2bcc628e8d9051fcf69fb2f8c7809e0f4f207fad13bb9075f4ce598c459ef4653fbf6c41d70296970d6519d3b0cd5d0a5b7bb
7
- data.tar.gz: 854b76159b3d53544d08f0f34f2574ee8351a709979c85dd8e08fd127b70a85bb716655d594e7dbb5360c8922be296527aa9fe4e12f46bded97941ae76f5be7f
6
+ metadata.gz: 30cdfffe72726c2ae90796f052cd330cf31dc4d336c5d57e59bf38ef57f5e22375faaf81704180c5f3d5399b54a899713d8575a29771aeeb754a65602baac75f
7
+ data.tar.gz: ae790c26a696b6331ae9e19f5c0000c2a572888d6a3f29931153b98ac6e844b32b2b0c281739c749a9546b16264df4cae680ed759e84e7dbbb4e1bfb03412b5c
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
+ *.orig
1
2
  .DS_Store
2
3
  pkg
3
4
  .idea/
4
5
  .yardoc/
6
+ *.gem
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
- ## 1.0.0
1
+ ## 0.0.2
2
+ - Fix check for inexistent report file
3
+ - Fix markdown message being printed without any issues reported
4
+
5
+ ## 0.0.1
2
6
  - Initial version
@@ -1,3 +1,3 @@
1
1
  module AndroidLint
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
@@ -57,16 +57,18 @@ module Danger
57
57
  return
58
58
  end
59
59
 
60
+ system "./gradlew #{gradle_task || 'lint'}"
61
+
60
62
  unless File.exists?(REPORT_FILE)
61
63
  fail("Lint report not found at `#{REPORT_FILE}`. "\
62
64
  "Have you forgot to add `xmlReport true` to your `build.gradle` file?")
63
65
  end
64
66
 
65
- system "./gradlew #{gradle_task || 'lint'}"
66
-
67
67
  issues = read_issues_from_report
68
- message = message_for_issues(issues)
69
- markdown(message) unless issues.empty?
68
+ filtered_issues = filter_issues_by_severity(issues)
69
+
70
+ message = message_for_issues(filtered_issues)
71
+ markdown(message) unless filtered_issues.empty?
70
72
  end
71
73
 
72
74
  # A getter for `severity`, returning "Warning" if value is nil.
@@ -77,7 +79,7 @@ module Danger
77
79
 
78
80
  private
79
81
 
80
- def read_issues_from_report()
82
+ def read_issues_from_report
81
83
  file = File.open("app/build/reports/lint/lint-result.xml")
82
84
 
83
85
  require 'oga'
@@ -86,12 +88,20 @@ module Danger
86
88
  report.xpath('//issue')
87
89
  end
88
90
 
91
+ def filter_issues_by_severity(issues)
92
+ issues.select do |issue|
93
+ severity_index(issue.get("severity")) >= severity_index(severity)
94
+ end
95
+ end
96
+
97
+ def severity_index(severity)
98
+ SEVERITY_LEVELS.index(severity) || 0
99
+ end
100
+
89
101
  def message_for_issues(issues)
90
102
  message = "### AndroidLint found issues\n\n"
91
103
 
92
- severity_index = SEVERITY_LEVELS.index(severity) || 0
93
- levels = SEVERITY_LEVELS.slice(severity_index, SEVERITY_LEVELS.size)
94
- levels.reverse.each do |level|
104
+ SEVERITY_LEVELS.reverse.each do |level|
95
105
  filtered = issues.select{|issue| issue.get("severity") == level}
96
106
  message << parse_results(filtered, level) unless filtered.empty?
97
107
  end
@@ -32,7 +32,7 @@ module Danger
32
32
  allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
33
33
  allow(File).to receive(:exists?).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(true)
34
34
 
35
- fake_result = File.open("spec/fixtures/lint-result.xml")
35
+ fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
36
36
  allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
37
37
 
38
38
  @android_lint.lint
@@ -43,7 +43,7 @@ module Danger
43
43
  allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
44
44
  allow(File).to receive(:exists?).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(false)
45
45
 
46
- fake_result = File.open("spec/fixtures/lint-result.xml")
46
+ fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
47
47
  allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
48
48
 
49
49
  @android_lint.lint
@@ -56,12 +56,12 @@ module Danger
56
56
  before do
57
57
  allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
58
58
  allow(File).to receive(:exists?).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(false)
59
-
60
- fake_result = File.open("spec/fixtures/lint-result.xml")
61
- allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
62
59
  end
63
60
 
64
61
  it 'Prints markdown if issues were found' do
62
+ fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
63
+ allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
64
+
65
65
  @android_lint.lint
66
66
 
67
67
  markdown = @android_lint.status_report[:markdowns].first.message
@@ -77,6 +77,27 @@ module Danger
77
77
  expect(markdown).to include("`Events.java` | 24 | Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
78
78
  end
79
79
 
80
+ it 'Doesn`t print anything if no errors were found' do
81
+ fake_result = File.open("spec/fixtures/lint-result-empty.xml")
82
+ allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
83
+
84
+ @android_lint.lint
85
+
86
+ markdown = @android_lint.status_report[:markdowns].first
87
+ expect(markdown).to be_nil
88
+ end
89
+
90
+ it 'Doesn`t print anything if no errors were found' do
91
+ fake_result = File.open("spec/fixtures/lint-result-without-fatal.xml")
92
+ allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
93
+
94
+ @android_lint.severity = "Fatal"
95
+ @android_lint.lint
96
+
97
+ markdown = @android_lint.status_report[:markdowns].first
98
+ expect(markdown).to be_nil
99
+ end
100
+
80
101
  end
81
102
 
82
103
  end
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <issues format="4" by="lint 25.2.2">
3
+
4
+ </issues>
@@ -0,0 +1,64 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <issues format="4" by="lint 25.2.2">
3
+
4
+ <issue
5
+ id="DefaultLocale"
6
+ severity="Error"
7
+ message="Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead"
8
+ category="Correctness"
9
+ priority="6"
10
+ summary="Implied default locale in case conversion"
11
+ explanation="Calling `String#toLowerCase()` or `#toUpperCase()` *without specifying an explicit locale* is a common source of bugs. The reason for that is that those methods will use the current locale on the user&apos;s device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for `i` is *not* `I`.
12
+
13
+ If you want the methods to just perform ASCII replacement, for example to convert an enum name, call `String#toUpperCase(Locale.US)` instead. If you really want to use the current locale, call `String#toUpperCase(Locale.getDefault())` instead."
14
+ url="http://developer.android.com/reference/java/util/Locale.html#default_locale"
15
+ urls="http://developer.android.com/reference/java/util/Locale.html#default_locale"
16
+ errorLine1=" return word.substring(0, 1).toUpperCase();"
17
+ errorLine2=" ~~~~~~~~~~~">
18
+ <location
19
+ file="/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/common/views/AvatarView.java"
20
+ line="60"
21
+ column="37"/>
22
+ </issue>
23
+
24
+ <issue
25
+ id="DefaultLocale"
26
+ severity="Error"
27
+ message="Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead"
28
+ category="Correctness"
29
+ priority="6"
30
+ summary="Implied default locale in case conversion"
31
+ explanation="Calling `String#toLowerCase()` or `#toUpperCase()` *without specifying an explicit locale* is a common source of bugs. The reason for that is that those methods will use the current locale on the user&apos;s device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for `i` is *not* `I`.
32
+
33
+ If you want the methods to just perform ASCII replacement, for example to convert an enum name, call `String#toUpperCase(Locale.US)` instead. If you really want to use the current locale, call `String#toUpperCase(Locale.getDefault())` instead."
34
+ url="http://developer.android.com/reference/java/util/Locale.html#default_locale"
35
+ urls="http://developer.android.com/reference/java/util/Locale.html#default_locale"
36
+ errorLine1=" return String.format(&quot;Tracking / Close to Delivery #%d Location&quot;, stopIndex);"
37
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
38
+ <location
39
+ file="/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/analytics/Events.java"
40
+ line="21"
41
+ column="16"/>
42
+ </issue>
43
+
44
+ <issue
45
+ id="DefaultLocale"
46
+ severity="Warning"
47
+ message="Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead"
48
+ category="Correctness"
49
+ priority="6"
50
+ summary="Implied default locale in case conversion"
51
+ explanation="Calling `String#toLowerCase()` or `#toUpperCase()` *without specifying an explicit locale* is a common source of bugs. The reason for that is that those methods will use the current locale on the user&apos;s device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for `i` is *not* `I`.
52
+
53
+ If you want the methods to just perform ASCII replacement, for example to convert an enum name, call `String#toUpperCase(Locale.US)` instead. If you really want to use the current locale, call `String#toUpperCase(Locale.getDefault())` instead."
54
+ url="http://developer.android.com/reference/java/util/Locale.html#default_locale"
55
+ urls="http://developer.android.com/reference/java/util/Locale.html#default_locale"
56
+ errorLine1=" return String.format(&quot;Tracking / At Delivery #%d Location&quot;, stopIndex);"
57
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
58
+ <location
59
+ file="/Users/gustavo/Developer/app-android/app/src/main/java/com/loadsmart/analytics/Events.java"
60
+ line="24"
61
+ column="16"/>
62
+ </issue>
63
+
64
+ </issues>
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Barbosa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-12 00:00:00.000000000 Z
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga
@@ -185,7 +185,9 @@ files:
185
185
  - lib/danger_android_lint.rb
186
186
  - lib/danger_plugin.rb
187
187
  - spec/android_lint_spec.rb
188
- - spec/fixtures/lint-result.xml
188
+ - spec/fixtures/lint-result-empty.xml
189
+ - spec/fixtures/lint-result-with-everything.xml
190
+ - spec/fixtures/lint-result-without-fatal.xml
189
191
  - spec/spec_helper.rb
190
192
  homepage: https://github.com/loadsmart/danger-android_lint
191
193
  licenses:
@@ -214,6 +216,8 @@ summary: Lint files of a gradle based Android project. This is done using the An
214
216
  Lint tool. Results are passed out as tables in markdown.
215
217
  test_files:
216
218
  - spec/android_lint_spec.rb
217
- - spec/fixtures/lint-result.xml
219
+ - spec/fixtures/lint-result-empty.xml
220
+ - spec/fixtures/lint-result-with-everything.xml
221
+ - spec/fixtures/lint-result-without-fatal.xml
218
222
  - spec/spec_helper.rb
219
223
  has_rdoc: