0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 20:03:05 +02:00
Commit Graph

80 Commits

Author SHA1 Message Date
David Allison
b1468a2425 fix: Don't apply lint to ignored file
tools:ignore ignores the outcome, but still processed the file

This caused a bug as it found a duplicate key in an ignored file

and flagged it as an error on the non-ignored file
2022-04-24 14:56:36 -05:00
David Allison
bec3b346f1 fix: Don't apply strings lint to non-strings file
DuplicateCrowdInStrings applies to only the /values/ folder
But there are other files in the values folder aside from translatable
strings (resources, constants, etc...)

As lint does not currently have a good way to exclude files from linting
So instead we use `tools:ignore` to do this
2022-04-24 10:18:11 -05:00
David Allison
b51e99f0fd refactor: Kotlin Cleanup: DuplicateCrowdInStrings 2022-04-24 10:18:11 -05:00
David Allison
7c4bba2807 refactor: Convert DuplicateCrowdInStrings to Kotlin
com.ichi2.anki.lint.rules.DuplicateCrowdInStrings
2022-04-23 20:48:23 -05:00
David Allison
e83e696735 refactor: Rename DuplicateCrowdInStrings.java to .kt
com.ichi2.anki.lint.rules.DuplicateCrowdInStrings
2022-04-23 20:48:23 -05:00
David Allison
c16aae062a
feat: Allow Kotlin Migration on lint-rules (#11037)
* lint-rules: include kotlinMigration-lint

changes from `AnkiDroid/kotlinMigration`:

* remove `android { }` wrapper around `ktlint { }`

Due to this change, we use a new file
We use the -lint suffix to imply to reviewers that this is a different
 file type

* lint-rules: remove ANDROID_TEST from kotlinMigration
2022-04-23 16:37:36 -05:00
Mike Hardy
a70c0f6a38 fix: nonPositionalFormatSubstitution rule should use same param name as super
quiets a build warning
2022-04-23 14:32:38 -05:00
Mike Hardy
22c5da6522 fix: forward-port to non-deprecated APIs in DuplicateCrowdInStrings rule 2022-04-21 08:55:01 -05:00
Mike Hardy
10db92dbb0 chore(lint): fix lint compile warning re: missing Vendor 2022-04-20 15:34:48 +01:00
David Allison
d3e103f7fa docs: improve JUnitNullAssertionDetector message
* kotlin.test is better if we use assertNull without a message
* JUnitAsserter requires a message, meaning more change

Good to use:

https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/assert-null.html
https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/assert-not-null.html
https://kotlinlang.org/api/latest/kotlin.test/kotlin.test.junit/-j-unit-asserter/
2022-04-13 11:29:13 -05:00
David Allison
5da9561a29 refactor: typos & related KotlinCleanup 2022-04-07 10:27:03 -05:00
Divyansh Dwivedi
bff7e5ed3e
added New Lint rule for Detecting invalid string formats. (#10628) 2022-03-31 16:00:15 -05:00
Mike Hardy
2147589640 chore(ktlint): bump ktlint to 0.45.1 / spacing changes w/new version
spacing changes were produced automatically using the new version on the
command line with `-F` argument to auto-fix spacing to conform with new
version of the tool
2022-03-23 16:14:53 -05:00
Arthur Milchior
1d5ccb5620 NF: rename folder to directory
Simply for the sake of consistency. It will ensure that when searching for a
method, function or variable name, I have a single word to look for

This was done by a simple search and replace in .java and .kt files, preserving
case.

The only exception being org.junit.rules.TemporaryFolder and its method
`newFolder`, which obviously was not renamed.

Note that `folder` can't be entirely renamed to `directory` either because of
the class `DirectoryStream`. It seems even Java is not consistent between Folder
and directory
2022-03-14 16:12:07 +05:30
David Allison
4745b60d40 docs(copyright): Improve docs 2022-03-07 15:26:01 -05:00
David Allison
04735878ce feat(lint): Ensure use of JUnitAsserter
Adds lint to help with Kotlin migration

This removes some needs for `!!` in the code:

`assertNotNull(x)` -> `x` is now known to be non-null.

This will break lint on the "rename" commit in a Kotlin migration,
I feel this is worthwhile as otherwise the lint check would
 not be viable

https://kotlinlang.org/api/latest/kotlin.test/kotlin.test.junit/-j-unit-asserter/

Issue 10427
2022-03-05 08:30:43 -05:00
David Allison
21c5bcdc8e feat(lint): Verify Positional Format Strings
AAPT displayed these issues as build as warnings, but CI passed

Add lint to make sure this is caught.

We take AAPT's C++ code and convert it to Kotlin.

Tested on commit d392498050

Errors looks like:

AnkiDroid\src\main\res\values\04-network.xml:84:
Multiple substitutions specified in non-positional format.
Convert "%s" to "%1$s"
[NonPositionalFormatSubstitutions from com.ichi2.anki.lint]

Fixes 10347
2022-02-20 17:20:51 -05:00
Akshit Sinha
1b597dfc96 Fixed Typo in KotlinMigrationBrokenEmails 2022-02-12 07:14:07 -05:00
Akshit Sinha
29eb51518a Added a Lint Check for line-break tag issue in kotlin migration 2022-02-12 07:14:07 -05:00
Mike Hardy
b430879e54
Dependency updates 20220201 (#10296)
* Bump mockito-inline from 4.3.0 to 4.3.1

Bumps [mockito-inline](https://github.com/mockito/mockito) from 4.3.0 to 4.3.1.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v4.3.0...v4.3.1)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-inline
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* test(lint): only run default TestModes for prefer is empty check

if the extra whitespace mode runs, it perturbs the diff and the check fails

* Bump lint_version from 30.0.4 to 30.1.0

Bumps `lint_version` from 30.0.4 to 30.1.0.

Updates `lint-api` from 30.0.4 to 30.1.0

Updates `lint` from 30.0.4 to 30.1.0

Updates `lint-tests` from 30.0.4 to 30.1.0

---
updated-dependencies:
- dependency-name: com.android.tools.lint:lint-api
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: com.android.tools.lint:lint
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: com.android.tools.lint:lint-tests
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump fragment-testing from 1.4.0 to 1.4.1

Bumps fragment-testing from 1.4.0 to 1.4.1.

---
updated-dependencies:
- dependency-name: androidx.fragment:fragment-testing
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump preference-ktx from 1.1.1 to 1.2.0

Bumps preference-ktx from 1.1.1 to 1.2.0.

---
updated-dependencies:
- dependency-name: androidx.preference:preference-ktx
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* test(layout): do not attempt to inflate preference_category_material

* Bump fragment-ktx from 1.4.0 to 1.4.1

Bumps fragment-ktx from 1.4.0 to 1.4.1.

---
updated-dependencies:
- dependency-name: androidx.fragment:fragment-ktx
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump protobuf-java from 3.19.3 to 3.19.4

Bumps [protobuf-java](https://github.com/protocolbuffers/protobuf) from 3.19.3 to 3.19.4.
- [Release notes](https://github.com/protocolbuffers/protobuf/releases)
- [Changelog](https://github.com/protocolbuffers/protobuf/blob/master/generate_changelog.py)
- [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.19.3...v3.19.4)

---
updated-dependencies:
- dependency-name: com.google.protobuf:protobuf-java
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-01 08:43:44 -05:00
David Allison
14898fa14f lint: kotlin conversion corrupting emails
The Java -> Kotlin migration converts <...> into html tags
if the comment is /** instead of /*

This often catches the copyright header of files, which is bad
as it corrupts the emails in the copyright.

Pickup the email `<http:></http:>` and report this
2021-10-30 08:25:25 -05:00
David Allison
174ae14237 feat(lint-GPL): Steps for GPL compatible licenses
https://www.gnu.org/licenses/license-list.en.html#GPLCompatibleLicenses

https://softwarefreedom.org/resources/2007/gpl-non-gpl-collaboration.html#x1-40002.2

Fixes 9260
2021-10-18 13:02:21 -05:00
David Allison
b0fd892c1f lint: enable 'missing copyright' on tests
Previous commits have resolved the current warnings, this stops
it from occurring for new users

Issue 9538 - enable lint warnings on tests
2021-10-09 09:40:08 -05:00
David Allison
ee962c2d19 lint: check NonPublicNonStaticFieldName in tests
Issue 9538
2021-09-22 11:00:22 -05:00
Nicola Dardanis
c6f5d3f3ea lint: Use isEmpty instead of comparing size to zero 2021-08-27 08:19:38 -05:00
Nicola Dardanis
51ac9055db lint: Avoid use of field prefixes for variable names 2021-08-27 08:15:20 -05:00
David Allison
5a951f13de lint: Only enforce variable naming in java
We want to move away from AOSP naming for Kotlin

As it makes getters and primary constructors less useful
as the naming conflicts with other policies we want to enforce
AOSP naming is also against Google suggestions

Fixes 9377
2021-08-05 21:33:20 -05:00
dependabot[bot]
a8681b3486 build(deps): bump lint_version from 27.2.2 to 30.0.0
Fix errors which were introduced:

* api is now required
* Unicode Handling changed
* Compilation errors from missing imports were introduced
  * a2d0a4ca4d

Bumps `lint_version` from 27.2.2 to 30.0.0.

Updates `lint-api` from 27.2.2 to 30.0.0

Updates `lint` from 27.2.2 to 30.0.0

Updates `lint-tests` from 27.2.2 to 30.0.0

---
updated-dependencies:
- dependency-name: com.android.tools.lint:lint-api
  dependency-type: direct:production
  update-type: version-update:semver-major
- dependency-name: com.android.tools.lint:lint
  dependency-type: direct:production
  update-type: version-update:semver-major
- dependency-name: com.android.tools.lint:lint-tests
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-29 13:33:45 -05:00
David Allison
619c8d0b00 nf: NonNull annotation 2021-07-09 11:13:44 -05:00
David Allison
7cf2ea7850 fix[lint]: allow Kotlin companion objects
`ConstantFieldName` lint was triggered by auto-generated Kotlin
companion objects named "Companion" (expected: COMPANION)

As these are auto-generated, allow constants called "Companion"

Fixes 9223
2021-07-09 11:13:44 -05:00
David Allison
95ddf9bdbb gradle: consolidate lint library version
Reduce GitHub notification spam (previously we get 3 update PRs)
as the library updates in lockstep

Fixes 9179
2021-07-01 13:38:23 -05:00
almas33
bc7c2b98bb Lint: Ensure Copyright Header Exists
This is a common issue in code reviews
The lint check explains how to fix the issue
so reduces review load and helps onboarding

Fixes 8359
2021-06-24 10:28:56 -05:00
David Allison
1a08c583f3 Extract Kotlin version to variable
Review comment: keeps all Kotlin modules in sync

Note: adding this to the `ext { }` section didn't work for the main
build.gradle, but would be a better solution

Using
https://stackoverflow.com/questions/64834818/android-studio-could-not-get-unknown-property-kotlin-version
2021-06-23 23:16:23 -05:00
Shridhar
4f21060f5e Use compileOnly for Kotlin dependency in lint-rules 2021-05-28 20:12:33 +02:00
Shridhar
49a98af859 Migrate UiUtil to Kotlin 2021-05-28 20:12:33 +02:00
Mike Hardy
bd37e05495
Dependency updates 20210522 (#8906)
* Bump junit-vintage-engine from 5.7.1 to 5.7.2

Bumps [junit-vintage-engine](https://github.com/junit-team/junit5) from 5.7.1 to 5.7.2.
- [Release notes](https://github.com/junit-team/junit5/releases)
- [Commits](https://github.com/junit-team/junit5/compare/r5.7.1...r5.7.2)

Signed-off-by: dependabot[bot] <support@github.com>

* Bump fragment from 1.3.3 to 1.3.4

Bumps fragment from 1.3.3 to 1.3.4.

Signed-off-by: dependabot[bot] <support@github.com>

* Bump fragment-testing from 1.3.3 to 1.3.4

Bumps fragment-testing from 1.3.3 to 1.3.4.

Signed-off-by: dependabot[bot] <support@github.com>

* Bump annotations from 20.1.0 to 21.0.0

Bumps [annotations](https://github.com/JetBrains/java-annotations) from 20.1.0 to 21.0.0.
- [Release notes](https://github.com/JetBrains/java-annotations/releases)
- [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md)
- [Commits](https://github.com/JetBrains/java-annotations/compare/20.1.0...21.0.0)

Signed-off-by: dependabot[bot] <support@github.com>

* chore(dependencies): bump appcompat (rc01->stable) and some test only deps

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-22 12:19:03 -05:00
Arthur Milchior
6c0d3b77fa NF: remove JetBrains Nullable 2021-05-22 09:28:39 -05:00
Arthur Milchior
dcbed8f5cf NF: remove jetbrains NotNull 2021-05-22 09:28:39 -05:00
Mike Hardy
9c90cc52e5
Dependency updates 20210514 (#8840)
* Bump lint-api from 27.2.0 to 27.2.1
* Bump lint-tests from 27.2.0 to 27.2.1
* Bump gradle from 4.2.0 to 4.2.1
* Bump lint from 27.2.0 to 27.2.1
* Bump jackson-databind from 2.12.0 to 2.12.3
* Bump protobuf-java from 3.15.8 to 3.17.0
2021-05-14 17:42:59 -05:00
Mike Hardy
49edb49e17 build: android-gradle-plugin 4.2.0 + others
- remove jcenter (deprecated, thankfully no longer needed)
- remove r8 workaround for previous issue, AGP 4.2.0 has fix built-in
- bump Triple-T / Play Publisher plugin to match AGP 4.2.0
- remove java 1_8 source/target compat annotation, it is default in 4.2
- add noinspection for commons-compress - has to wait until API26
- lint to 27.2.0
- fragment to 1.2.3
2021-05-07 17:16:00 -05:00
David Allison
5fbb8801e8 docs: improve lint error
Was ambiguous about adding the attribute to just one string
2021-04-26 05:02:29 +02:00
Prateek Singh
11667f9de6 Updated Fixed Title length lint rule 2021-04-24 02:38:37 +02:00
Mike Hardy
61cb6c3f05 Update to gradle 7.0
- API publishing needed a complete overhaul, tested locally, works
- JCenter is still needed for AnkiDroid as noted unfortunately...couple months to go
- Some artifact resolution performance complaints but local testing shows every single thing works
2021-04-15 23:21:34 -05:00
Mrudul Tora
557eff4dc8
Lint: Lint rule for use of UIUtils.showSnackbar instead of Snackbar.make (#8625)
* Added lint rule for use of UIUtils.showSnackbar instead of Snackbar.make
* Fixed the lint errors related to Snackbar.make
* Fixed inconsistent spacing

Co-authored-by: David Allison <62114487+david-allison-1@users.noreply.github.com>
2021-04-15 22:44:46 -05:00
David Allison
3541c210d8 Add lint rule to enforce constant field naming
For: `public static final` variables

Lint Id: ConstantFieldName

Automation: Means that we don't need to enforce this in code reviews

Constant (final variables) names must be all uppercase using underscore
 to separate words.

https://github.com/ankidroid/Anki-Android/wiki/Code-style#constant-final-variables-names-must-be-all-uppercase-using-underscore-to-separate-words

Note: The wording is imprecise: so only flag public constants
2021-04-14 12:43:52 -05:00
David Allison
f1e37dc557 Add lint rule to enforce 'm' variable prefix
For: Non-Static, Non-Public variables

Lint Id: NonPublicNonStaticFieldName

Automation: Means that we don't need to enforce this in code reviews

https://github.com/ankidroid/Anki-Android/wiki/Code-style#non-public-non-static-field-names-should-start-with-m
2021-04-14 12:43:52 -05:00
Nicola Dardanis
901260bed6 lint: Reorder rules lexicographically in IssueRegistry 2021-04-14 11:15:14 -05:00
Nicola Dardanis
f8135927d1 lint: Add DirectToastMakeTextUsage rule 2021-04-14 11:15:14 -05:00
David Allison
89a7679839 Add lint rule: PrintStackTraceUsage
Speed up code review by ensuring that e.printStackTrace() isn't used

Also includes AnkiDroid's first "Auto-Fix" for lint
2021-04-08 10:08:22 -05:00
dependabot-preview[bot]
b7537af36a Bump lint-api from 27.1.2 to 27.1.3
Bumps lint-api from 27.1.2 to 27.1.3.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump lint-tests from 27.1.2 to 27.1.3

Bumps lint-tests from 27.1.2 to 27.1.3.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump lint from 27.1.2 to 27.1.3 (#303)

* Bump lint from 27.1.2 to 27.1.3

Bumps lint from 27.1.2 to 27.1.3.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Update lint-rules/build.gradle

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Mike Hardy <github@mikehardy.net>
2021-03-19 15:31:02 -05:00