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

Pre commit hooks and Samples update #86

Merged

Conversation

macisamuele
Copy link
Collaborator

@macisamuele macisamuele commented Jan 27, 2020

As mentioned in #82 this follow-up PR ensures:

  • samples are updated with code on the branch
  • pre-commit are updated and all the repo is re-validated against it

@macisamuele macisamuele added the infra PR or Issue related to project infrastructure label Jan 27, 2020
hooks:
- id: detect-secrets
args: [--baseline, .secrets.baseline]

# Do NOT run pre-commit hooks on generated-code
exclude: ^samples/[^/]+/src/main/java
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure about this?
KtLint was sanitising the generated code a lot. Now it doesn't really look that elegant as before. Any arguments for having this exclude rule here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The proposal here, and I'm more than happy to remove this line if needed, is that samples should contain the exact output of the tool.

If the generated code does not look "elegant" then we should eventually update the tool to generate some more elegant result rather than having ktlint fixing it.

One of the many things that I was noticing is that we have import okhttp3.RequestBody on all *Api.kt files even if we don't have parameters of type: file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the generated code does not look "elegant" then we should eventually update the tool to generate some more elegant result rather than having ktlint fixing it.

This is not always possible due to limitations of mustache.
I'm generally fine with:

generator outputting not elegant code -> formatter fixing it -> eventually committing it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What might eventually be a concern is that having the formatter fixing the file might hide issues within the generated code.

Think about the import okhttp3.RequestBody. The linter removes it because RequestBody is not used in most of the generated files. That's great, but what if we are using the generated code into a pipeline that generates an artifact? Probably we're going to have issues because the import statement (with the typo) will fail or similar.

About mustache limitations, I agree, I'll try to work on it to understand how complex would be to generate "elegant" enough code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Keeping this open as we're going to move the effort to address this specific comment into a separate PR

@macisamuele
Copy link
Collaborator Author

In order to get the pre-commit hooks and samples updated I'm removing from this PR the pre-commit exclusion of the samples.

I'll address #86 (comment) into a subsequent PR (the new PR will mostly focus on having mustache generate a "nicer" code that will make ktlint a bit happier).

@macisamuele macisamuele force-pushed the maci-pre-commit-hooks-and-samples-update branch from 7a503e7 to 4a9fbf9 Compare February 3, 2020 13:47
…d value toward teastability or showing how the generated code looks like
@cortinico
Copy link
Collaborator

  • ensure that pre-commit does not alter the code generated by the tool

Please update the description of this PR

@cortinico cortinico added this to the 1.4.0 milestone Feb 3, 2020
Copy link
Collaborator

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

LGTM. You do have merge conflicts but this looks good for me to be merged whenever you want.

@macisamuele macisamuele merged commit 722fba1 into Yelp:master Feb 4, 2020
@macisamuele macisamuele deleted the maci-pre-commit-hooks-and-samples-update branch February 4, 2020 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infra PR or Issue related to project infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants