Skip to content

Conversation

@cartland
Copy link
Contributor

Snippets from this repository are included in documentation at developer.android.com. Long lines are difficult to read in these snippets (and in general). We previously disabled ktlint for max-line-length because it was difficult to enforce across all snippets. Now we're seeing the challenge appear in the documentation publishing process. Since the snippet line length is not enforced in the code base, teams are adding manual warnings and checks at publishing time to make sure that the line length is not too long.

I am creating this pull request to show which changes will allow max-line-length to be enforced. I will ask teams to review these changes to make sure they don't cause other side effects in the documentation or build process. After everyone is satisfied, we can enforce the line lengths.

@snippet-bot
Copy link

snippet-bot bot commented Nov 6, 2025

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@cartland cartland force-pushed the cartland/line-length branch from 48691b6 to 3f1660d Compare November 6, 2025 07:47
@devbridie
Copy link
Member

I am supportive of this, but I don't see how the modification of the lint rules follow the changes that are suggested in the PR - are there some changes that are manual instead of generated by the linter? Examples on the commits.

.wrapContentWidth()
.padding(8.dp),
style = MaterialTheme.typography.titleSmall
style = MaterialTheme.typography.titleSmall,
Copy link
Member

Choose a reason for hiding this comment

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

Added trailing comma

}
composable(
"details/{id}",
route = "details/{id}",
Copy link
Member

Choose a reason for hiding this comment

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

Named parameter added

) {
Icon(
painter = if (isPressed) painterResource(id = selectedImage) else painterResource(id = unselectedImage),
painter = if (isPressed) {
Copy link
Member

Choose a reason for hiding this comment

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

Brace style fixed

shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f)),
surfaceProtection = SurfaceEntity.SurfaceProtection.SURFACE_PROTECTION_PROTECTED
surfaceProtection =
SurfaceEntity.SurfaceProtection.SURFACE_PROTECTION_PROTECTED
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct? I would expect an indent here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would also expect an indent here. I'm not sure why Spotless or Android Studio suggested this formatting. If I have time, I can check to see if Spotless will let me add the indentation. I would normally expect Spotless to fix this, so maybe some of the other lint rules can be improved.

@cartland
Copy link
Contributor Author

cartland commented Nov 7, 2025

Whenever possible, the changes come from ./gradlew spotlessApply. When Spotless failed, I tried to make minimal changes and then use Android Studio to fix formatting. Sometimes these disagree with each other, so I did the bare minimum to make sure that ./gradlew spotlessCheck passed.

In general, I think it's better to try and simplify the Spotless configuration so that it uses more and more of the default Android Studio style guides. Currently there are a lot of disabled rules, and I'm not sure how long those disabled rules interact with each other. I'm also not sure why there are two different line length rules that were disabled.

Overall, I agree with your confusion. If we can fix more of these style issues with Spotless configuration, then we can spend less time discussing the indentation, named parameters, and trailing commas.

The primary purpose of this change is to provide a step towards a more strict and standard Spotless configuration. If it's easier, you are welcome to close this pull request and create a new one with additional changes that go beyond this step. You are also welcome to merge this version and then create additional changes that build on it.

@kkuan2011
Copy link
Contributor

Discussed with Cartland about how we can move forward on this. I think we need to enable more of the Spotless rules one-by-one, and then hopefully enabling this rule will only change the line lengths and not change other parts of the code. So we don't need to enforce line length later down the pipeline. Thanks Cartland! We'll take a closer look at how to get to this state.

@kkuan2011 kkuan2011 closed this Nov 7, 2025
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.

4 participants