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

Add twitter compose rules ktlint check #610

Closed
wants to merge 1 commit into from

Conversation

luizgrp
Copy link
Member

@luizgrp luizgrp commented Sep 22, 2022

WHAT

Run Twitter's Jetpack Compose Rules in CI.

WHY

In order to improve quality of project's composables.

HOW

Add plugin via kolinter given it's not currently working with spotless. Given it might be potentially doing duplicated work and increasing build time, we might decide to only add it to the project once it's supported by spotless.

RESULTS

  • A lot of findings in composables functions in preview files, test files, and sample apps, which we should filter out for those rules.

  • modifier-missing-check in many functions.

Lint error > [twitter-compose:modifier-missing-check] This @Composable function emits content but doesn't have a modifier parameter.

See https://twitter.github.io/compose-rules/rules/#when-should-i-expose-modifier-parameters for more information.
  • param-order-check in WearNavScaffold, SegmentedProgressIndicator, FillerScreen, BigScalingLazyColumn, BigColumn, MediaPlayerScaffold, StandardChip and other internal functions.
Lint error > [twitter-compose:param-order-check]         Parameters in a composable function should be ordered following this pattern: params without defaults, modifiers, params with defaults and optionally, a trailing function that might not have a default param.

See https://twitter.github.io/compose-rules/rules/#ordering-composable-parameters-properly for more information.
  • modifier-reused-check in PlayPauseButton (seems to be intended?).
[twitter-compose:modifier-reused-check] Modifiers should only be used once and by the root level layout of a Composable. This is true even if
appended to or with other modifiers e.g. 'modifier.fillMaxWith()'.

Use Modifier (with a capital 'M') to construct a new Modifier that you can pass to other Composables.

See https://twitter.github.io/compose-rules/rules/#dont-re-use-modifiers for more information.
  • twitter-compose:multiple-emitters-check in TimePicker.
Lint error > [twitter-compose:multiple-emitters-check] Composable functions should only be emitting content into the composition from one source at their top level.

Checklist 📋

  • [N/A] Add explicit visibility modifier and explicit return types for public declarations
  • Run spotless check
  • Run tests
  • [N/A] Update metalava's signature text files

Copy link
Collaborator

@yschimke yschimke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea!

@luizgrp
Copy link
Member Author

luizgrp commented Sep 26, 2022

Closing as kotlinter does not support baselines - jeremymailen/kotlinter-gradle#167

Using kotlinter was a temporary option until spotless can enable custom ruleset diffplug/spotless#1220

@luizgrp luizgrp closed this Sep 26, 2022
@luizgrp luizgrp deleted the twitter_compose_rules branch September 26, 2022 09:56
@luizgrp luizgrp self-assigned this Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants