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
Closes coala#2152
- Loading branch information
1 parent
5a4115e
commit c2c146a
Showing
11 changed files
with
107 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
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,27 @@ | ||
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<filename>.*):(?P<line>\d+):' | ||
r'(?P<column>\d+): (?P<message>.+)') | ||
class KotlinLintBear: | ||
""" | ||
Lints your Kotlin files. | ||
Checks for coding standards or semantical problems that might lead | ||
to problems in execution of the code. | ||
""" | ||
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,32 @@ | ||
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) > 5) | ||
|
||
def test_good_files(self): | ||
self.set_config_dir('good_files') | ||
results = list(self.uut.run_bear_from_section([], {})) | ||
self.assertTrue(len(results) == 0) |
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,8 @@ | ||
fun a() { | ||
|
||
|
||
} | ||
fun b() { | ||
|
||
|
||
} |
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,19 @@ | ||
/** | ||
* _ | ||
*/ | ||
fun main() { | ||
val a = 0 | ||
val b = 0 | ||
if (a == 0) { | ||
println(a) | ||
} | ||
val b = builder().setX().setY() | ||
.build() | ||
val c = builder("long_string" + | ||
"") | ||
} | ||
class A { | ||
var x: String | ||
get() = "" | ||
set(v: String) { x = v } | ||
} |
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 @@ | ||
fun main() { x(1,3); x(1, 3)\n \n } |
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) | ||
} | ||
} |