Skip to content

Commit

Permalink
Merge pull request #77 from asarazan/fix/packageNameDashes
Browse files Browse the repository at this point in the history
Dashes become underscores in package names, also respects snakeToCamel.
  • Loading branch information
asarazan authored Mar 8, 2024
2 parents dc448f6 + 9656f55 commit 201352e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/martok/Martok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { title } from "./NameGenerators";
import { AsyncLocalStorage } from "async_hooks";
import { TypeReplacer } from "./processing/TypeReplacer";
import { processSnakeCase } from "./processing/SnakeCase";
import { processOldNames } from "./processing/SanitizeNames";
import { processOldNames, sanitizeName } from "./processing/SanitizeNames";
import { TypeExpander } from "./processing/TypeExpander";
import { TsCompiler } from "./TsCompiler";

Expand Down Expand Up @@ -200,6 +200,8 @@ export class Martok {
`${file.fileName} is not within the given source root, it can't be included in this project.`
);
}
return `${this.config.package}${relativePath.replace(/\//g, ".")}`;
return sanitizeName(
`${this.config.package}${relativePath.replace(/\//g, ".")}`
);
}
}
2 changes: 1 addition & 1 deletion src/martok/processing/SanitizeNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Klass = kotlin.Klass;
import { MartokOutFile } from "../MartokOutFile";

export function sanitizeName(name: string): string {
return name.replace(/:/g, "_").replace(/"/g, "");
return name.replace(/:/g, "_").replace(/"/g, "").replace(/-/g, "_");
}

export function processOldNames(files: MartokOutFile[]) {
Expand Down
1 change: 1 addition & 0 deletions src/martok/processing/SnakeCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MartokOutFile } from "../MartokOutFile";

export function processSnakeCase(files: MartokOutFile[]) {
for (const file of files) {
file.pkg = snakeToCamel(file.pkg);
for (const klass of file.text.declarations) {
if (!(klass instanceof Klass)) continue;
processKlass(klass);
Expand Down
6 changes: 5 additions & 1 deletion src/tests/NameGenerators.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { pascalToSnake, snakeToCamel, title } from "../martok/NameGenerators";
import { sanitizeName } from "../martok/processing/SanitizeNames";

describe("Naming Correctness Tests", () => {
it("convert snake to camel", () => {
expect(snakeToCamel("utcDate1")).toBe("utcDate1");
expect(snakeToCamel("utc_date_1")).toBe("utcDate1");
expect(snakeToCamel("foo_bar")).toBe("fooBar");
});
it("convert pascale to snake", () => {
it("convert pascal to snake", () => {
expect(pascalToSnake("oneTwo")).toBe("one_two");
expect(pascalToSnake("OneTwo")).toBe("one_two");
expect(pascalToSnake("one")).toBe("one");
Expand All @@ -17,4 +18,7 @@ describe("Naming Correctness Tests", () => {
expect(title("foo_bar")).toBe("FooBar");
expect(title("foo__bar")).toBe("FooBar");
});
it("Sanitize dashes", () => {
expect(sanitizeName("foo-bar")).toBe("foo_bar");
});
});

0 comments on commit 201352e

Please sign in to comment.