-
Notifications
You must be signed in to change notification settings - Fork 66
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
Update dependency com.pinterest:ktlint to v0.47.1 #827
Conversation
Signed-off-by: zhichao-aws <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #827 +/- ##
=========================================
Coverage 66.93% 66.93%
Complexity 267 267
=========================================
Files 39 39
Lines 1742 1742
Branches 165 165
=========================================
Hits 1166 1166
Misses 453 453
Partials 123 123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Edited/Blocked NotificationRenovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR. You can manually request rebase by checking the rebase/retry box above. ⚠ Warning: custom changes will be lost. |
we may want to have a baseline for existing code and only apply ktlint to changed code in future. But for this time, we can apply with the new code style for all. |
@@ -72,7 +72,7 @@ configurations { | |||
} | |||
|
|||
dependencies { | |||
add("ktlint", "com.pinterest:ktlint:0.44.0") { | |||
add("ktlint", "com.pinterest:ktlint:0.47.1") { |
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.
The latest version is 1.0.1, how about changed to latest version?
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/notifications/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/notifications/backport-2.x
# Create a new branch
git switch --create backport/backport-827-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f26f7dca464d5a51b384be85fbcda7fc8b4b5d79
# Push it to GitHub
git push --set-upstream origin backport/backport-827-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/notifications/backport-2.x Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/notifications/backport-2.11 2.11
# Navigate to the new working tree
pushd ../.worktrees/notifications/backport-2.11
# Create a new branch
git switch --create backport/backport-827-to-2.11
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f26f7dca464d5a51b384be85fbcda7fc8b4b5d79
# Push it to GitHub
git push --set-upstream origin backport/backport-827-to-2.11
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/notifications/backport-2.11 Then, create a pull request where the |
This PR contains the following updates:
0.44.0
->0.47.1
By merging this PR, the issue #826 will be automatically resolved and closed:
Release Notes
pinterest/ktlint (com.pinterest:ktlint)
v0.47.1
Compare Source
Fixed
trailing-comma-on-call-site
,trailing-comma-on-declaration-site
) (#1602)--disabled-rules
(#1599)@file:Suppress
on all toplevel declarations (#1623)Changed
v0.47.0
Compare Source
API Changes & RuleSet providers
If you are not an API consumer nor a RuleSet provider, then you can safely skip this section. Otherwise, please read below carefully and upgrade your usage of ktlint. In this and coming releases, we are changing and adapting important parts of our API in order to increase maintainability and flexibility for future changes. Please avoid skipping a releases as that will make it harder to migrate.
Rule lifecycle hooks / deprecate RunOnRootOnly visitor modifier
Up until ktlint 0.46 the Rule class provided only one life cycle hook. This "visit" hook was called in a depth-first-approach on all nodes in the file. A rule like the IndentationRule used the RunOnRootOnly visitor modifier to call this lifecycle hook for the root node only in combination with an alternative way of traversing the ASTNodes. Downside of this approach was that suppression of the rule on blocks inside a file was not possible (#631). More generically, this applied to all rules, applying alternative traversals of the AST.
The Rule class now offers new life cycle hooks:
Optionally, a rule can stop the traversal of the remainder of the AST whenever the goal of the rule has been achieved. See KDoc on Rule class for more information.
The "visit" life cycle hook will be removed in Ktlint 0.48. In KtLint 0.47 the "visit" life cycle hook will be called only when hook "beforeVisitChildNodes" is not overridden. It is recommended to migrate to the new lifecycle hooks in KtLint 0.47. Please create an issue, in case you need additional assistence to implement the new life cycle hooks in your rules.
Ruleset providing by Custom Rule Set Provider
The KtLint engine needs a more fine-grained control on the instantiation of new Rule instances. Currently, a new instance of a rule can be created only once per file. However, when formatting files the same rule instance is reused for a second processing iteration in case a Lint violation has been autocorrected. By re-using the same rule instance, state of that rule might leak from the first to the second processing iteration.
Providers of custom rule sets have to migrate the custom rule set JAR file. The current RuleSetProvider interface which is implemented in the custom rule set is deprecated and marked for removal in KtLint 0.48. Custom rule sets using the old RuleSetProvider interface will not be run in KtLint 0.48 or above.
For now, it is advised to implement the new RuleSetProviderV2 interface without removing the old RuleSetProvider interface. In this way, KtLint 0.47 and above use the RuleSetProviderV2 interface and ignore the old RuleSetProvider interface completely. KtLint 0.46 and below only use the old RuleSetProvider interface.
Adding the new interface is straight forward, as can be seen below:
Also note that file 'resource/META-INF/services/com.pinterest.ktlint.core.RuleSetProviderV2' needs to be added. In case your custom rule set provider implements both RuleSetProvider and RuleSetProviderV2, the resource directory contains files for both implementation. The content of those files is identical as the interfaces are implemented on the same class.
Once above has been implemented, rules no longer have to clean up their internal state as the KtLint rule engine can request a new instance of the Rule at any time it suspects that the internal state of the Rule is tampered with (e.g. as soon as the Rule instance is used for traversing the AST).
Rule set providing by API Consumer
The KtLint engine needs a more fine-grained control on the instantiation of new Rule instances. Currently, a new instance of a rule can be created only once per file. However, when formatting files the same rule instance is reused for a second processing iteration in case a Lint violation has been autocorrected. By re-using the same rule instance, state of that rule might leak from the first to the second processing iteration.
The ExperimentalParams parameter which is used to invoke "KtLint.lint" and "KtLint.format" contains a new parameter "ruleProviders" which will replace the "ruleSets" parameter in KtLint 0.48. Exactly one of those parameters should be a non-empty set. It is preferred that API consumers migrate to using "ruleProviders".
Once above has been implemented, rules no longer have to clean up their internal state as the KtLint rule engine can request a new instance of the Rule at any time it suspects that the internal state of the Rule is tampered with (e.g. as soon as the Rule instance is used for traversing the AST).
Format callback
The callback function provided as parameter to the format function is now called for all errors regardless whether the error has been autocorrected. Existing consumers of the format function should now explicitly check the
autocorrected
flag in the callback result and handle it appropriately (in most case this will be ignoring the callback results for whichautocorrected
has valuetrue
).CurrentBaseline
Class
com.pinterest.ktlint.core.internal.CurrentBaseline
has been replaced withcom.pinterest.ktlint.core.api.Baseline
.Noteworthy changes:
baselineRules
(nullable) is replaced with `lintErrorsPerFile (non-nullable).baselineGenerationNeeded
(boolean) is replaced withstatus
(typeBaseline.Status
).The utility functions provided via
com.pinterest.ktlint.core.internal.CurrentBaseline
are moved to the new class. One new methodList<LintError>.doesNotContain(lintError: LintError)
is added..editorconfig property "disabled_rules"
The
.editorconfig
propertydisabled_rules
(api propertyDefaultEditorConfigProperties.disabledRulesProperty
) has been deprecated and will be removed in a future version. Usektlint_disabled_rules
(api propertyDefaultEditorConfigProperties.ktlintDisabledRulesProperty
) instead as it more clearly identifies that ktlint is the owner of the property. This property is to be renamed in.editorconfig
files andExperimentalParams.editorConfigOverride
.Although, Ktlint 0.47.0 falls back on property
disabled_rules
wheneverktlint_disabled_rules
is not found, this result in a warning message being printed.Default/alternative .editorconfig
Parameter "ExperimentalParams.editorConfigPath" is deprecated in favor of the new parameter "ExperimentalParams.editorConfigDefaults". When used in the old implementation this resulted in ignoring all ".editorconfig" files on the path to the file. The new implementation uses properties from the "editorConfigDefaults"parameter only when no ".editorconfig" files on the path to the file supplies this property for the filepath.
API consumers can easily create the EditConfigDefaults by calling
"EditConfigDefaults.load(path)" or creating it programmatically.
Reload of
.editorconfig
fileSome API Consumers keep a long-running instance of the KtLint engine alive. In case an
.editorconfig
file is changed, which was already loaded into the internal cache of the KtLint engine this change would not be taken into account by KtLint. One way to deal with this, was to clear the entire KtLint cache after each change in an.editorconfig
file.Now, the API consumer can reload an
.editorconfig
. If the.editorconfig
with given path is actually found in the cached, it will be replaced with the new value directly. If the file is not yet loaded in the cache, loading will be deferred until the file is actually requested again.Example:
Miscellaneous
Several methods for which it is unlikely that they are used by API consumers have been marked for removal from the public API in KtLint 0.48.0. Please create an issue in case you have a valid business case to keep such methods in the public API.
Added
format
reporter. This reporter prints a one-line-summary of the formatting status per file. (#621).Fixed
filename
(#1521).indent
) #631enum-entry-name-case
,filename
) (#1530).ktlint
cli on default kotlin extensions only when an (existing) path to a directory is given. (#917).format
function for all errors including errors that are autocorrected (#1491)function-signature
(#1527)multiline-if-else
(#1560)multiline-if-else
(#828)ktlint_code_style
(#1559)trailing-comma
(#1542)trailing-comma
intotrailing-comma-on-call-site
andtrailing-comma-on-declaration-site
(#1555)wrapping
(#1578)Changed
format
function for all errors including errors that are autocorrected (#1491)annotation
(#1574).editorconfig
propertydisabled_rules
toktlint_disabled_rules
(#701)1.7.20-beta
and Kotlin version to1.7.10
.7.5.1
versionRemoved
v0.46.1
Compare Source
Minor release to address some regressions introduced in 0.46.0
Fixed
-Xuse-k2
as it forces API Consumers to compile their projects with this same flag (#1506).indent
(#1510)v0.46.0
Compare Source
Promoting experimental rules to standard
The rules below are promoted from the
experimental
ruleset to thestandard
ruleset.annotation
annotation-spacing
argument-list-wrapping
double-colon-spacing
enum-entry-name-case
multiline-if-else
no-empty-first-line-in-method-block
package-name
trailing-comma
spacing-around-angle-brackets
spacing-between-declarations-with-annotations
spacing-between-declarations-with-comments
unary-op-spacing
Note that as a result of moving the rules that the prefix
experimental:
has to be removed from all references to this rule. Check references in:.editorconfig
settingdisabled_rules
.VisitorModifier.RunAfterRule
.If your project did not run with the
experimental
ruleset enabled before, you might expect new lint violations to be reported. Please note that rules can be disabled via the the.editorconfig
in case you do not want the rules to be applied on your project.API Changes & RuleSet providers
If you are not an API user nor a RuleSet provider, then you can safely skip this section. Otherwise, please read below carefully and upgrade your usage of ktlint. In this and coming releases, we are changing and adapting important parts of our API in order to increase maintainability and flexibility for future changes. Please avoid skipping a releases as that will make it harder to migrate.
Lint and formatting functions
The lint and formatting changes no longer accept parameters of type
Params
but onlyExperimentalParams
. Also, the VisitorProvider parameter has been removed. Because of this, your integration with KtLint breaks. Based on feedback with ktlint 0.45.x, we now prefer to break at compile time instead of trying to keep the interface backwards compatible. Please raise an issue, in case you help to convert to the new API.Use of ".editorconfig" properties & userData
The interface
UsesEditorConfigProperties
provides methodgetEditorConfigValue
to retrieve a named.editorconfig
property for a given ASTNode. When implementing this interface, the valueeditorConfigProperties
needs to be overridden. Previously it was not checked whether a retrieved property was actually recorded in this list. Now, retrieval of unregistered properties results in an exception.Property
Ktlint.DISABLED
has been removed. The property value can now be retrieved as follows:and be supplied via the
ExperimentalParams
as follows:Property
Ktlint.ANDROID_USER_DATA_KEY
has been removed. The property value can now be retrieved as follows:astNode .getEditorConfigValue(DefaultEditorConfigProperties.codeStyleProperty)
and be supplied via the
ExperimentalParams
as follows:This property defaults to the
official
Kotlin code style when not set.Testing KtLint rules
An AssertJ style API for testing KtLint rules (#1444) has been added. Usage of this API is encouraged in favor of using the old RuleExtension API. For more information, see KtLintAssertThat API
Added
spacing-between-function-name-and-opening-parenthesis
) (#1341)parameter-list-spacing
) (#1341)function-return-type-spacing
) (#1341)nullable-type-spacing
) (#1341)type-parameter-list-spacing
) (#1435)function-start-of-body-spacing
) (#1341)@Suppress
(more information) (#765)function-signature
) (#1341)Fixed
no-consecutive-blank-lines
to new rule (no-blank-lines-in-chained-method-calls
) (#1248)wrapping
(#1457)indent
(#1340)indent
) and a newline in the expression in a for-statement should not force to wrap itwrapping
(#1350)indent
(#1335).editorconfig
settingindentSize
is set to valuetab
then return the default tab width as value forindentSize
(#1485)@file:Suppress(...)
(#1029)Changed
1.7.0
and Kotlin version to1.7.0
.7.1.2
release4.6.3
releasefilename
(#1004)annotation
,annotation-spacing
,argument-list-wrapping
,double-colon-spacing
,enum-entry-name-case
,multiline-if-else
,no-empty-first-line-in-method-block
,package-name
,traling-comma
,spacing-around-angle-brackets
,spacing-between-declarations-with-annotations
,spacing-between-declarations-with-comments
,unary-op-spacing
(#1481)--android
can be omitted when the.editorconfig
propertyktlint_code_style = android
is definedv0.45.2
Compare Source
Fixed
Changed
1.6.20
and Kotlin version to1.6.20
.v0.45.1
Compare Source
Minor release to fix a breaking issue with
ktlint
API consumersFixed
v0.45.0
Compare Source
API Changes & RuleSet providers
If you are not an API user nor a RuleSet provider, then you can safely skip this section. Otherwise, please read below carefully and upgrade your usage of ktlint. In this and coming releases, we are changing and adapting important parts of our API in order to increase maintainability and flexibility for future changes. Please avoid skipping a releases as that will make it harder to migrate.
Retrieving ".editorconfig" property value
This section is applicable when providing rules that depend on one or more values of ".editorconfig" properties. Property values should no longer be retrieved via EditConfig or directly via
userData[EDITOR_CONFIG_USER_DATA_KEY]
. Property values should now only be retrieved using methodASTNode.getEditorConfigValue(editorConfigProperty)
of interfaceUsesEditorConfigProperties
which is provided in this release. Starting from next release after the current release, the EditConfig and/oruserData[EDITOR_CONFIG_USER_DATA_KEY]
may be removed without further notice which will break your API or rule. To prevent disruption of your end user, you should migrate a.s.a.p.Added
function-type-reference-spacing
) (#1341)type-parameter-list-spacing
) (#1366)discouraged-comment-location
) (#1365)fun-keyword-spacing
) (#1362)experimental:block-comment-initial-star-alignment
(#297).editorconfig
propertyij_kotlin_packages_to_use_import_on_demand
(no-wildcard-imports
) (#1272)comment-wrapping
) (#1403)kdoc-wrapping
) (#1403)type-parameter-list-spacing
) (#1366)Fixed
no-multi-spaces
) (#1394)indent
) (#1375)no-unused-imports
) (#1277), (#1393), (#1256)Changed
indent
rule to the new rulewrapping
(as part of thestandard
ruleset). In case you currently have disabled theindent
rule, you may want to reconsider whether this is still necessary or that you also want to disable the newwrapping
rule to keep the status quo. Both rules can be run independent of each other. (#835)