Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add excluding_issue_ids option (#34)
Browse files Browse the repository at this point in the history
* Clarify test name

* Update Gemfile.lock

* Add feature to filter by issue ID

Set filter_issue_ids to an array of issue IDs to be ignored.

* Add documentation for filter_issue_ids

* Bump to version 0.0.11

* Rename to excluding_issue_ids

* Update gem version in Gemfile.lock

* Rename to excluding_issue_ids in readme and changelog
  • Loading branch information
petitJAM authored Jul 11, 2022
1 parent 447b63c commit 5565270
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.0.11

- Add `excluding_issue_ids` parameter to skip showing issues with the given IDs, e.g. "MissingTranslation" ([@petitJAM](https://github.com/petitJAM))

# 0.0.10

- Fix `filtering_lines` parameter to also apply to when `inline_mode` is `false` ([@petitJAM](https://github.com/petitJAM))
Expand Down
36 changes: 23 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
PATH
remote: .
specs:
danger-android_lint (0.0.9)
danger-android_lint (0.0.11)
danger-plugin-api (~> 1.0)
oga

GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ansi (1.5.0)
ast (2.4.2)
claide (1.0.3)
claide (1.1.0)
claide-plugins (0.9.2)
cork
nap
Expand All @@ -21,7 +21,7 @@ GEM
colored2 (3.1.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (8.2.3)
danger (8.5.0)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
Expand All @@ -37,24 +37,34 @@ GEM
danger-plugin-api (1.0.0)
danger (> 2.0)
diff-lcs (1.4.4)
faraday (1.4.2)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
multipart-post (>= 1.2, < 3)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-http-cache (2.2.0)
faraday (>= 0.8)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.1.0)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
ffi (1.15.3)
formatador (0.3.0)
git (1.8.1)
git (1.10.2)
rchardet (~> 1.8)
guard (2.17.0)
formatador (>= 0.2.4)
Expand All @@ -70,7 +80,7 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
kramdown (2.3.1)
kramdown (2.3.2)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
Expand All @@ -86,7 +96,7 @@ GEM
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
octokit (4.21.0)
octokit (4.22.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
oga (3.3)
Expand Down Expand Up @@ -133,12 +143,12 @@ GEM
ansi
ast
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
ruby2_keywords (0.0.5)
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
shellany (0.0.1)
terminal-table (3.0.1)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
thor (1.1.0)
unicode-display_width (1.7.0)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ android_lint.filtering_lines = true
android_lint.lint
```

#### Filter issues by ID

In some cases you may want to conditionally ignore specific lint warnings without fully disabling
them in your `lintOptions` configuration. To do that, you can pass a list of IDs to the
`excluding_issue_ids` parameter.

```rb
android_lint.excluding_issue_ids = ["MissingTranslation"]
android_lint.lint
```

#### Make Danger comment directly on the line instead of printing a Markdown table (GitHub only)

```rb
Expand Down
2 changes: 1 addition & 1 deletion lib/android_lint/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AndroidLint
VERSION = "0.0.10".freeze
VERSION = "0.0.11".freeze
end
7 changes: 6 additions & 1 deletion lib/android_lint/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ def severity
# Only show messages within changed files.
attr_accessor :filtering

# Only shows messages for the modified lines.
# Only show messages for the modified lines.
attr_accessor :filtering_lines

# Only show messages for issues not in this list.
attr_accessor :excluding_issue_ids

# 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.
Expand Down Expand Up @@ -167,6 +170,8 @@ def parse_results(results, heading)
message = ""

results.each do |r|
issue_id = r.get('id')
next if excluding_issue_ids && excluding_issue_ids.include?(issue_id)
location = r.xpath('location').first
filename = location.get('file').gsub(dir, "")
next unless (!filtering && !filtering_lines) || (target_files.include? filename)
Expand Down
19 changes: 18 additions & 1 deletion spec/android_lint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module Danger
expect(markdown).to be_nil
end

it 'Doesn`t print anything if no errors were found' do
it 'Doesn`t print anything if no errors were found at the set minimum severity level' do
fake_result = File.open("spec/fixtures/lint-result-without-fatal.xml")
allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)

Expand Down Expand Up @@ -188,6 +188,23 @@ module Danger
expect(warn).not_to include("Implicitly using the default locale is a common source of bugs: Use `String.format(Locale, ...)` instead")
end

describe 'excluding_issue_ids' do
before do
fake_result = File.open("spec/fixtures/lint-result-with-everything.xml")
allow(File).to receive(:open).with(@android_lint.report_file).and_return(fake_result)
end

it 'Does not print ignored issues' do
@android_lint.excluding_issue_ids = ["MissingTranslation", "RtlEnabled"]
@android_lint.lint

markdown = @android_lint.status_report[:markdowns].first.message
expect(markdown).to include("Implicitly using the default locale")
expect(markdown).not_to include("is not translated in")
expect(markdown).not_to include("The project references RTL attributes, but does not explicitly enable or disable RTL support with `android:supportsRtl` in the manifest")
end
end

describe "for a modified file" do
before do
allow(Dir).to receive(:pwd).and_return("/Users/shivampokhriyal/Documents/projects/Commcare/commcare-android")
Expand Down
30 changes: 30 additions & 0 deletions spec/fixtures/lint-result-with-everything.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,34 @@ If you want the methods to just perform ASCII replacement, for example to conver
column="16"/>
</issue>

<issue
id="MissingTranslation"
severity="Error"
message="&quot;someStringResource&quot; is not translated in &quot;de&quot; (German), &quot;fi&quot; (Finnish), &quot;ru&quot; (Russian), &quot;sv&quot; (Swedish), &q
uot;ko&quot; (Korean), &quot;pt&quot; (Portuguese), &quot;el&quot; (Greek), &quot;en&quot; (English), &quot;it&quot; (Italian), &quot;fr&quot; (French), &quot;es&quot; (Spanish), &quot;cs&q
uot; (Czech), &quot;nb&quot; (Norwegian Bokmål), &quot;ja&quot; (Japanese), &quot;da&quot; (Danish), &quot;ca&quot; (Catalan), &quot;nl&quot; (Dutch)"
category="Correctness:Messages"
priority="8"
summary="Incomplete translation"
explanation="If an application has more than one locale, then all the strings declared in one language should also be translated in all other languages.&#xA;&#xA;If the string should **not** be translated, you can add the attribute `translatable=&quot;false&quot;` on the `&lt;string>` element, or you can define all your non-translatable strings in a resource file called `donottranslate.xml`. Or, you can ignore the issue with a `tools:ignore=&quot;MissingTranslation&quot;` attribute.&#xA;&#xA;You can tell lint (and other tools) which language is the default language in your `res/values/` folder by specifying `tools:locale=&quot;languageCode&quot;` for the root `&lt;resources>` element in your resource file. (The `tools` prefix refers to the namespace declaration `http://schemas.android.com/tools`.)"
errorLine1=" &lt;string name=&quot;someStringResource&quot;>Hello this is a string resource.&lt;/string>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="/Users/gustavo/Developer/app-android/app/src/main/res/values/strings.xml"
line="10"
column="13"/>
</issue>

<issue
id="RtlEnabled"
severity="Warning"
message="The project references RTL attributes, but does not explicitly enable or disable RTL support with `android:supportsRtl` in the manifest"
category="Internationalization:Bidirectional Text"
priority="3"
summary="Using RTL attributes without enabling RTL support"
explanation="To enable right-to-left support, when running on API 17 and higher, you must set the `android:supportsRtl` attribute in the manifest `&lt;application>` element.&#xA;&#xA;If you have started adding RTL attributes, but have not yet finished the migration, you can set the attribute to false to satisfy this lint check.">
<location
file="/Users/gustavo/Developer/app-android/app/src/main/AndroidManifest.xml"/>
</issue>

</issues>

0 comments on commit 5565270

Please sign in to comment.