Skip to content

Commit

Permalink
Fixes #620 by adding arguments to ParameterListWrappingRule. (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamMc331 authored Aug 5, 2020
1 parent f697547 commit a94b43f
Show file tree
Hide file tree
Showing 15 changed files with 450 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Experimental SpacingAroundAngleBracketsRule ([#769](https://github.com/pinterest/ktlint/pull/769))
- Checksum generation for executable Jar ([#695](https://github.com/pinterest/ktlint/issues/695))
- Enable Gradle dependency verification
- `parameter-list-wrapping` rule now also considers function arguments while wrapping ([#620](https://github.com/pinterest/ktlint/issues/620))

### Fixed
- Safe-called wrapped trailing lambdas indented correctly ([#776](https://github.com/pinterest/ktlint/issues/776))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ object KtLint {
compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
val project = KotlinCoreEnvironment.createForProduction(
Disposable {},
compilerConfiguration, EnvironmentConfigFiles.JVM_CONFIG_FILES
compilerConfiguration,
EnvironmentConfigFiles.JVM_CONFIG_FILES
).project
// everything below (up to PsiFileFactory.getInstance(...)) is to get AST mutations (`ktlint -F ...`) working
// otherwise it's not needed
Expand All @@ -113,7 +114,8 @@ object KtLint {
// (check constructor signature and compare it to the source)
// (org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.3)
val constructor = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(
aspect, Any::class.java.getDeclaredConstructor(*arrayOfNulls<Class<*>>(0))
aspect,
Any::class.java.getDeclaredConstructor(*arrayOfNulls<Class<*>>(0))
)
return constructor.newInstance(*emptyArray()) as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ class CheckStyleReporterTest {
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"<\"&'>"
),
false
)
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
2, 1, "rule-2",
2,
1,
"rule-2",
"And if you see my friend"
),
true
Expand All @@ -32,15 +36,19 @@ class CheckStyleReporterTest {
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
1, 10, "rule-1",
1,
10,
"rule-1",
"I thought I would again"
),
false
)
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
2, 20, "rule-2",
2,
20,
"rule-2",
"A single thin straight line"
),
false
Expand All @@ -49,14 +57,16 @@ class CheckStyleReporterTest {
reporter.onLintError(
"/all-corrected.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"I thought we had more time"
),
true
)
reporter.afterAll()
assertThat(String(out.toByteArray())).isEqualTo(
"""
"""
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="8.0">
<file name="/one-fixed-and-one-not.kt">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ class JsonReporterTest {
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"<\"&'>"
),
false
)
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
2, 1, "rule-2",
2,
1,
"rule-2",
"And if you see my friend"
),
true
Expand All @@ -32,15 +36,19 @@ class JsonReporterTest {
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
1, 10, "rule-1",
1,
10,
"rule-1",
"I thought I would again"
),
false
)
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
2, 20, "rule-2",
2,
20,
"rule-2",
"A single thin straight line"
),
false
Expand All @@ -49,7 +57,9 @@ class JsonReporterTest {
reporter.onLintError(
"/all-corrected.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"I thought we had more time"
),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ class PlainReporterTest {
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"<\"&'>"
),
false
)
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
2, 1, "rule-2",
2,
1,
"rule-2",
"And if you see my friend"
),
true
Expand All @@ -36,15 +40,19 @@ class PlainReporterTest {
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
1, 10, "rule-1",
1,
10,
"rule-1",
"I thought I would again"
),
false
)
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
2, 20, "rule-2",
2,
20,
"rule-2",
"A single thin straight line"
),
false
Expand All @@ -53,7 +61,9 @@ class PlainReporterTest {
reporter.onLintError(
"/all-corrected.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"I thought we had more time"
),
true
Expand All @@ -79,7 +89,9 @@ class PlainReporterTest {
reporter.onLintError(
File.separator + "one-fixed-and-one-not.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"<\"&'>"
),
false
Expand Down Expand Up @@ -107,15 +119,19 @@ class PlainReporterTest {
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"<\"&'>"
),
false
)
reporter.onLintError(
"/one-fixed-and-one-not.kt",
LintError(
2, 1, "rule-2",
2,
1,
"rule-2",
"And if you see my friend"
),
true
Expand All @@ -124,15 +140,19 @@ class PlainReporterTest {
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
1, 10, "rule-1",
1,
10,
"rule-1",
"I thought I would again"
),
false
)
reporter.onLintError(
"/two-not-fixed.kt",
LintError(
2, 20, "rule-2",
2,
20,
"rule-2",
"A single thin straight line"
),
false
Expand All @@ -141,7 +161,9 @@ class PlainReporterTest {
reporter.onLintError(
"/all-corrected.kt",
LintError(
1, 1, "rule-1",
1,
1,
"rule-1",
"I thought we had more time"
),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class EnumEntryNameCaseRule : Rule("enum-entry-name-case") {
if (!name.startsWithUpperCase()) {
emit(
node.startOffset,
ERROR_MESSAGE, false
ERROR_MESSAGE,
false
)

if (autoCorrect) correct(enumEntry, name)
Expand All @@ -37,7 +38,8 @@ class EnumEntryNameCaseRule : Rule("enum-entry-name-case") {
else if (name.contains("_") && name.containsLowerCase()) {
emit(
node.startOffset,
ERROR_MESSAGE, false
ERROR_MESSAGE,
false
)

if (autoCorrect) correct(enumEntry, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class NoEmptyFirstLineInMethodBlockRule : Rule("no-empty-first-line-in-method-bl
if (split.size > 2) {
emit(
node.startOffset + 1,
"First line in a method block should not be empty", true
"First line in a method block should not be empty",
true
)
if (autoCorrect) {
(node as LeafPsiElement).rawReplaceWithText("${split.first()}\n${split.last()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SpacingBetweenDeclarationsWithAnnotationsRule : Rule("spacing-between-decl
if (node.psi.parent.prevSibling is PsiWhiteSpace && node.psi.parent.prevSibling.text == "\n") {
emit(
node.startOffset,
"Declarations and declarations with annotations should have an empty space between.", true
"Declarations and declarations with annotations should have an empty space between.",
true
)
if (autoCorrect) {
(node.psi.parent.prevSibling.node as LeafPsiElement).rawReplaceWithText("\n\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class SpacingBetweenDeclarationsWithCommentsRule : Rule("spacing-between-declara
if (node.parent.prevSibling is PsiWhiteSpace && node.parent.prevSibling.text == "\n") {
emit(
node.startOffset,
"Declarations and declarations with comments should have an empty space between.", true
"Declarations and declarations with comments should have an empty space between.",
true
)
if (autoCorrect) {
(node.parent.prevSibling.node as LeafPsiElement).rawReplaceWithText("\n\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class AnnotationRuleTest {
)
).containsExactly(
LintError(
2, 5, "annotation",
2,
5,
"annotation",
AnnotationRule.multipleAnnotationsOnSameLineAsAnnotatedConstructErrorMessage
)
)
Expand Down Expand Up @@ -184,7 +186,10 @@ class AnnotationRuleTest {
)
).containsExactly(
LintError(
2, 28, "annotation", "Missing spacing after @SomeAnnotation(\"value\")"
2,
28,
"annotation",
"Missing spacing after @SomeAnnotation(\"value\")"
)
)
}
Expand All @@ -204,7 +209,9 @@ class AnnotationRuleTest {
)
).containsExactly(
LintError(
2, 5, "annotation",
2,
5,
"annotation",
AnnotationRule.annotationsWithParametersAreNotOnSeparateLinesErrorMessage
)
)
Expand Down Expand Up @@ -250,11 +257,15 @@ class AnnotationRuleTest {
)
).containsExactly(
LintError(
1, 1, "annotation",
1,
1,
"annotation",
AnnotationRule.multipleAnnotationsOnSameLineAsAnnotatedConstructErrorMessage
),
LintError(
1, 1, "annotation",
1,
1,
"annotation",
AnnotationRule.annotationsWithParametersAreNotOnSeparateLinesErrorMessage
)
)
Expand Down Expand Up @@ -328,11 +339,15 @@ class AnnotationRuleTest {
)
).containsExactly(
LintError(
2, 5, "annotation",
2,
5,
"annotation",
AnnotationRule.multipleAnnotationsOnSameLineAsAnnotatedConstructErrorMessage
),
LintError(
2, 5, "annotation",
2,
5,
"annotation",
AnnotationRule.annotationsWithParametersAreNotOnSeparateLinesErrorMessage
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class NoBlankLineBeforeRbraceRule : Rule("no-blank-line-before-rbrace") {
if (split.size > 2) {
emit(
node.startOffset + split[0].length + split[1].length + 1,
"Unexpected blank line(s) before \"}\"", true
"Unexpected blank line(s) before \"}\"",
true
)
if (autoCorrect) {
(node as LeafPsiElement).rawReplaceWithText("${split.first()}\n${split.last()}")
Expand Down
Loading

0 comments on commit a94b43f

Please sign in to comment.