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

Include code format tools #49

Merged
merged 24 commits into from
Jun 4, 2021
Merged

Include code format tools #49

merged 24 commits into from
Jun 4, 2021

Conversation

kevinlind
Copy link
Collaborator

@kevinlind kevinlind commented May 24, 2021

Description

Includes code format tools to build system.

  • Adds Spotless configuration to Gradle scripts
  • Configures Spotless with Prettier in edgeidentity module (Java files)
  • Configures Spotless with ktlint in app module (Kotlin files)
  • Adds config/formatter/adobe.header.txt used by Spotless to apply copyright header to all Java and Kotlin files
  • Add Makefile targets to apply and check formatting by running Spotless gradle commands.
  • Add .githook folder with pre-commit hook to apply formatting on each commit. Include init Makefile target to set git's core.hooksPath to this folder.
  • Update README with formatting instructions.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

.circleci/config.yml Show resolved Hide resolved
.githook/pre-commit Outdated Show resolved Hide resolved
ij_visual_guides = 120
ij_wrap_on_typing = false

[*.java]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've only included the configurations for Java and Kotlin as those were the only two languages I've configured. I manually removed the configs for other languages when exporting the file from Android Studio.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are these mostly custom or default settings? Can we keep only the custom ones for easier maintenance?

Copy link
Contributor

Choose a reason for hiding this comment

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

Any updates on this one?

spotless {
kotlin {
target "src/*/java/**/*.kt"
ktlint('0.41.0')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I decided to use ktlint here to format the Kotlin test app. There were minimal changes to the app files after running the formatting.

Comment on lines +17 to +22
format:
(./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessApply)
(./code/gradlew -p code/$(TEST-APP-FOLDER-NAME) spotlessApply)

format-check:
(./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessCheck)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I set the make targets to apply formatting to both the source code and test app, but only to check the formatting on the source code. I can add a check to the test app code as well, but I was thinking we wouldn't want to fail a build if the test app source wasn't formatted correctly. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it doesn't hurt to add the check for the test app if we anyway run the hook/format cmd on both.


jacoco {
toolVersion = rootProject.ext.jacocoVersion
}

preBuild.dependsOn spotlessApply
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will apply the formatting when the project is built. I feel this could be convenient, but as there is the pre-commit hook, if this ends up adding too much time to every build we can remove it.

@codecov
Copy link

codecov bot commented May 25, 2021

Codecov Report

Merging #49 (14859b2) into dev (0076ec8) will increase coverage by 0.38%.
The diff coverage is 69.10%.

@@            Coverage Diff             @@
##              dev      #49      +/-   ##
==========================================
+ Coverage   79.67%   80.05%   +0.38%     
==========================================
  Files          18       18              
  Lines         777      817      +40     
  Branches      115      124       +9     
==========================================
+ Hits          619      654      +35     
- Misses        114      117       +3     
- Partials       44       46       +2     
Flag Coverage Δ
functional-tests 59.73% <49.79%> (+1.17%) ⬆️
unit-tests 78.45% <68.67%> (+0.47%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...eting/mobile/edge/identity/AuthenticatedState.java 100.00% <ø> (ø)
...keting/mobile/edge/identity/IdentityConstants.java 0.00% <0.00%> (ø)
...e/marketing/mobile/edge/identity/IdentityItem.java 60.87% <40.00%> (+0.87%) ⬆️
...obe/marketing/mobile/edge/identity/EventUtils.java 53.57% <42.86%> (+7.74%) ⬆️
...keting/mobile/edge/identity/IdentityExtension.java 72.79% <54.00%> (+0.07%) ⬆️
...om/adobe/marketing/mobile/edge/identity/Utils.java 70.49% <57.14%> (ø)
...eting/mobile/edge/identity/IdentityProperties.java 90.16% <60.00%> (-2.82%) ⬇️
...adobe/marketing/mobile/edge/identity/Identity.java 69.39% <66.10%> (+0.50%) ⬆️
...g/mobile/edge/identity/IdentityStorageService.java 92.00% <90.00%> (ø)
.../marketing/mobile/edge/identity/IdentityState.java 92.75% <91.67%> (+0.11%) ⬆️
... and 8 more

Copy link
Contributor

@emdobrin emdobrin left a comment

Choose a reason for hiding this comment

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

@kevinlind I think the changes look great overall, as I was going through the code I felt it much easier to read and more organized 👍

Comment on lines +17 to +22
format:
(./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessApply)
(./code/gradlew -p code/$(TEST-APP-FOLDER-NAME) spotlessApply)

format-check:
(./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessCheck)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it doesn't hurt to add the check for the test app if we anyway run the hook/format cmd on both.

ij_visual_guides = 120
ij_wrap_on_typing = false

[*.java]
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these mostly custom or default settings? Can we keep only the custom ones for easier maintenance?

Comment on lines +78 to +79
)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

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

this one looks kind of odd for builders but looks good in the Mokito usage for example in testBootupIfReady_whenIdentityDirectRegistered_onFirstBoot_whenIdentityDirectECIDNull_generatesNew

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think there is much I can do here as it's how Prettier is conforming to the Google Java Code Style. The issue is really that the builder takes parameters to the constructor, so there are multiple rules being applied. The rule to close the parenthesis puts it in line with the start of the statement, however chained method calls are indented one indentation size. As you pointed out, chained calls without constructor parameters are lined up correctly.

IdentityConstants.EventType.GENERIC_IDENTITY,
IdentityConstants.EventSource.REQUEST_RESET,
ListenerIdentityRequestReset.class,
listenerErrorCallback
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I actually like this a lot better

" ],\n" +
" \"USERID\": [\n" +
" {\n" +
" \"id\":someUserID,\n" +
Copy link
Contributor

Choose a reason for hiding this comment

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

this should have been the string"someUserID" 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That isn't what it was originally, \"id\":" + "someUserID" + ",\n". If it was supposed to quoted, then the original string should be \"id\":" + "\"someUserID\"" + ",\n".

ij_visual_guides = 120
ij_wrap_on_typing = false

[*.java]
Copy link
Contributor

Choose a reason for hiding this comment

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

Any updates on this one?

@emdobrin
Copy link
Contributor

emdobrin commented Jun 4, 2021

We decided not to include the .editorconfig file for now

@emdobrin emdobrin merged commit 3c9f7c6 into adobe:dev Jun 4, 2021
@kevinlind kevinlind deleted the format-spotless branch June 4, 2021 22:11
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