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
-
#filtering ⇒ Object
Enable filtering Only show messages within changed files.
-
#gradle_task ⇒ String
Custom gradle task to run.
-
#report_file ⇒ String
A getter for ‘report_file`.
-
#severity ⇒ String
A getter for ‘severity`, returning “Warning” if value is nil.
-
#skip_gradle_task ⇒ Object
Skip gradle task.
Instance Method Summary collapse
-
#lint(inline_mode: false) ⇒ void
Calls lint task of your gradle project.
Instance Attribute Details
#filtering ⇒ Object
Enable filtering Only show messages within changed files.
55 56 57 |
# File 'lib/android_lint/plugin.rb', line 55 def filtering @filtering end |
#gradle_task ⇒ String
Custom gradle task to run. This is useful when your project has different flavors. Defaults to “lint”.
44 45 46 |
# File 'lib/android_lint/plugin.rb', line 44 def gradle_task @gradle_task end |
#report_file ⇒ String
A getter for ‘report_file`.
33 34 35 |
# File 'lib/android_lint/plugin.rb', line 33 def report_file @report_file end |
#severity ⇒ String
A getter for ‘severity`, returning “Warning” if value is nil.
98 99 100 |
# File 'lib/android_lint/plugin.rb', line 98 def severity @severity || SEVERITY_LEVELS.first end |
#skip_gradle_task ⇒ Object
Skip gradle task
58 59 60 |
# File 'lib/android_lint/plugin.rb', line 58 def skip_gradle_task @skip_gradle_task 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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/android_lint/plugin.rb', line 66 def lint(inline_mode: false) if !skip_gradle_task && !gradlew_exists? fail("Could not find `gradlew` inside current directory") return end unless SEVERITY_LEVELS.include?(severity) fail("'#{severity}' is not a valid value for `severity` parameter.") return end system "./gradlew #{gradle_task || 'lint'}" unless skip_gradle_task 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 |