Class: Danger::DangerAndroidLint
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerAndroidLint
- Defined in:
- lib/android_lint/plugin.rb
Overview
Lint files of a gradle based Android project. This is done using the Android’s [Lint](developer.android.com/studio/write/lint.html) tool. Results are passed out as tables in markdown.
Constant Summary collapse
- SEVERITY_LEVELS =
["Warning", "Error", "Fatal"]
Instance Attribute Summary collapse
-
#excluding_issue_ids ⇒ Object
Only show messages for issues not in this list.
-
#filtering ⇒ Object
Enable filtering Only show messages within changed files.
-
#filtering_lines ⇒ Object
Only show messages for the modified lines.
-
#gradle_task ⇒ String
A getter for ‘gradle_task`, returning “lint” if value is nil.
-
#report_file ⇒ String
A getter for ‘report_file`.
-
#severity ⇒ String
A getter for ‘severity`, returning “Warning” if value is nil.
-
#skip_gradle_task ⇒ Boolean
A getter for ‘skip_gradle_task`, returning `false` if value is nil.
Instance Method Summary collapse
-
#lint(inline_mode: false) ⇒ void
Calls lint task of your gradle project.
Instance Attribute Details
#excluding_issue_ids ⇒ Object
Only show messages for issues not in this list.
91 92 93 |
# File 'lib/android_lint/plugin.rb', line 91 def excluding_issue_ids @excluding_issue_ids end |
#filtering ⇒ Object
Enable filtering Only show messages within changed files.
85 86 87 |
# File 'lib/android_lint/plugin.rb', line 85 def filtering @filtering end |
#filtering_lines ⇒ Object
Only show messages for the modified lines.
88 89 90 |
# File 'lib/android_lint/plugin.rb', line 88 def filtering_lines @filtering_lines end |
#gradle_task ⇒ String
A getter for ‘gradle_task`, returning “lint” if value is nil.
50 51 52 |
# File 'lib/android_lint/plugin.rb', line 50 def gradle_task @gradle_task end |
#report_file ⇒ String
A getter for ‘report_file`.
38 39 40 |
# File 'lib/android_lint/plugin.rb', line 38 def report_file @report_file end |
#severity ⇒ String
A getter for ‘severity`, returning “Warning” if value is nil.
79 80 81 |
# File 'lib/android_lint/plugin.rb', line 79 def severity @severity || SEVERITY_LEVELS.first end |
#skip_gradle_task ⇒ Boolean
A getter for ‘skip_gradle_task`, returning `false` if value is nil.
66 67 68 |
# File 'lib/android_lint/plugin.rb', line 66 def skip_gradle_task @skip_gradle_task ||= false end |
Instance Method Details
#lint(inline_mode: false) ⇒ void
This method returns an undefined value.
Calls lint task of your gradle project. It fails if ‘gradlew` cannot be found inside current directory. It fails if `severity` level is not a valid option. It fails if `xmlReport` configuration is not set to `true` in your `build.gradle` file.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/android_lint/plugin.rb', line 99 def lint(inline_mode: false) unless skip_gradle_task return fail("Could not find `gradlew` inside current directory") unless gradlew_exists? end unless SEVERITY_LEVELS.include?(severity) fail("'#{severity}' is not a valid value for `severity` parameter.") return end unless skip_gradle_task system "./gradlew #{gradle_task}" end unless File.exists?(report_file) fail("Lint report not found at `#{report_file}`. "\ "Have you forgot to add `xmlReport true` to your `build.gradle` file?") end issues = read_issues_from_report filtered_issues = filter_issues_by_severity(issues) = "" if inline_mode # Report with inline comment send_inline_comment(filtered_issues) else = (filtered_issues) markdown("### AndroidLint found issues\n\n" + ) unless .to_s.empty? end end |