Skip to content

Commit

Permalink
Merge pull request #10 from pjonsson/typescript-remove-public-modifie…
Browse files Browse the repository at this point in the history
…r-test

fix: typescript/remove-public-modifier: keep private/protected
  • Loading branch information
amirabbas-gh authored Dec 23, 2024
2 parents 2bda70c + 0b4a472 commit 7b83098
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion codemods/typescript/remove-public-modifier/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function transformer(file: FileInfo, api: API) {
path.node.body.body.forEach((member) => {
if (
(member.type === "ClassMethod" || member.type === "ClassProperty") &&
"accessibility" in member
"accessibility" in member && member.accessibility === "public"
) {
member.accessibility = undefined;
}
Expand Down
6 changes: 5 additions & 1 deletion codemods/typescript/remove-public-modifier/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,20 @@ describe("remove-public-modifier", () => {
);
});

it("class with other modifiers (static, readonly)", () => {
it("class with other modifiers (private, protected, static, readonly)", () => {
const INPUT = `
class MyClass {
public static readonly myProperty: string = 'value';
private secondProperty: string = 'value';
protected thirdProperty: string = 'value';
}
`;

const OUTPUT = `
class MyClass {
static readonly myProperty: string = 'value';
private secondProperty: string = 'value';
protected thirdProperty: string = 'value';
}
`;
const fileInfo: FileInfo = {
Expand Down

0 comments on commit 7b83098

Please sign in to comment.