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

Run rules during unit tests in correct order #1460

Conversation

paul-dingemans
Copy link
Collaborator

Description

With KtLintAssertThat an AssertJ style assertThat is created for a specific rule. In addition to that rule, it is possible to run additional rules. In case the rule which is to be tested has defined a VisitorModifier which requires one or more additional rules to be loaded and to be enabled, it is even mandatory that those rules are added to the unit test.

The goal is to execute the rules during unit tests in the same order as when running the CLI version of KtLint. During each unit test a dynamic RuleSet is being created for a limited set of rules (e.g. the rule for which the assertThat is created plus the additional rules specified in the unit tests). The rules in this minimized ruleSet are executed in the order as defined by the VisitorModifier as defined in the rules.

  • Split naming policy of rule id and rule set id. The naming policy of the latter is not changed. The naming policy of the ruleId is changed so that the ruleSetId prefix can be specified optionally. If the ruleId is not prefixed with a ruleSetId then it is assumed to be equal to "standard". For all experimental rules, the ruleSetId has been added.
  • Remove obsolete parameter "isUnitTestContext" from VisitorProvider
  • As the VisitorModifiers are now also used and checked during unit tests, it is required to run the additional rules during the lint phase as well. Some code examples in tests in which the IndentationRule is added as additional rule are changed to comply with that rule.

Checklist

  • PR description added
  • tests are added
  • CHANGELOG.md is updated

In case of adding a new rule:

  • README.md is updated
  • Rule has been applied on Ktlint itself and violations are fixed

= and others added 8 commits May 5, 2022 18:55
…specific rule. In addition to that rule, it is possible to run additional rules. In case the rule which is to be tested has defined a VisitorModifier which requires one or more additional rules to be loaded and to be enabled, it is even mandatory that those rules are added to the unit test.

The goal is to execute the rules during unit tests in the same order as when running the CLI version of KtLint. During each unit test a dynamic RuleSet is being created for a limited set of rules (e.g. the rule for which the `assertThat` is created plus the additional rules specified in the unit tests). The rules in this minimized ruleSet are executed in the order as defined by the VisitorModifier as defined in the rules.

* Split naming policy of rule id and rule set id. The naming policy of the latter is not changed. The naming policy of the ruleId is changed so that the ruleSetId prefix can be specified optionally. If the ruleId is not prefixed with a ruleSetId then it is assumed to be equal to "standard". For all experimental rules, the ruleSetId has been added.
* Remove obsolete parameter "isUnitTestContext" from VisitorProvider
* As the VisitorModifiers are now also used and checked during unit tests, it is required to run the additional rules during the lint phase as well. Some code examples in tests in which the IndentationRule is added as additional rule are changed to comply with that rule.
* Run CI on java 17

* Run tests on all LTS JDKs

* Cleanup

* Increase jvm heap size

* Remove PR limit & Correct upload actions
* Bump Kotlin dev version to 1.7.0-Beta

* Remove dup `Removed` in changelog
…lines (pinterest#1457)

* Wrapping rule should not prevent comments for interfaces on separate lines

Closes pinterest#1457

Co-authored-by: paul-dingemans
Includes:
* removal of extra apiVersion as it by default is in sync with the kotlin version.
* Kotlin 1.6.21, follow up pinterest#1455
* Enable gradle-enterprise
This rule rewrites the function signature to a single line when possible (e.g. when not exceeding the "max_line_length" property) or a multiline signature otherwise. In case of function with a body expression, the body expression is placed on the same line as the function signature when not exceeding the "max_line_length" property. 

Optionally the function signature can be forced to be written as a multiline signature in case the function has more than a specified number of parameters (".editorconfig" property "ktlint_function_signature_wrapping_rule_always_with_minimum_parameters")
…o ktlintAssertThat-rule-order

# Conflicts:
#	ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt
@paul-dingemans
Copy link
Collaborator Author

Closed as due to incorrect merge with master the squashed commit would contain too much changes. Replaced with PR #1470

@paul-dingemans paul-dingemans deleted the ktlintAssertThat-rule-order branch July 7, 2022 18:28
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.

3 participants