diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/MaxLineLengthRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/MaxLineLengthRule.kt index efd02da045..1b30cef1c2 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/MaxLineLengthRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/MaxLineLengthRule.kt @@ -4,6 +4,8 @@ import com.github.shyiko.ktlint.core.KtLint import com.github.shyiko.ktlint.core.Rule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiComment +import org.jetbrains.kotlin.psi.KtImportDirective +import org.jetbrains.kotlin.psi.KtPackageDirective import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes @@ -28,7 +30,9 @@ class MaxLineLengthRule : Rule("max-line-length") { if (line.length > maxLineLength) { val el = node.psi.findElementAt(offset + line.length - 1)!! if (!el.isPartOf(PsiComment::class)) { - emit(offset, "Exceeded max line length ($maxLineLength)", false) + if (!el.isPartOf(KtPackageDirective::class) && !el.isPartOf(KtImportDirective::class)) { + emit(offset, "Exceeded max line length ($maxLineLength)", false) + } } else { // if comment is the only thing on the line - fine, otherwise emit an error val prevLeaf = el.getPrevSiblingIgnoringWhitespaceAndComments(false) diff --git a/ktlint-ruleset-standard/src/test/resources/spec/max-line-length/lint.kt.spec b/ktlint-ruleset-standard/src/test/resources/spec/max-line-length/lint.kt.spec index aa5fa28d71..c55b6970ef 100644 --- a/ktlint-ruleset-standard/src/test/resources/spec/max-line-length/lint.kt.spec +++ b/ktlint-ruleset-standard/src/test/resources/spec/max-line-length/lint.kt.spec @@ -1,3 +1,5 @@ +package com.omg.sooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.long +import com.omg.soooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.long // http://______________________________________________________________________. fun main() { // comment padded with spaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaace @@ -6,5 +8,5 @@ fun main() { } // expect -// 4:1:Exceeded max line length (80) -// 5:1:Exceeded max line length (80) +// 6:1:Exceeded max line length (80) +// 7:1:Exceeded max line length (80)