Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prohibit post/postDelayed via a new regex check #4689

Closed
BenHenning opened this issue Nov 1, 2022 · 1 comment · Fixed by #4900
Closed

Prohibit post/postDelayed via a new regex check #4689

BenHenning opened this issue Nov 1, 2022 · 1 comment · Fixed by #4900

Comments

@BenHenning
Copy link
Member

Is your feature request related to a problem? Please describe.
post/postDelayed are difficult to use correctly, and likely always have a better alternative possible per https://betterprogramming.pub/stop-using-post-postdelayed-in-your-android-views-9d1c8eeaadf2.

Describe the solution you'd like
These functions should be prohibited using regex checks with alternatives mentioned, such as using a LiveData observer or specific lifecycle callbacks that guarantee a view being measured or available.

Describe alternatives you've considered
N/A

Additional context
N/A

@BenHenning
Copy link
Member Author

/cc @JishnuGoyal as FYI since we were chatting about this today.

BenHenning added a commit that referenced this issue Apr 11, 2023
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->
Fix #4689: When merged, this PR will;
- Add regex check to prohibit the usage of post() and postDelayed()
- Add tests for the regex check added.
- Add file exemptions for files that don't meet the new rules.

**The commits pushed on 4th April 2023 will**;
- Remove tests from exemptions list of the regex check.
- Add `RegexPatternValidationCheckTest.kt` to exemptions since it is
matched correctly against the regex. This is an undesired side effect or
removing tests from exemptions.
- Modify the language of the error message to align with Oppia
guidelines.
- Remove the `SpotlightFragment.kt` from exemptions since it contains no
instance of post() or postDelayed()
- Update the regex to take care of cases with curly braces such as `post
{}` instead of only matching `post() `and `postDelayed()`.
- Cater for any spaces between the post/postDelayed and the bracket used
i.e. `post ()`, `postDelayed ()` and `post {}`.
- Add another test to verify check for usages of post with curly braces.
- Add an extra test in the test methods to ensure that the correct error
message is being shown.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
<!-- Delete these section if this PR does not include UI-related
changes. -->
If your PR includes UI-related changes, then:
- Add screenshots for portrait/landscape for both a tablet & phone of
the before & after UI changes
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))
- Add a video showing the full UX flow with a screen reader enabled (see
[accessibility
guide](https://github.com/oppia/oppia-android/wiki/Accessibility-(A11y)-Guide))
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing

---------

Co-authored-by: Ben Henning <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant