Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for Kotlin
Browse files Browse the repository at this point in the history
Updates #460

Signed-off-by: Ian Lewis <[email protected]>
ianlewis committed Dec 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c4b5f44 commit c94fbd7
Showing 4 changed files with 134 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Support for [Kotlin](https://kotlinlang.org/) was added.

## [0.7.0] - 2023-12-01

### Added in 0.7.0
3 changes: 2 additions & 1 deletion SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Supported Languages

39 languages are currently supported.
40 languages are currently supported.

| File type | Supported comments |
| ----------------- | ------------------ |
@@ -21,6 +21,7 @@
| JSON | `//`, `#`, `/* */` |
| Java | `//`, `/* */` |
| JavaScript | `//`, `/* */` |
| Kotlin | `//`, `/* */` |
| Lua | `--`, `--[[ --]]` |
| Makefile | `#` |
| Objective-C | `//`, `/* */` |
12 changes: 12 additions & 0 deletions internal/scanner/languages.yml
Original file line number Diff line number Diff line change
@@ -208,6 +208,18 @@ JSON:
- start: "'"
end: "'"
escape: backslash
Kotlin:
line_comment_start: ["//"]
multiline_comment:
start: "/*"
end: "*/"
strings:
- start: '"'
end: '"'
escape: backslash
- start: "'"
end: "'"
escape: backslash
Lua:
line_comment_start: ["--"]
multiline_comment:
114 changes: 114 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
@@ -761,6 +761,120 @@ var scannerTestCases = []*struct {
},
},

// Kotlin
{
name: "line_comments.kt",
src: `// file comment
// TODO is a function.
fun TODO() {
return // Random comment
}`,
config: "Kotlin",
comments: []struct {
text string
line int
}{
{
text: "// file comment",
line: 1,
},
{
text: "// TODO is a function.",
line: 3,
},
{
text: "// Random comment",
line: 5,
},
},
},
{
name: "multi_line.kt",
src: `// file comment
/*
TODO is a function.
*/
fun TODO() {
return // Random comment
}
/* extra comment */`,
config: "Kotlin",
comments: []struct {
text string
line int
}{
{
text: "// file comment",
line: 1,
},
{
text: "/*\n\t\t\tTODO is a function.\n\t\t\t*/",
line: 3,
},
{
text: "// Random comment",
line: 7,
},
{
text: "/* extra comment */",
line: 9,
},
},
},
{
name: "comments_in_string.kt",
src: `// file comment
// TODO is a function.
fun TODO():String {
String x = "// Random comment";
String y = "/* Random comment */";
String z = '// Random comment';
return x + y + z;
}`,
config: "Kotlin",
comments: []struct {
text string
line int
}{
{
text: "// file comment",
line: 1,
},
{
text: "// TODO is a function.",
line: 3,
},
},
},
{
name: "escaped_string.kt",
src: `// file comment
// TODO is a function.
fun TODO():String {
String x = "\"// Random comment";
String y = '\'// Random comment';
return x + y;
}`,
config: "Kotlin",
comments: []struct {
text string
line int
}{
{
text: "// file comment",
line: 1,
},
{
text: "// TODO is a function.",
line: 3,
},
},
},

// PHP
{
name: "line_comments.php",

0 comments on commit c94fbd7

Please sign in to comment.