-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Kotlin: Set up ktfmt in OSS #52064
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
base: main
Are you sure you want to change the base?
Kotlin: Set up ktfmt in OSS #52064
Conversation
@@ -18,6 +18,8 @@ | |||
"featureflags": "yarn --cwd packages/react-native featureflags", | |||
"lint-ci": "./.github/workflow-scripts/analyze_code.sh && yarn shellcheck", | |||
"lint-java": "node ./scripts/lint-java.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW We can nuke this and also remove the script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tackling this separately in #52092
package.json
Outdated
"lint-kotlin-check": "./gradlew :packages:react-native:ReactAndroid:ktfmtCheck", | ||
"lint-kotlin": "./gradlew :packages:react-native:ReactAndroid:ktfmtFormat", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want a top level task inside the build.gradle.kts
file that invokes several other tasks.
So you will invoke ./gradlew ktfmtCheck
and it will format both ReactAndroid and the Gradle plugin, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to the top level build.gradle.kts and configured it to also check other projects other than ReactAndroid
. However, I'm not sure whether my new approach is the correct one and whether there is something else I should include.
Tested mostly with the packages react-native/ReactAndroid
and gradle-plugin
} | ||
} | ||
|
||
// Disable the problematic ktfmt script tasks due to symbolic link issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't disable those, I start getting this when running the check/format tasks:
* What went wrong:
Execution failed for task ':packages:react-native:ReactAndroid:ktfmtCheckScripts'.
> Couldn't follow symbolic link '/Users/mateoguzman/Documents/react-native/packages/react-native/ReactAndroid/hermes-engine/build/hermes/API/hermes/hermes.framework/hermes'.
Summary: Following up from #52064 (comment), this PR removes lint-java and its related files. The codebase is moving entirely to Kotlin and a Kotlin linter is being setup as well, the usage of the Java linter will become unnecessary. ## Changelog: [INTERNAL] - Remove lint-java Pull Request resolved: #52092 Test Plan: Relying on CI here to be green. Reviewed By: cortinico Differential Revision: D76880712 Pulled By: sbuggay fbshipit-source-id: 2736772e7347f435b17d007e0322e1afc2fb2d7b
Summary:
This PR adds the basic
ktfmt
setup in OSS to lint Kotlin files before they're imported into the Meta codebase, making collaboration with external contributors smoother for Android related PRs.I tried to put together certain rules that mimic the current code style and it seems to work well as I get no errors for properly formatted files but this still might need some input to have the correct configuration.
Added two scripts to the main package.json:
yarn lint-kotlin-check
yarn lint-kotlin
Changelog:
[INTERNAL] - Kotlin: Set up ktfmt in OSS
Test Plan:
Unformat any random Kotlin file inside ReactAndroid and then run: