Skip to content

Commit

Permalink
Merge pull request #366 from gabrielittner/import-order-experimental
Browse files Browse the repository at this point in the history
 move ImportOrderingRule to experimental ruleset
  • Loading branch information
NightlyNexus authored Apr 3, 2019
2 parents 3bfc666 + cc117a1 commit 2cecdde
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.shyiko.ktlint.core

import com.github.shyiko.ktlint.core.ast.prevLeaf
import java.util.ArrayList
import java.util.HashSet
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
Expand All @@ -9,6 +11,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.mock.MockProject
import org.jetbrains.kotlin.com.intellij.openapi.Disposable
import org.jetbrains.kotlin.com.intellij.openapi.diagnostic.DefaultLogger
import org.jetbrains.kotlin.com.intellij.openapi.diagnostic.Logger as DiagnosticLogger
import org.jetbrains.kotlin.com.intellij.openapi.extensions.ExtensionPoint
import org.jetbrains.kotlin.com.intellij.openapi.extensions.Extensions.getArea
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
Expand All @@ -28,9 +31,6 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.KtFile
import sun.reflect.ReflectionFactory
import java.util.ArrayList
import java.util.HashSet
import org.jetbrains.kotlin.com.intellij.openapi.diagnostic.Logger as DiagnosticLogger

object KtLint {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.github.shyiko.ktlint.core.ast

import com.github.shyiko.ktlint.core.ast.ElementType.WHITE_SPACE
import com.github.shyiko.ktlint.core.ast.ElementType.STRING_TEMPLATE
import com.github.shyiko.ktlint.core.ast.ElementType.WHITE_SPACE
import kotlin.reflect.KClass
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiComment
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
import kotlin.reflect.KClass

fun ASTNode.nextLeaf(includeEmpty: Boolean = false, skipSubtree: Boolean = false): ASTNode? {
var n = if (skipSubtree) this.lastChildLeafOrSelf().nextLeafAny() else this.nextLeafAny()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.github.shyiko.ktlint.core

import com.github.shyiko.ktlint.core.ast.ElementType
import com.github.shyiko.ktlint.core.ast.isPartOf
import java.util.ArrayList
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
import org.testng.annotations.Test
import java.util.ArrayList

class ErrorSuppressionTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.shyiko.ktlint.reporter.checkstyle

import com.github.shyiko.ktlint.core.LintError
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test

class CheckStyleReporterTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.shyiko.ktlint.reporter.json

import com.github.shyiko.ktlint.core.LintError
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test

class JsonReporterTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.shyiko.ktlint.reporter.plain

import com.github.shyiko.ktlint.core.LintError
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test

class PlainReporterTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ExperimentalRuleSetProvider : RuleSetProvider {

override fun get(): RuleSet = RuleSet(
"experimental",
ImportOrderingRule(),
IndentationRule()
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.shyiko.ktlint.ruleset.standard
package com.github.shyiko.ktlint.ruleset.experimental

import com.github.shyiko.ktlint.core.Rule
import com.github.shyiko.ktlint.core.ast.ElementType.IMPORT_DIRECTIVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ import com.github.shyiko.ktlint.core.ast.prevSibling
import com.github.shyiko.ktlint.core.ast.upsertWhitespaceAfterMe
import com.github.shyiko.ktlint.core.ast.upsertWhitespaceBeforeMe
import com.github.shyiko.ktlint.core.ast.visit
import java.lang.StringBuilder
import java.util.Deque
import java.util.LinkedList
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiComment
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
import org.jetbrains.kotlin.psi.KtSuperTypeList
import java.lang.StringBuilder
import java.util.Deque
import java.util.LinkedList

/**
* ktlint's rule that checks & corrects indentation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.shyiko.ktlint.ruleset.standard
package com.github.shyiko.ktlint.ruleset.experimental

import com.github.shyiko.ktlint.core.LintError
import com.github.shyiko.ktlint.test.diffFileFormat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.shyiko.ktlint.ruleset.experimental

import com.github.shyiko.ktlint.core.LintError
import com.github.shyiko.ktlint.test.format
import com.github.shyiko.ktlint.test.diffFileFormat
import com.github.shyiko.ktlint.test.lint
import com.github.shyiko.ktlint.test.diffFileLint
import com.github.shyiko.ktlint.test.format
import com.github.shyiko.ktlint.test.lint
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import com.github.shyiko.ktlint.core.ast.ElementType.SHEBANG_COMMENT
import com.github.shyiko.ktlint.core.ast.ElementType.TYPEALIAS
import com.github.shyiko.ktlint.core.ast.ElementType.WHITE_SPACE
import com.github.shyiko.ktlint.core.ast.prevCodeSibling
import java.nio.file.Paths
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
import java.nio.file.Paths

/**
* If there is only one top level class/object/typealias in a given file, then its name should match the file's name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import com.github.shyiko.ktlint.core.ast.ElementType.SEALED_KEYWORD
import com.github.shyiko.ktlint.core.ast.ElementType.SUSPEND_KEYWORD
import com.github.shyiko.ktlint.core.ast.ElementType.TAILREC_KEYWORD
import com.github.shyiko.ktlint.core.ast.ElementType.VARARG_KEYWORD
import java.util.Arrays
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtDeclarationModifierList
import java.util.Arrays

class ModifierOrderRule : Rule("modifier-order") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class StandardRuleSetProvider : RuleSetProvider {
// disabled until auto-correct is working properly
// (e.g. try formatting "if (true)\n return { _ ->\n _\n}")
// MultiLineIfElseRule(),
// disabled until it's clear how to reconcile difference in Intellij & Android Studio import layout
// ImportOrderingRule(),
IndentationRule(),
MaxLineLengthRule(),
ModifierOrderRule(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.github.shyiko.ktlint.test.format
import com.github.shyiko.ktlint.test.lint
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat

import org.testng.annotations.Test

class MultiLineIfElseRuleTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.github.shyiko.ktlint.ruleset.standard

import com.github.shyiko.ktlint.core.LintError
import com.github.shyiko.ktlint.test.lint
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
import java.net.URI
import java.nio.file.Paths
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test

/**
* @author yokotaso <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import com.github.shyiko.ktlint.core.ast.isRoot
import com.github.shyiko.ktlint.core.ast.lastChildLeafOrSelf
import com.github.shyiko.ktlint.test.internal.Color
import com.github.shyiko.ktlint.test.internal.color
import java.io.PrintStream
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.lexer.KtTokens
import java.io.PrintStream

val debugAST = {
(System.getProperty("ktlintDebug") ?: System.getenv("KTLINT_DEBUG") ?: "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.github.shyiko.ktlint.core.KtLint
import com.github.shyiko.ktlint.core.LintError
import com.github.shyiko.ktlint.core.Rule
import com.github.shyiko.ktlint.core.RuleSet
import java.util.ArrayList
import org.assertj.core.util.diff.DiffUtils.diff
import org.assertj.core.util.diff.DiffUtils.generateUnifiedDiff
import java.util.ArrayList

fun Rule.lint(text: String, userData: Map<String, String> = emptyMap(), script: Boolean = false): List<LintError> {
val res = ArrayList<LintError>()
Expand Down
22 changes: 11 additions & 11 deletions ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ import com.github.shyiko.ktlint.internal.EditorConfig
import com.github.shyiko.ktlint.internal.IntellijIDEAIntegration
import com.github.shyiko.ktlint.internal.MavenDependencyResolver
import com.github.shyiko.ktlint.test.DumpAST
import org.eclipse.aether.RepositoryException
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.repository.RemoteRepository
import org.eclipse.aether.repository.RepositoryPolicy
import org.eclipse.aether.repository.RepositoryPolicy.CHECKSUM_POLICY_IGNORE
import org.eclipse.aether.repository.RepositoryPolicy.UPDATE_POLICY_NEVER
import org.jetbrains.kotlin.backend.common.onlyIf
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import picocli.CommandLine.Parameters
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileNotFoundException
Expand Down Expand Up @@ -51,6 +40,17 @@ import java.util.concurrent.atomic.AtomicInteger
import java.util.jar.Manifest
import kotlin.concurrent.thread
import kotlin.system.exitProcess
import org.eclipse.aether.RepositoryException
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.repository.RemoteRepository
import org.eclipse.aether.repository.RepositoryPolicy
import org.eclipse.aether.repository.RepositoryPolicy.CHECKSUM_POLICY_IGNORE
import org.eclipse.aether.repository.RepositoryPolicy.UPDATE_POLICY_NEVER
import org.jetbrains.kotlin.backend.common.onlyIf
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import picocli.CommandLine.Parameters

@Command(
headerHeading = """An anti-bikeshedding Kotlin linter with built-in formatter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.shyiko.ktlint.internal

import com.github.shyiko.klob.Glob
import org.w3c.dom.Element
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
Expand All @@ -17,6 +16,7 @@ import javax.xml.transform.dom.DOMSource
import javax.xml.transform.stream.StreamResult
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory
import org.w3c.dom.Element

object IntellijIDEAIntegration {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.shyiko.ktlint.internal

import java.io.File
import org.apache.maven.repository.internal.MavenRepositorySystemUtils
import org.eclipse.aether.DefaultRepositorySystemSession
import org.eclipse.aether.RepositorySystem
Expand All @@ -20,7 +21,6 @@ import org.eclipse.aether.transfer.TransferListener
import org.eclipse.aether.transport.file.FileTransporterFactory
import org.eclipse.aether.transport.http.HttpTransporterFactory
import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator
import java.io.File

class MavenDependencyResolver(
baseDir: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.github.shyiko.ktlint.internal

import com.google.common.jimfs.Configuration
import com.google.common.jimfs.Jimfs
import java.nio.file.Files
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
import java.nio.file.Files

class EditorConfigTest {

Expand Down

0 comments on commit 2cecdde

Please sign in to comment.