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

Move wrapping logic from IndentationRule to new WrappingRule #1399

Merged

Conversation

paul-dingemans
Copy link
Collaborator

Description

Wrapping logic belong in an own rule, so it can be disabled without disabling the indentation logic.

The WrappingRule contains a simplified indentation logic. Whenever a linebreak is inserted, it determines the indentation based on the current indentation of the parent node regardless whether this node is indented correctly. It is the responsibility of the IndentationRule, which runs later than the WrappingRule to fix the indentations.

Spec files used in the unit tests have been split. Some parts are moved to new spec files specific for the WrappingRule. Other parts are moved to real unit tests. And on some spec files, both the wrapping and indentation rules are run together. Those files need further refactoring.

The RuleExtension now also allows the diffFileLint and diffFileFormat to run on a list of rules. Spec files which are used for linting with multiple rules must specify the rule-id in the expectations. The rule-id now optionally can also be specified in those expectation when the file is checked by only one rule. However, in case the detail property of the LintError contains a ":" then the rule-id must be specified as it is used as delimiter.

Closes #835

NOTE: This change is nearly impossible to review. The change is big, complex and not always straightforward. I could not find a way to make the changes smaller. Best way to test it, is running the changed code on top of multiple projects which already have been formatted with the current version of ktlint. This should not result in changes in the code.

Checklist

  • tests are added
  • CHANGELOG.md is updated

Wrapping logic belong in an own rule, so it can be disabled without
disabling the indentation logic.

The WrappingRule contains a simplified indentation logic. Whenever
a linebreak is inserted, it determines the indentation based on the
current indentation of the parent node regardless whether this node
is indented correctly. It is the responsibility of the
IndentationRule, which runs later than the WrappingRule to fix the
indentations.

Spec files used in the unit tests have been split. Some parts are
moved to new spec files specific for the WrappingRule. Other
parts are moved to real unit tests. And on some spec files,
both the wrapping and indentation rules are run together. Those
files need further refactoring.

The RuleExtension now also allows the diffFileLint and
diffFileFormat to run on a list of rules. Spec files which are
used for linting with multiple rules must specify the rule-id
in the expectations. The rule-id now optionally can also be
specified in those expectation when the file is checked by
only one rule. However, in case the detail property of the
LintError contains a ":" then the rule-id *must* be specified
as it is used as delimiter.

Closes pinterest#835
@paul-dingemans paul-dingemans merged commit c4ac48b into pinterest:master Mar 8, 2022
@paul-dingemans paul-dingemans deleted the 835-split-indent-wrapping branch March 8, 2022 16:54
@paul-dingemans paul-dingemans added this to the 0.45.0 milestone Mar 8, 2022
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.

Indentation-rule do code wrapping instead of just indentation
1 participant