danger-android_lint 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +140 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +23 -0
- data/danger-android_lint.gemspec +51 -0
- data/lib/android_lint/gem_version.rb +3 -0
- data/lib/android_lint/plugin.rb +124 -0
- data/lib/danger_android_lint.rb +1 -0
- data/lib/danger_plugin.rb +1 -0
- data/spec/android_lint_spec.rb +84 -0
- data/spec/fixtures/lint-result.xml +64 -0
- data/spec/spec_helper.rb +59 -0
- metadata +219 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f282c21919c8285f09b44d4466a690e9d3208db8
|
4
|
+
data.tar.gz: ea242b17a6681032b7f611894ec0e548044eb24a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da1f099f47ecdd976e212c1469b2bcc628e8d9051fcf69fb2f8c7809e0f4f207fad13bb9075f4ce598c459ef4653fbf6c41d70296970d6519d3b0cd5d0a5b7bb
|
7
|
+
data.tar.gz: 854b76159b3d53544d08f0f34f2574ee8351a709979c85dd8e08fd127b70a85bb716655d594e7dbb5360c8922be296527aa9fe4e12f46bded97941ae76f5be7f
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
danger-android_lint (0.0.1)
|
5
|
+
danger-plugin-api (~> 1.0)
|
6
|
+
oga
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.0)
|
12
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
13
|
+
ansi (1.5.0)
|
14
|
+
ast (2.3.0)
|
15
|
+
claide (1.0.1)
|
16
|
+
claide-plugins (0.9.2)
|
17
|
+
cork
|
18
|
+
nap
|
19
|
+
open4 (~> 1.3)
|
20
|
+
coderay (1.1.1)
|
21
|
+
colored (1.2)
|
22
|
+
cork (0.2.0)
|
23
|
+
colored (~> 1.2)
|
24
|
+
danger (4.0.1)
|
25
|
+
claide (~> 1.0)
|
26
|
+
claide-plugins (>= 0.9.2)
|
27
|
+
colored (~> 1.2)
|
28
|
+
cork (~> 0.1)
|
29
|
+
faraday (~> 0.9)
|
30
|
+
faraday-http-cache (~> 1.0)
|
31
|
+
git (~> 1)
|
32
|
+
kramdown (~> 1.5)
|
33
|
+
octokit (~> 4.2)
|
34
|
+
terminal-table (~> 1)
|
35
|
+
danger-plugin-api (1.0.0)
|
36
|
+
danger (> 2.0)
|
37
|
+
diff-lcs (1.2.5)
|
38
|
+
faraday (0.10.0)
|
39
|
+
multipart-post (>= 1.2, < 3)
|
40
|
+
faraday-http-cache (1.3.1)
|
41
|
+
faraday (~> 0.8)
|
42
|
+
ffi (1.9.14)
|
43
|
+
formatador (0.2.5)
|
44
|
+
git (1.3.0)
|
45
|
+
guard (2.14.0)
|
46
|
+
formatador (>= 0.2.4)
|
47
|
+
listen (>= 2.7, < 4.0)
|
48
|
+
lumberjack (~> 1.0)
|
49
|
+
nenv (~> 0.1)
|
50
|
+
notiffany (~> 0.0)
|
51
|
+
pry (>= 0.9.12)
|
52
|
+
shellany (~> 0.0)
|
53
|
+
thor (>= 0.18.1)
|
54
|
+
guard-compat (1.2.1)
|
55
|
+
guard-rspec (4.7.3)
|
56
|
+
guard (~> 2.1)
|
57
|
+
guard-compat (~> 1.1)
|
58
|
+
rspec (>= 2.99.0, < 4.0)
|
59
|
+
kramdown (1.13.0)
|
60
|
+
listen (3.0.7)
|
61
|
+
rb-fsevent (>= 0.9.3)
|
62
|
+
rb-inotify (>= 0.9.7)
|
63
|
+
lumberjack (1.0.10)
|
64
|
+
method_source (0.8.2)
|
65
|
+
multipart-post (2.0.0)
|
66
|
+
nap (1.1.0)
|
67
|
+
nenv (0.3.0)
|
68
|
+
notiffany (0.1.1)
|
69
|
+
nenv (~> 0.1)
|
70
|
+
shellany (~> 0.0)
|
71
|
+
octokit (4.6.2)
|
72
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
73
|
+
oga (2.7)
|
74
|
+
ast
|
75
|
+
ruby-ll (~> 2.1)
|
76
|
+
open4 (1.3.4)
|
77
|
+
parser (2.3.1.4)
|
78
|
+
ast (~> 2.2)
|
79
|
+
powerpack (0.1.1)
|
80
|
+
pry (0.10.4)
|
81
|
+
coderay (~> 1.1.0)
|
82
|
+
method_source (~> 0.8.1)
|
83
|
+
slop (~> 3.4)
|
84
|
+
public_suffix (2.0.4)
|
85
|
+
rainbow (2.1.0)
|
86
|
+
rake (10.5.0)
|
87
|
+
rb-fsevent (0.9.8)
|
88
|
+
rb-inotify (0.9.7)
|
89
|
+
ffi (>= 0.5.0)
|
90
|
+
rspec (3.5.0)
|
91
|
+
rspec-core (~> 3.5.0)
|
92
|
+
rspec-expectations (~> 3.5.0)
|
93
|
+
rspec-mocks (~> 3.5.0)
|
94
|
+
rspec-core (3.5.4)
|
95
|
+
rspec-support (~> 3.5.0)
|
96
|
+
rspec-expectations (3.5.0)
|
97
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
98
|
+
rspec-support (~> 3.5.0)
|
99
|
+
rspec-mocks (3.5.0)
|
100
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
101
|
+
rspec-support (~> 3.5.0)
|
102
|
+
rspec-support (3.5.0)
|
103
|
+
rubocop (0.45.0)
|
104
|
+
parser (>= 2.3.1.1, < 3.0)
|
105
|
+
powerpack (~> 0.1)
|
106
|
+
rainbow (>= 1.99.1, < 3.0)
|
107
|
+
ruby-progressbar (~> 1.7)
|
108
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
109
|
+
ruby-ll (2.1.2)
|
110
|
+
ansi
|
111
|
+
ast
|
112
|
+
ruby-progressbar (1.8.1)
|
113
|
+
sawyer (0.8.1)
|
114
|
+
addressable (>= 2.3.5, < 2.6)
|
115
|
+
faraday (~> 0.8, < 1.0)
|
116
|
+
shellany (0.0.1)
|
117
|
+
slop (3.6.0)
|
118
|
+
terminal-table (1.7.3)
|
119
|
+
unicode-display_width (~> 1.1.1)
|
120
|
+
thor (0.19.1)
|
121
|
+
unicode-display_width (1.1.1)
|
122
|
+
yard (0.9.5)
|
123
|
+
|
124
|
+
PLATFORMS
|
125
|
+
ruby
|
126
|
+
|
127
|
+
DEPENDENCIES
|
128
|
+
bundler (~> 1.3)
|
129
|
+
danger-android_lint!
|
130
|
+
guard (~> 2.14)
|
131
|
+
guard-rspec (~> 4.7)
|
132
|
+
listen (= 3.0.7)
|
133
|
+
pry
|
134
|
+
rake (~> 10.0)
|
135
|
+
rspec (~> 3.4)
|
136
|
+
rubocop (~> 0.41)
|
137
|
+
yard (~> 0.8)
|
138
|
+
|
139
|
+
BUNDLED WITH
|
140
|
+
1.12.5
|
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# A guardfile for making Danger Plugins
|
2
|
+
# For more info see https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# To run, use `bundle exec guard`.
|
5
|
+
|
6
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
7
|
+
require 'guard/rspec/dsl'
|
8
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Loadsmart, Inc. <mobile@loadsmart.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/loadsmart/danger-android_lint.svg?style=svg)](https://circleci.com/gh/loadsmart/danger-android_lint)
|
2
|
+
|
3
|
+
# danger-android_lint
|
4
|
+
|
5
|
+
Lint files of a gradle based Android project.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
### Via global gems
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install danger-android_lint
|
13
|
+
```
|
14
|
+
|
15
|
+
### Via Bundler
|
16
|
+
|
17
|
+
Add the following line to your Gemfile and then run `bundle install`:
|
18
|
+
|
19
|
+
```rb
|
20
|
+
gem 'danger-android_lint'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Before all, you need to turn lint reports on in your `build.gradle` file. You can do this by adding the `xmlReport true` option, like:
|
26
|
+
|
27
|
+
```gradle
|
28
|
+
android {
|
29
|
+
lintOptions {
|
30
|
+
xmlReport true
|
31
|
+
}
|
32
|
+
}
|
33
|
+
```
|
34
|
+
|
35
|
+
### Basic
|
36
|
+
|
37
|
+
```rb
|
38
|
+
android_lint.lint
|
39
|
+
```
|
40
|
+
|
41
|
+
### Advanced
|
42
|
+
|
43
|
+
#### Using a custom gradle task
|
44
|
+
|
45
|
+
In case you have multiple flavors, you may want to change the gradle task that runs the lint command. You can achieve that by simply changing the value of `gradle_task`. Default is `lint`.
|
46
|
+
|
47
|
+
```rb
|
48
|
+
android_lint.gradle_task = "lintMyFlavorDebug"
|
49
|
+
android_lint.lint
|
50
|
+
```
|
51
|
+
|
52
|
+
#### Changing report's severity level
|
53
|
+
|
54
|
+
If you want to filter lint issues based on their severity level, you can do that by setting a value to `severity`. Bear in mind that you are filtering issues by the severity level you've set **and up**. Possible values are `Warning`, `Error` and `Fatal`. Default is `Warning` (which is everything).
|
55
|
+
|
56
|
+
```rb
|
57
|
+
android_lint.severity = "Error"
|
58
|
+
android_lint.lint
|
59
|
+
```
|
60
|
+
|
61
|
+
## Development
|
62
|
+
|
63
|
+
1. Clone this repo
|
64
|
+
2. Run `bundle install` to setup dependencies.
|
65
|
+
3. Run `bundle exec rake spec` to run the tests.
|
66
|
+
4. Use `bundle exec guard` to automatically have tests run as you make changes.
|
67
|
+
5. Make your changes.
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:specs)
|
6
|
+
|
7
|
+
task default: :specs
|
8
|
+
|
9
|
+
task :spec do
|
10
|
+
Rake::Task['specs'].invoke
|
11
|
+
Rake::Task['rubocop'].invoke
|
12
|
+
Rake::Task['spec_docs'].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run RuboCop on the lib/specs directory'
|
16
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
17
|
+
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Ensure that the plugin passes `danger plugins lint`'
|
21
|
+
task :spec_docs do
|
22
|
+
sh 'bundle exec danger plugins lint'
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'android_lint/gem_version.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'danger-android_lint'
|
8
|
+
spec.version = AndroidLint::VERSION
|
9
|
+
spec.authors = ['Gustavo Barbosa']
|
10
|
+
spec.email = ['gustavo@loadsmart.com']
|
11
|
+
spec.description = %q{A Danger plugin for Android Lint}
|
12
|
+
spec.summary = %q{Lint files of a gradle based Android project. This is done using the Android's Lint tool. Results are passed out as tables in markdown.}
|
13
|
+
spec.homepage = 'https://github.com/loadsmart/danger-android_lint'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'oga'
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
|
24
|
+
|
25
|
+
# General ruby development
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
|
29
|
+
# Testing support
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
|
+
|
32
|
+
# Linting code and docs
|
33
|
+
spec.add_development_dependency "rubocop", "~> 0.41"
|
34
|
+
spec.add_development_dependency "yard", "~> 0.8"
|
35
|
+
|
36
|
+
# Makes testing easy via `bundle exec guard`
|
37
|
+
spec.add_development_dependency 'guard', '~> 2.14'
|
38
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
39
|
+
|
40
|
+
# If you want to work on older builds of ruby
|
41
|
+
spec.add_development_dependency 'listen', '3.0.7'
|
42
|
+
|
43
|
+
# This gives you the chance to run a REPL inside your tests
|
44
|
+
# via:
|
45
|
+
#
|
46
|
+
# require 'pry'
|
47
|
+
# binding.pry
|
48
|
+
#
|
49
|
+
# This will stop test execution and let you inspect the results
|
50
|
+
spec.add_development_dependency 'pry'
|
51
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Danger
|
2
|
+
|
3
|
+
# Lint files of a gradle based Android project.
|
4
|
+
# This is done using the Android's [Lint](https://developer.android.com/studio/write/lint.html) tool.
|
5
|
+
# Results are passed out as tables in markdown.
|
6
|
+
#
|
7
|
+
# @example Running AndroidLint with its basic configuration
|
8
|
+
#
|
9
|
+
# android_lint.lint
|
10
|
+
#
|
11
|
+
# @example Running AndroidLint with a specific gradle task
|
12
|
+
#
|
13
|
+
# android_lint.gradle_task = "lintMyFlavorDebug"
|
14
|
+
# android_lint.lint
|
15
|
+
#
|
16
|
+
# @example Running AndroidLint for a specific severity level and up
|
17
|
+
#
|
18
|
+
# # options are ["Warning", "Error", "Fatal"]
|
19
|
+
# android_lint.severity = "Error"
|
20
|
+
# android_lint.lint
|
21
|
+
#
|
22
|
+
# @see loadsmart/danger-android_lint
|
23
|
+
# @tags android, lint
|
24
|
+
#
|
25
|
+
class DangerAndroidLint < Plugin
|
26
|
+
|
27
|
+
SEVERITY_LEVELS = ["Warning", "Error", "Fatal"]
|
28
|
+
REPORT_FILE = "app/build/reports/lint/lint-result.xml"
|
29
|
+
|
30
|
+
# Custom gradle task to run.
|
31
|
+
# This is useful when your project has different flavors.
|
32
|
+
# Defaults to "lint".
|
33
|
+
# @return [String]
|
34
|
+
attr_accessor :gradle_task
|
35
|
+
|
36
|
+
# Defines the severity level of the execution.
|
37
|
+
# Selected levels are the chosen one and up.
|
38
|
+
# Possible values are "Warning", "Error" or "Fatal".
|
39
|
+
# Defaults to "Warning".
|
40
|
+
# @return [String]
|
41
|
+
attr_writer :severity
|
42
|
+
|
43
|
+
# Calls lint task of your gradle project.
|
44
|
+
# It fails if `gradlew` cannot be found inside current directory.
|
45
|
+
# It fails if `severity` level is not a valid option.
|
46
|
+
# It fails if `xmlReport` configuration is not set to `true` in your `build.gradle` file.
|
47
|
+
# @return [void]
|
48
|
+
#
|
49
|
+
def lint
|
50
|
+
unless gradlew_exists?
|
51
|
+
fail("Could not find `gradlew` inside current directory")
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
unless SEVERITY_LEVELS.include?(severity)
|
56
|
+
fail("'#{severity}' is not a valid value for `severity` parameter.")
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
unless File.exists?(REPORT_FILE)
|
61
|
+
fail("Lint report not found at `#{REPORT_FILE}`. "\
|
62
|
+
"Have you forgot to add `xmlReport true` to your `build.gradle` file?")
|
63
|
+
end
|
64
|
+
|
65
|
+
system "./gradlew #{gradle_task || 'lint'}"
|
66
|
+
|
67
|
+
issues = read_issues_from_report
|
68
|
+
message = message_for_issues(issues)
|
69
|
+
markdown(message) unless issues.empty?
|
70
|
+
end
|
71
|
+
|
72
|
+
# A getter for `severity`, returning "Warning" if value is nil.
|
73
|
+
# @return [String]
|
74
|
+
def severity
|
75
|
+
@severity || SEVERITY_LEVELS.first
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def read_issues_from_report()
|
81
|
+
file = File.open("app/build/reports/lint/lint-result.xml")
|
82
|
+
|
83
|
+
require 'oga'
|
84
|
+
report = Oga.parse_xml(file)
|
85
|
+
|
86
|
+
report.xpath('//issue')
|
87
|
+
end
|
88
|
+
|
89
|
+
def message_for_issues(issues)
|
90
|
+
message = "### AndroidLint found issues\n\n"
|
91
|
+
|
92
|
+
severity_index = SEVERITY_LEVELS.index(severity) || 0
|
93
|
+
levels = SEVERITY_LEVELS.slice(severity_index, SEVERITY_LEVELS.size)
|
94
|
+
levels.reverse.each do |level|
|
95
|
+
filtered = issues.select{|issue| issue.get("severity") == level}
|
96
|
+
message << parse_results(filtered, level) unless filtered.empty?
|
97
|
+
end
|
98
|
+
|
99
|
+
message
|
100
|
+
end
|
101
|
+
|
102
|
+
def parse_results(results, heading)
|
103
|
+
message = "#### #{heading} (#{results.count})\n\n"
|
104
|
+
|
105
|
+
message << "| File | Line | Reason |\n"
|
106
|
+
message << "| ---- | ---- | ------ |\n"
|
107
|
+
|
108
|
+
results.each do |r|
|
109
|
+
location = r.xpath('location').first
|
110
|
+
filename = location.get('file').split('/').last
|
111
|
+
line = location.get('line') || 'N/A'
|
112
|
+
reason = r.get('message')
|
113
|
+
|
114
|
+
message << "`#{filename}` | #{line} | #{reason} \n"
|
115
|
+
end
|
116
|
+
|
117
|
+
message
|
118
|
+
end
|
119
|
+
|
120
|
+
def gradlew_exists?
|
121
|
+
`ls gradlew`.strip.empty? == false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'android_lint/gem_version'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'android_lint/plugin'
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
describe Danger::DangerAndroidLint do
|
5
|
+
it 'should be a plugin' do
|
6
|
+
expect(Danger::DangerAndroidLint.new(nil)).to be_a Danger::Plugin
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'with Dangerfile' do
|
10
|
+
before do
|
11
|
+
@dangerfile = testing_dangerfile
|
12
|
+
@android_lint = @dangerfile.android_lint
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Fails if gradlew does not exist" do
|
16
|
+
allow(@android_lint).to receive(:`).with("ls gradlew").and_return("")
|
17
|
+
|
18
|
+
@android_lint.lint
|
19
|
+
expect(@android_lint.status_report[:errors]).to eq(["Could not find `gradlew` inside current directory"])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Fails if severity is an unknown value" do
|
23
|
+
allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
|
24
|
+
|
25
|
+
@android_lint.severity = "Dummy"
|
26
|
+
@android_lint.lint
|
27
|
+
|
28
|
+
expect(@android_lint.status_report[:errors]).to eq(["'Dummy' is not a valid value for `severity` parameter."])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Sets severity to 'Warning' if no severity param is provided" do
|
32
|
+
allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
|
33
|
+
allow(File).to receive(:exists?).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(true)
|
34
|
+
|
35
|
+
fake_result = File.open("spec/fixtures/lint-result.xml")
|
36
|
+
allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
|
37
|
+
|
38
|
+
@android_lint.lint
|
39
|
+
expect(@android_lint.severity).to eq("Warning")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "Fails if report file does not exist" do
|
43
|
+
allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
|
44
|
+
allow(File).to receive(:exists?).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(false)
|
45
|
+
|
46
|
+
fake_result = File.open("spec/fixtures/lint-result.xml")
|
47
|
+
allow(File).to receive(:open).with(Danger::DangerAndroidLint::REPORT_FILE).and_return(fake_result)
|
48
|
+
|
49
|
+
@android_lint.lint
|
50
|
+
|
51
|
+
expect(@android_lint.status_report[:errors]).to eq(["Lint report not found at `app/build/reports/lint/lint-result.xml`. "\
|
52
|
+
"Have you forgot to add `xmlReport true` to your `build.gradle` file?"])
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'lint' do
|
56
|
+
before do
|
57
|
+
allow(@android_lint).to receive(:`).with("ls gradlew").and_return("gradlew")
|
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
|
+
end
|
63
|
+
|
64
|
+
it 'Prints markdown if issues were found' do
|
65
|
+
@android_lint.lint
|
66
|
+
|
67
|
+
markdown = @android_lint.status_report[:markdowns].first.message
|
68
|
+
expect(markdown).to include("AndroidLint found issues")
|
69
|
+
|
70
|
+
expect(markdown).to include("Fatal (1)")
|
71
|
+
expect(markdown).to include("`AvatarView.java` | 60 | Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead")
|
72
|
+
|
73
|
+
expect(markdown).to include("Error (1)")
|
74
|
+
expect(markdown).to include("`Events.java` | 21 | Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
|
75
|
+
|
76
|
+
expect(markdown).to include("Warning (1)")
|
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
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -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="Fatal"
|
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'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'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("Tracking / Close to Delivery #%d Location", 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'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("Tracking / At Delivery #%d Location", 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>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
|
3
|
+
$:.unshift((ROOT + 'lib').to_s)
|
4
|
+
$:.unshift((ROOT + 'spec').to_s)
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
require 'rspec'
|
10
|
+
require 'danger'
|
11
|
+
|
12
|
+
# Use coloured output, it's the best.
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.filter_gems_from_backtrace "bundler"
|
15
|
+
config.color = true
|
16
|
+
config.tty = true
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'danger_plugin'
|
20
|
+
|
21
|
+
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
22
|
+
# If you are expanding these files, see if it's already been done ^.
|
23
|
+
|
24
|
+
# A silent version of the user interface,
|
25
|
+
# it comes with an extra function `.string` which will
|
26
|
+
# strip all ANSI colours from the string.
|
27
|
+
|
28
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
29
|
+
def testing_ui
|
30
|
+
@output = StringIO.new
|
31
|
+
def @output.winsize
|
32
|
+
[20, 9999]
|
33
|
+
end
|
34
|
+
|
35
|
+
cork = Cork::Board.new(out: @output)
|
36
|
+
def cork.string
|
37
|
+
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
38
|
+
end
|
39
|
+
cork
|
40
|
+
end
|
41
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
42
|
+
|
43
|
+
# Example environment (ENV) that would come from
|
44
|
+
# running a PR on TravisCI
|
45
|
+
def testing_env
|
46
|
+
{
|
47
|
+
'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
|
48
|
+
'TRAVIS_PULL_REQUEST' => '800',
|
49
|
+
'TRAVIS_REPO_SLUG' => 'artsy/eigen',
|
50
|
+
'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
|
51
|
+
'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# A stubbed out Dangerfile for use in tests
|
56
|
+
def testing_dangerfile
|
57
|
+
env = Danger::EnvironmentManager.new(testing_env)
|
58
|
+
Danger::Dangerfile.new(env, testing_ui)
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danger-android_lint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gustavo Barbosa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oga
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: danger-plugin-api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.41'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.41'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.14'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.14'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '4.7'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '4.7'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: listen
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 3.0.7
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 3.0.7
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: A Danger plugin for Android Lint
|
168
|
+
email:
|
169
|
+
- gustavo@loadsmart.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- .gitignore
|
175
|
+
- CHANGELOG.md
|
176
|
+
- Gemfile
|
177
|
+
- Gemfile.lock
|
178
|
+
- Guardfile
|
179
|
+
- LICENSE.txt
|
180
|
+
- README.md
|
181
|
+
- Rakefile
|
182
|
+
- danger-android_lint.gemspec
|
183
|
+
- lib/android_lint/gem_version.rb
|
184
|
+
- lib/android_lint/plugin.rb
|
185
|
+
- lib/danger_android_lint.rb
|
186
|
+
- lib/danger_plugin.rb
|
187
|
+
- spec/android_lint_spec.rb
|
188
|
+
- spec/fixtures/lint-result.xml
|
189
|
+
- spec/spec_helper.rb
|
190
|
+
homepage: https://github.com/loadsmart/danger-android_lint
|
191
|
+
licenses:
|
192
|
+
- MIT
|
193
|
+
metadata: {}
|
194
|
+
post_install_message:
|
195
|
+
rdoc_options: []
|
196
|
+
require_paths:
|
197
|
+
- lib
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - '>='
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - '>='
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
requirements: []
|
209
|
+
rubyforge_project:
|
210
|
+
rubygems_version: 2.0.3
|
211
|
+
signing_key:
|
212
|
+
specification_version: 4
|
213
|
+
summary: Lint files of a gradle based Android project. This is done using the Android's
|
214
|
+
Lint tool. Results are passed out as tables in markdown.
|
215
|
+
test_files:
|
216
|
+
- spec/android_lint_spec.rb
|
217
|
+
- spec/fixtures/lint-result.xml
|
218
|
+
- spec/spec_helper.rb
|
219
|
+
has_rdoc:
|