forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KotlinLintBear.py: Add bear wrapping ktlint
Checks for coding standards or semantic problems in Kotlin files. Closes coala#2152
- Loading branch information
1 parent
b650a4b
commit cfb5bc0
Showing
14 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from coalib.bearlib.abstractions.Linter import linter | ||
from dependency_management.requirements.DistributionRequirement import ( | ||
DistributionRequirement) | ||
|
||
|
||
@linter(executable='ktlint', | ||
global_bear=True, | ||
output_format='regex', | ||
output_regex=r'(?P<line>\d+):(?P<column>\d+): ' | ||
r'(?P<message>.+)') | ||
class KotlinLintBear: | ||
""" | ||
Lints your Kotlin files. | ||
Checks for coding standards or semantic problems in Kotlin files. | ||
""" | ||
LANGUAGES = {'kotlin'} | ||
REQUIREMENTS = {DistributionRequirement(brew='shyiko/ktlint/ktlint')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Formatting', 'Syntax'} | ||
SEE_MORE = 'https://ktlint.github.io' | ||
|
||
@staticmethod | ||
def create_arguments(config_file): | ||
return () |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import unittest | ||
from queue import Queue | ||
|
||
from coalib.settings.Section import Section | ||
from bears.kotlin.KotlinLintBear import KotlinLintBear | ||
from coalib.testing.BearTestHelper import generate_skip_decorator | ||
|
||
|
||
@generate_skip_decorator(KotlinLintBear) | ||
class KotlinLintBearTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.section = Section('Kotlin') | ||
self.queue = Queue() | ||
self.file_dict = {} | ||
self.uut = KotlinLintBear(self.file_dict, self.section, self.queue) | ||
|
||
def set_config_dir(self, directory): | ||
test_path = os.path.abspath(os.path.join( | ||
os.path.dirname(__file__), directory)) | ||
self.uut.get_config_dir = lambda *args, **kwargs: test_path | ||
|
||
def test_bad_files(self): | ||
self.set_config_dir('bad_files') | ||
results = list(self.uut.run_bear_from_section([], {})) | ||
self.assertTrue(len(results) > 10) | ||
|
||
def test_good_files(self): | ||
self.set_config_dir('good_files') | ||
results = list(self.uut.run_bear_from_section([], {})) | ||
self.assertTrue(len(results) == 0) | ||
|
||
def test_config_files(self): | ||
self.set_config_dir('test_files') | ||
results = list(self.uut.run_bear_from_section([], {})) | ||
self.assertTrue(len(results) == 1) | ||
self.assertEqual(results[0].message, | ||
'File must end with a newline (\\n)') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import io.vertx.core.* | ||
import com.google.inject.* | ||
import pkg.UnusedClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
abstract internal class A { | ||
open protected val v = "" | ||
open suspend internal fun f(v: Any): Any = "" | ||
lateinit public var lv: String | ||
tailrec abstract fun findFixPoint(x: Double = 1.0): Double | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package a.b.c; | ||
fun main() { | ||
fun name() { a(); return b } | ||
println(";") | ||
println(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
val a = "class = ${String::class.toString()}" | ||
val b = "not ${a}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fun a() { | ||
val x = 5 | ||
if (x == 0) { | ||
println(a) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
internal abstract class A { | ||
protected open val v = "" | ||
internal open suspend fun f(v: Any): Any = "" | ||
public lateinit var lv: String | ||
abstract tailrec fun findFixPoint(x: Double = 1.0): Double | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
internal abstract class A { | ||
protected open val v = "" | ||
internal open suspend fun f(v: Any): Any = "" | ||
public lateinit var lv: String | ||
abstract tailrec fun findFixPoint(x: Double = 1.0): Double | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[*.{kt,kts}] | ||
insert_final_newline=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fun a() { | ||
val x = 5 | ||
if (x == 0) { | ||
println(a) | ||
} | ||
} |