danger-android_lint 0.0.7 → 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
- SHA1:
3
- metadata.gz: a23cf2639550cda7bae6d9c49eec3f24564da9ef
4
- data.tar.gz: 8aae8686cd7d2ab3c1bc344716cdbe67c9bcf2bb
5
2
  SHA512:
6
- metadata.gz: bff880a4f7ec5dcc46337d794bbf4439878984d51d477c0d55253a8fa61c63538e6a84d43fcfcbc4e976cbec79e71a232615131d2476dbe04b7f4500289cd127
7
- data.tar.gz: 83aadd5d46813762ad94ca152757c1a4156989c780d48622f6f23fc163671ff0abd6c477d43fe72e1fe723042d865c0bec8bf5b26d50d1e6cb8222194fc09fdf
3
+ metadata.gz: ee6bc1e76ca2a7d11670cf1d0d50438a05aa62e93c6d81b289b48e4b2c2709181a234d6f6664439dc1aa531e5b1467722aa71752934662495cf992188227381c
4
+ data.tar.gz: 0f0e99183aea7bbbda95cddeb56c29d9f939d948f627e8da60b2bf2711dd0d8a794d7349c534cf9c5fa3d6e940abbc7c1ef38e6c599792f4ee8ee5b2689b2643
@@ -0,0 +1,13 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@1.0
4
+
5
+ jobs:
6
+ build:
7
+ docker:
8
+ - image: circleci/ruby:2.7
9
+ steps:
10
+ - checkout
11
+ - run: gem install bundler:2.2.10
12
+ - run: bundle install
13
+ - run: bundle exec rake spec
data/.github/CODEOWNERS CHANGED
@@ -1 +1 @@
1
- * @loadsmart/mobile
1
+ * @barbosa
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
5
+ # 0.0.9
6
+ - Add `filtering_lines` parameter, to show lint issues only on modified lines ([@ShivamPokhriyal](https://github.com/ShivamPokhriyal))
7
+
8
+ # 0.0.8
9
+ - Fix security issues ([@barbosa](https://github.com/barbosa))
10
+ - Expose report message ([@adamstrange])(https://github.com/adamstrange))
11
+ - Skip gradle task ([@mathroule])(https://github.com/mathroule))
12
+
1
13
  # 0.0.7
2
- - Bump ffi version due to security reasons ([@barbosa](https://github.com/barbosa))
14
+ - Fix security issues ([@barbosa](https://github.com/barbosa))
3
15
 
4
16
  # 0.0.6
5
17
  - Bump yarn and rubocop versions due to security issues ([@barbosa](https://github.com/barbosa))
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in danger-android_lint.gemspec
4
4
  gemspec
5
- gem "ffi", ">= 1.9.24"
data/Gemfile.lock CHANGED
@@ -1,50 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-android_lint (0.0.6)
4
+ danger-android_lint (0.0.9)
5
5
  danger-plugin-api (~> 1.0)
6
6
  oga
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.5.2)
12
- public_suffix (>= 2.0.2, < 4.0)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
13
  ansi (1.5.0)
14
- ast (2.4.0)
15
- claide (1.0.2)
14
+ ast (2.4.2)
15
+ claide (1.0.3)
16
16
  claide-plugins (0.9.2)
17
17
  cork
18
18
  nap
19
19
  open4 (~> 1.3)
20
- coderay (1.1.2)
20
+ coderay (1.1.3)
21
21
  colored2 (3.1.2)
22
22
  cork (0.3.0)
23
23
  colored2 (~> 3.1)
24
- danger (6.0.3)
24
+ danger (8.2.3)
25
25
  claide (~> 1.0)
26
26
  claide-plugins (>= 0.9.2)
27
27
  colored2 (~> 3.1)
28
28
  cork (~> 0.1)
29
- faraday (~> 0.9)
30
- faraday-http-cache (~> 1.0)
31
- git (~> 1.5)
32
- kramdown (~> 2.0)
29
+ faraday (>= 0.9.0, < 2.0)
30
+ faraday-http-cache (~> 2.0)
31
+ git (~> 1.7)
32
+ kramdown (~> 2.3)
33
33
  kramdown-parser-gfm (~> 1.0)
34
34
  no_proxy_fix
35
35
  octokit (~> 4.7)
36
- terminal-table (~> 1)
36
+ terminal-table (>= 1, < 4)
37
37
  danger-plugin-api (1.0.0)
38
38
  danger (> 2.0)
39
- diff-lcs (1.3)
40
- faraday (0.15.4)
39
+ diff-lcs (1.4.4)
40
+ faraday (1.4.2)
41
+ faraday-em_http (~> 1.0)
42
+ faraday-em_synchrony (~> 1.0)
43
+ faraday-excon (~> 1.1)
44
+ faraday-net_http (~> 1.0)
45
+ faraday-net_http_persistent (~> 1.1)
41
46
  multipart-post (>= 1.2, < 3)
42
- faraday-http-cache (1.3.1)
43
- faraday (~> 0.8)
44
- ffi (1.10.0)
45
- formatador (0.2.5)
46
- git (1.5.0)
47
- guard (2.15.0)
47
+ ruby2_keywords (>= 0.0.4)
48
+ faraday-em_http (1.0.0)
49
+ faraday-em_synchrony (1.0.0)
50
+ faraday-excon (1.1.0)
51
+ faraday-http-cache (2.2.0)
52
+ faraday (>= 0.8)
53
+ faraday-net_http (1.0.1)
54
+ faraday-net_http_persistent (1.1.0)
55
+ ffi (1.15.3)
56
+ formatador (0.3.0)
57
+ git (1.8.1)
58
+ rchardet (~> 1.8)
59
+ guard (2.17.0)
48
60
  formatador (>= 0.2.4)
49
61
  listen (>= 2.7, < 4.0)
50
62
  lumberjack (>= 1.0.12, < 2.0)
@@ -58,54 +70,58 @@ GEM
58
70
  guard (~> 2.1)
59
71
  guard-compat (~> 1.1)
60
72
  rspec (>= 2.99.0, < 4.0)
61
- kramdown (2.1.0)
62
- kramdown-parser-gfm (1.0.1)
73
+ kramdown (2.3.1)
74
+ rexml
75
+ kramdown-parser-gfm (1.1.0)
63
76
  kramdown (~> 2.0)
64
77
  listen (3.0.7)
65
78
  rb-fsevent (>= 0.9.3)
66
79
  rb-inotify (>= 0.9.7)
67
- lumberjack (1.0.13)
68
- method_source (0.9.2)
69
- multipart-post (2.0.0)
80
+ lumberjack (1.2.8)
81
+ method_source (1.0.0)
82
+ multipart-post (2.1.1)
70
83
  nap (1.1.0)
71
84
  nenv (0.3.0)
72
85
  no_proxy_fix (0.1.2)
73
- notiffany (0.1.1)
86
+ notiffany (0.1.3)
74
87
  nenv (~> 0.1)
75
88
  shellany (~> 0.0)
76
- octokit (4.14.0)
89
+ octokit (4.21.0)
90
+ faraday (>= 0.9)
77
91
  sawyer (~> 0.8.0, >= 0.5.3)
78
- oga (2.15)
92
+ oga (3.3)
79
93
  ast
80
94
  ruby-ll (~> 2.1)
81
95
  open4 (1.3.4)
82
- parallel (1.17.0)
83
- parser (2.6.2.1)
84
- ast (~> 2.4.0)
85
- powerpack (0.1.2)
86
- pry (0.12.2)
87
- coderay (~> 1.1.0)
88
- method_source (~> 0.9.0)
89
- public_suffix (3.0.3)
96
+ parallel (1.20.1)
97
+ parser (2.7.2.0)
98
+ ast (~> 2.4.1)
99
+ powerpack (0.1.3)
100
+ pry (0.14.1)
101
+ coderay (~> 1.1)
102
+ method_source (~> 1.0)
103
+ public_suffix (4.0.6)
90
104
  rainbow (2.2.2)
91
105
  rake
92
- rake (10.5.0)
93
- rb-fsevent (0.10.3)
94
- rb-inotify (0.10.0)
106
+ rake (13.0.3)
107
+ rb-fsevent (0.11.0)
108
+ rb-inotify (0.10.1)
95
109
  ffi (~> 1.0)
96
- rspec (3.8.0)
97
- rspec-core (~> 3.8.0)
98
- rspec-expectations (~> 3.8.0)
99
- rspec-mocks (~> 3.8.0)
100
- rspec-core (3.8.0)
101
- rspec-support (~> 3.8.0)
102
- rspec-expectations (3.8.2)
110
+ rchardet (1.8.0)
111
+ rexml (3.2.5)
112
+ rspec (3.10.0)
113
+ rspec-core (~> 3.10.0)
114
+ rspec-expectations (~> 3.10.0)
115
+ rspec-mocks (~> 3.10.0)
116
+ rspec-core (3.10.1)
117
+ rspec-support (~> 3.10.0)
118
+ rspec-expectations (3.10.1)
103
119
  diff-lcs (>= 1.2.0, < 2.0)
104
- rspec-support (~> 3.8.0)
105
- rspec-mocks (3.8.0)
120
+ rspec-support (~> 3.10.0)
121
+ rspec-mocks (3.10.2)
106
122
  diff-lcs (>= 1.2.0, < 2.0)
107
- rspec-support (~> 3.8.0)
108
- rspec-support (3.8.0)
123
+ rspec-support (~> 3.10.0)
124
+ rspec-support (3.10.2)
109
125
  rubocop (0.49.1)
110
126
  parallel (~> 1.10)
111
127
  parser (>= 2.3.3.1, < 3.0)
@@ -116,32 +132,33 @@ GEM
116
132
  ruby-ll (2.1.2)
117
133
  ansi
118
134
  ast
119
- ruby-progressbar (1.10.0)
120
- sawyer (0.8.1)
121
- addressable (>= 2.3.5, < 2.6)
122
- faraday (~> 0.8, < 1.0)
135
+ ruby-progressbar (1.11.0)
136
+ ruby2_keywords (0.0.4)
137
+ sawyer (0.8.2)
138
+ addressable (>= 2.3.5)
139
+ faraday (> 0.8, < 2.0)
123
140
  shellany (0.0.1)
124
- terminal-table (1.8.0)
125
- unicode-display_width (~> 1.1, >= 1.1.1)
126
- thor (0.20.3)
127
- unicode-display_width (1.5.0)
128
- yard (0.9.19)
141
+ terminal-table (3.0.1)
142
+ unicode-display_width (>= 1.1.1, < 3)
143
+ thor (1.1.0)
144
+ unicode-display_width (1.7.0)
145
+ yard (0.9.26)
129
146
 
130
147
  PLATFORMS
131
- ruby
148
+ universal-darwin-20
149
+ x86_64-linux
132
150
 
133
151
  DEPENDENCIES
134
- bundler (~> 2.0)
152
+ bundler (>= 2.2.10)
135
153
  danger-android_lint!
136
- ffi (>= 1.9.24)
137
154
  guard (~> 2.14)
138
155
  guard-rspec (~> 4.7)
139
156
  listen (= 3.0.7)
140
157
  pry
141
- rake (~> 10.0)
158
+ rake (~> 13.0)
142
159
  rspec (~> 3.4)
143
160
  rubocop (~> 0.49.0)
144
161
  yard (~> 0.9.11)
145
162
 
146
163
  BUNDLED WITH
147
- 2.0.1
164
+ 2.2.10
data/README.md CHANGED
@@ -49,7 +49,9 @@ android_lint.gradle_task = "lintMyFlavorDebug"
49
49
  android_lint.lint
50
50
  ```
51
51
 
52
- If you want to skip gradle task, setting the `skip_gradle_task` parameter to `true`.
52
+ #### Skip gradle task execution
53
+
54
+ If you want to skip the gradle task execution. You can achieve that by simply changing the value of `skip_gradle_task`. Default is `false`.
53
55
 
54
56
  ```rb
55
57
  android_lint.skip_gradle_task = true
@@ -83,6 +85,13 @@ android_lint.filtering = true
83
85
  android_lint.lint
84
86
  ```
85
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
+
86
95
  #### Make Danger comment directly on the line instead of printing a Markdown table (GitHub only)
87
96
 
88
97
  ```rb
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ task default: :specs
8
8
 
9
9
  task :spec do
10
10
  Rake::Task['specs'].invoke
11
- Rake::Task['rubocop'].invoke
11
+ # Rake::Task['rubocop'].invoke
12
12
  Rake::Task['spec_docs'].invoke
13
13
  end
14
14
 
data/atlantis.yaml ADDED
@@ -0,0 +1,5 @@
1
+ version: 3
2
+ projects:
3
+ - dir: .
4
+ autoplan:
5
+ enabled: false
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
24
24
 
25
25
  # General ruby development
26
- spec.add_development_dependency 'bundler', '~> 2.0'
27
- spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'bundler', '>= 2.2.10'
27
+ spec.add_development_dependency 'rake', '~> 13.0'
28
28
 
29
29
  # Testing support
30
30
  spec.add_development_dependency 'rspec', '~> 3.4'
@@ -1,3 +1,3 @@
1
1
  module AndroidLint
2
- VERSION = "0.0.7".freeze
2
+ VERSION = "0.0.10".freeze
3
3
  end
@@ -13,6 +13,11 @@ module Danger
13
13
  # android_lint.gradle_task = "lintMyFlavorDebug"
14
14
  # android_lint.lint
15
15
  #
16
+ # @example Running AndroidLint without running a Gradle task
17
+ #
18
+ # android_lint.skip_gradle_task = true
19
+ # android_lint.lint
20
+ #
16
21
  # @example Running AndroidLint for a specific severity level and up
17
22
  #
18
23
  # # options are ["Warning", "Error", "Fatal"]
@@ -31,6 +36,7 @@ module Danger
31
36
  # Defaults to "app/build/reports/lint/lint-result.xml".
32
37
  # @return [String]
33
38
  attr_accessor :report_file
39
+
34
40
  # A getter for `report_file`.
35
41
  # @return [String]
36
42
  def report_file
@@ -43,6 +49,24 @@ module Danger
43
49
  # @return [String]
44
50
  attr_accessor :gradle_task
45
51
 
52
+ # A getter for `gradle_task`, returning "lint" if value is nil.
53
+ # @return [String]
54
+ def gradle_task
55
+ @gradle_task ||= "lint"
56
+ end
57
+
58
+ # Skip Gradle task.
59
+ # This is useful when Gradle task has been already executed.
60
+ # Defaults to `false`.
61
+ # @return [Bool]
62
+ attr_writer :skip_gradle_task
63
+
64
+ # A getter for `skip_gradle_task`, returning `false` if value is nil.
65
+ # @return [Boolean]
66
+ def skip_gradle_task
67
+ @skip_gradle_task ||= false
68
+ end
69
+
46
70
  # Defines the severity level of the execution.
47
71
  # Selected levels are the chosen one and up.
48
72
  # Possible values are "Warning", "Error" or "Fatal".
@@ -50,12 +74,18 @@ module Danger
50
74
  # @return [String]
51
75
  attr_writer :severity
52
76
 
77
+ # A getter for `severity`, returning "Warning" if value is nil.
78
+ # @return [String]
79
+ def severity
80
+ @severity || SEVERITY_LEVELS.first
81
+ end
82
+
53
83
  # Enable filtering
54
84
  # Only show messages within changed files.
55
85
  attr_accessor :filtering
56
86
 
57
- # Skip gradle task
58
- attr_accessor :skip_gradle_task
87
+ # Only shows messages for the modified lines.
88
+ attr_accessor :filtering_lines
59
89
 
60
90
  # Calls lint task of your gradle project.
61
91
  # It fails if `gradlew` cannot be found inside current directory.
@@ -64,9 +94,8 @@ module Danger
64
94
  # @return [void]
65
95
  #
66
96
  def lint(inline_mode: false)
67
- if !skip_gradle_task && !gradlew_exists?
68
- fail("Could not find `gradlew` inside current directory")
69
- return
97
+ unless skip_gradle_task
98
+ return fail("Could not find `gradlew` inside current directory") unless gradlew_exists?
70
99
  end
71
100
 
72
101
  unless SEVERITY_LEVELS.include?(severity)
@@ -74,7 +103,9 @@ module Danger
74
103
  return
75
104
  end
76
105
 
77
- system "./gradlew #{gradle_task || 'lint'}" unless skip_gradle_task
106
+ unless skip_gradle_task
107
+ system "./gradlew #{gradle_task}"
108
+ end
78
109
 
79
110
  unless File.exists?(report_file)
80
111
  fail("Lint report not found at `#{report_file}`. "\
@@ -84,6 +115,8 @@ module Danger
84
115
  issues = read_issues_from_report
85
116
  filtered_issues = filter_issues_by_severity(issues)
86
117
 
118
+ message = ""
119
+
87
120
  if inline_mode
88
121
  # Report with inline comment
89
122
  send_inline_comment(filtered_issues)
@@ -91,12 +124,8 @@ module Danger
91
124
  message = message_for_issues(filtered_issues)
92
125
  markdown("### AndroidLint found issues\n\n" + message) unless message.to_s.empty?
93
126
  end
94
- end
95
127
 
96
- # A getter for `severity`, returning "Warning" if value is nil.
97
- # @return [String]
98
- def severity
99
- @severity || SEVERITY_LEVELS.first
128
+ message
100
129
  end
101
130
 
102
131
  private
@@ -140,9 +169,13 @@ module Danger
140
169
  results.each do |r|
141
170
  location = r.xpath('location').first
142
171
  filename = location.get('file').gsub(dir, "")
143
- next unless !filtering || (target_files.include? filename)
144
- 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'
145
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
146
179
  count = count + 1
147
180
  message << "`#{filename}` | #{line} | #{reason} \n"
148
181
  end
@@ -160,7 +193,7 @@ module Danger
160
193
  # Send inline comment with danger's warn or fail method
161
194
  #
162
195
  # @return [void]
163
- def send_inline_comment (issues)
196
+ def send_inline_comment(issues)
164
197
  target_files = (git.modified_files - git.deleted_files) + git.added_files
165
198
  dir = "#{Dir.pwd}/"
166
199
  SEVERITY_LEVELS.reverse.each do |level|
@@ -169,13 +202,42 @@ module Danger
169
202
  filtered.each do |r|
170
203
  location = r.xpath('location').first
171
204
  filename = location.get('file').gsub(dir, "")
172
- next unless !filtering || (target_files.include? filename)
205
+ next unless (!filtering && !filtering_lines) || (target_files.include? filename)
173
206
  line = (location.get('line') || "0").to_i
207
+ if filtering_lines
208
+ added_lines = parse_added_line_numbers(git.diff[filename].patch)
209
+ next unless added_lines.include? line
210
+ end
174
211
  send(level === "Warning" ? "warn" : "fail", r.get('message'), file: filename, line: line)
175
212
  end
176
213
  end
177
214
  end
178
215
 
216
+ # Parses git diff of a file and retuns an array of added line numbers.
217
+ def parse_added_line_numbers(diff)
218
+ current_line_number = nil
219
+ added_line_numbers = []
220
+ diff_lines = diff.strip.split("\n")
221
+ diff_lines.each_with_index do |line, index|
222
+ if m = /\+(\d+)(?:,\d+)? @@/.match(line)
223
+ # (e.g. @@ -32,10 +32,7 @@)
224
+ current_line_number = Integer(m[1])
225
+ else
226
+ if !current_line_number.nil?
227
+ if line.start_with?('+')
228
+ # added line
229
+ added_line_numbers.push current_line_number
230
+ current_line_number += 1
231
+ elsif !line.start_with?('-')
232
+ # unmodified line
233
+ current_line_number += 1
234
+ end
235
+ end
236
+ end
237
+ end
238
+ added_line_numbers
239
+ end
240
+
179
241
  def gradlew_exists?
180
242
  `ls gradlew`.strip.empty? == false
181
243
  end
@@ -25,6 +25,26 @@ module Danger
25
25
  expect(@android_lint.status_report[:errors]).to eq(["Could not find `gradlew` inside current directory"])
26
26
  end
27
27
 
28
+ it "Set custom Gradle task" do
29
+ custom_task = "lintRelease"
30
+ @android_lint.gradle_task = custom_task
31
+ expect(@android_lint.gradle_task).to eq(custom_task)
32
+ end
33
+
34
+ it "Check default Gradle task" do
35
+ expect(@android_lint.gradle_task).to eq("lint")
36
+ end
37
+
38
+ it "Skip Gradle task" do
39
+ skip_gradle_task = true
40
+ @android_lint.skip_gradle_task = skip_gradle_task
41
+ expect(@android_lint.skip_gradle_task).to eq(skip_gradle_task)
42
+ end
43
+
44
+ it "Check default skip Gradle task" do
45
+ expect(@android_lint.skip_gradle_task).to eq(false)
46
+ end
47
+
28
48
  it "Fails if severity is an unknown value" do
29
49
  allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
30
50
  allow(File).to receive(:exists?).with(@android_lint.report_file()).and_return(true)
@@ -49,7 +69,7 @@ module Danger
49
69
  it "Sets the report file to a default location if no param is provided" do
50
70
  allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
51
71
  allow(File).to receive(:exists?).with(@android_lint.report_file).and_return(true)
52
-
72
+
53
73
  fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
54
74
  allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
55
75
 
@@ -65,7 +85,7 @@ module Danger
65
85
  fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
66
86
  allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
67
87
  allow(File).to receive(:exists?).with(@android_lint.report_file).and_return(true)
68
-
88
+
69
89
  @android_lint.lint
70
90
 
71
91
  expect(@android_lint.report_file).to eq('some/other/location/lint-result.xml')
@@ -91,6 +111,19 @@ module Danger
91
111
  end
92
112
 
93
113
  it 'Prints markdown if issues were found' do
114
+ fake_result = File.open("spec/fixtures/lint-result-with-special-chars.xml")
115
+ allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
116
+
117
+ @android_lint.lint
118
+
119
+ markdown = @android_lint.status_report[:markdowns].first.message
120
+ expect(markdown).to include("AndroidLint found issues")
121
+
122
+ expect(markdown).to include("Warning (1)")
123
+ expect(markdown).to include("`app/src/main/res/values/strings.xml` | 105 | The resource `R.string.authentication_invalid_auth_token_type` appears to be unused")
124
+ end
125
+
126
+ it 'Prints markdown if issues were found even if there is a special char' do
94
127
  fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
95
128
  allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
96
129
 
@@ -101,12 +134,6 @@ module Danger
101
134
 
102
135
  expect(markdown).to include("Fatal (1)")
103
136
  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")
104
-
105
- expect(markdown).to include("Error (1)")
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")
107
-
108
- expect(markdown).to include("Warning (1)")
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")
110
137
  end
111
138
 
112
139
  it 'Doesn`t print anything if no errors were found' do
@@ -161,8 +188,79 @@ module Danger
161
188
  expect(warn).not_to include("Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
162
189
  end
163
190
 
191
+ describe "for a modified file" do
192
+ before do
193
+ allow(Dir).to receive(:pwd).and_return("/Users/shivampokhriyal/Documents/projects/Commcare/commcare-android")
194
+
195
+ allow(@android_lint.git).to receive(:modified_files).and_return([
196
+ "app/build.gradle",
197
+ ])
198
+
199
+ fake_patch = File.read("spec/fixtures/pr-diff.diff")
200
+ diff = [OpenStruct.new(type: "modified", path: "app/build.gradle")]
201
+ allow(@android_lint.git).to receive(:diff).and_return(diff)
202
+ diff_for_file = OpenStruct.new(insertions: 3)
203
+ allow(diff).to receive(:[]).with("app/build.gradle").and_return(diff_for_file)
204
+ allow(diff_for_file).to receive(:patch).and_return(fake_patch)
205
+
206
+ fake_result = File.open("spec/fixtures/lint-result-for-pr.xml")
207
+ allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
208
+ end
209
+
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
214
+
215
+ error = @android_lint.status_report[:errors]
216
+ expect(error).to include("fake message three")
217
+
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
234
+ end
235
+
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
253
+
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")
258
+
259
+ expect(message).not_to include("fake message in unmodified file")
260
+ end
261
+ end
262
+ end
164
263
  end
165
-
166
264
  end
167
265
  end
168
266
  end
@@ -0,0 +1,62 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <issues format="5" by="lint 4.0.0">
3
+ <issue
4
+ id="DuplicatePlatformClasses"
5
+ severity="Error"
6
+ message="fake message one"
7
+ category="Correctness"
8
+ priority="8"
9
+ summary="Duplicate Platform Classes"
10
+ explanation="There are a number of libraries that duplicate not just functionality of the Android platform but using the exact same class names as the ones provided in Android -- for example the apache http classes. This can lead to unexpected crashes.&#xA;&#xA;To solve this, you need to either find a newer version of the library which no longer has this problem, or to repackage the library (and all of its dependencies) using something like the `jarjar` tool, or finally, rewriting the code to use different APIs (for example, for http code, consider using `HttpUrlConnection` or a library like `okhttp`).">
11
+ <location
12
+ file="/Users/shivampokhriyal/Documents/projects/Commcare/commcare-android/app/build.gradle"/>
13
+ </issue>
14
+
15
+ <issue
16
+ id="DuplicatePlatformClasses"
17
+ severity="Error"
18
+ message="fake message two"
19
+ category="Correctness"
20
+ priority="8"
21
+ summary="Duplicate Platform Classes"
22
+ explanation="There are a number of libraries that duplicate not just functionality of the Android platform but using the exact same class names as the ones provided in Android -- for example the apache http classes. This can lead to unexpected crashes.&#xA;&#xA;To solve this, you need to either find a newer version of the library which no longer has this problem, or to repackage the library (and all of its dependencies) using something like the `jarjar` tool, or finally, rewriting the code to use different APIs (for example, for http code, consider using `HttpUrlConnection` or a library like `okhttp`)."
23
+ errorLine1=" testImplementation &apos;org.json:json:20140107&apos;"
24
+ errorLine2=" ~~~~~~~~~~~~~">
25
+ <location
26
+ file="/Users/shivampokhriyal/Documents/projects/Commcare/commcare-android/app/build.gradle"
27
+ line="52"
28
+ column="25"/>
29
+ </issue>
30
+
31
+ <issue
32
+ id="FakeId"
33
+ severity="Error"
34
+ message="fake message three"
35
+ category="Correctness"
36
+ priority="8"
37
+ summary="Fake summary"
38
+ explanation="Fake explanation."
39
+ errorLine1="// debugImplementation because LeakCanary should only run in debug builds."
40
+ errorLine2=" ~~~~~~~~~~~~~">
41
+ <location
42
+ file="/Users/shivampokhriyal/Documents/projects/Commcare/commcare-android/app/build.gradle"
43
+ line="36"
44
+ column="10"/>
45
+ </issue>
46
+
47
+ <issue
48
+ id="2"
49
+ severity="Error"
50
+ message="fake message in unmodified file"
51
+ category="Correctness"
52
+ priority="8"
53
+ summary="Fake summary"
54
+ explanation="Fake explanation."
55
+ errorLine1="// debugImplementation because LeakCanary should only run in debug builds."
56
+ errorLine2=" ~~~~~~~~~~~~~">
57
+ <location
58
+ file="/Users/shivampokhriyal/Documents/projects/Commcare/commcare-android/app/AndroidManifest.xml"
59
+ line="36"
60
+ column="10"/>
61
+ </issue>
62
+ </issues>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <issues format="4" by="lint 25.2.2">
3
+ <issue
4
+ id="UnusedResources"
5
+ severity="Warning"
6
+ message="The resource `R.string.authentication_invalid_auth_token_type` appears to be unused"
7
+ category="Performance"
8
+ priority="3"
9
+ summary="Unused resources"
10
+ explanation="Unused resources make applications larger and slow down builds."
11
+ errorLine1=" &lt;string name=&quot;authentication_invalid_auth_token_type&quot;>Autenticação inválida.&lt;/string>"
12
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
13
+ quickfix="studio">
14
+ <location
15
+ file="app/src/main/res/values/strings.xml"
16
+ line="105"
17
+ column="13"/>
18
+ </issue>
19
+ </issues>
@@ -0,0 +1,14 @@
1
+ diff --git a/app/build.gradle b/app/build.gradle
2
+ index 6dcc647b8..a1365bd75 100644
3
+ --- a/app/build.gradle
4
+ +++ b/app/build.gradle
5
+ @@ -33,6 +33,9 @@ configurations {
6
+ }
7
+
8
+ dependencies {
9
+ + // debugImplementation because LeakCanary should only run in debug builds.
10
+ + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
11
+ +
12
+ testImplementation 'junit:junit:4.12'
13
+ testImplementation('org.robolectric:robolectric:4.3.1') {
14
+ exclude(group: 'org.bouncycastle', module: 'bcprov-jdk15on')
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.7
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: 2019-04-09 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
@@ -42,30 +42,30 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: 2.2.10
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: 2.2.10
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -171,8 +171,10 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
+ - ".circleci/config.yml"
174
175
  - ".github/CODEOWNERS"
175
176
  - ".gitignore"
177
+ - ".ruby-version"
176
178
  - CHANGELOG.md
177
179
  - Gemfile
178
180
  - Gemfile.lock
@@ -180,6 +182,7 @@ files:
180
182
  - LICENSE.txt
181
183
  - README.md
182
184
  - Rakefile
185
+ - atlantis.yaml
183
186
  - danger-android_lint.gemspec
184
187
  - lib/android_lint/gem_version.rb
185
188
  - lib/android_lint/plugin.rb
@@ -187,14 +190,17 @@ files:
187
190
  - lib/danger_plugin.rb
188
191
  - spec/android_lint_spec.rb
189
192
  - spec/fixtures/lint-result-empty.xml
193
+ - spec/fixtures/lint-result-for-pr.xml
190
194
  - spec/fixtures/lint-result-with-everything.xml
195
+ - spec/fixtures/lint-result-with-special-chars.xml
191
196
  - spec/fixtures/lint-result-without-fatal.xml
197
+ - spec/fixtures/pr-diff.diff
192
198
  - spec/spec_helper.rb
193
199
  homepage: https://github.com/loadsmart/danger-android_lint
194
200
  licenses:
195
201
  - MIT
196
202
  metadata: {}
197
- post_install_message:
203
+ post_install_message:
198
204
  rdoc_options: []
199
205
  require_paths:
200
206
  - lib
@@ -209,15 +215,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
215
  - !ruby/object:Gem::Version
210
216
  version: '0'
211
217
  requirements: []
212
- rubyforge_project:
213
- rubygems_version: 2.5.2.3
214
- signing_key:
218
+ rubygems_version: 3.0.9
219
+ signing_key:
215
220
  specification_version: 4
216
221
  summary: Lint files of a gradle based Android project. This is done using the Android's
217
222
  Lint tool. Results are passed out as tables in markdown.
218
223
  test_files:
219
224
  - spec/android_lint_spec.rb
220
225
  - spec/fixtures/lint-result-empty.xml
226
+ - spec/fixtures/lint-result-for-pr.xml
221
227
  - spec/fixtures/lint-result-with-everything.xml
228
+ - spec/fixtures/lint-result-with-special-chars.xml
222
229
  - spec/fixtures/lint-result-without-fatal.xml
230
+ - spec/fixtures/pr-diff.diff
223
231
  - spec/spec_helper.rb