-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for enum and class members
- Loading branch information
Showing
10 changed files
with
151 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export class Rectangle { | ||
constructor( | ||
public width: number, | ||
public height: number | ||
) {} | ||
|
||
static Key = 1; | ||
|
||
public get unusedGetter(): string { | ||
return 'unusedGetter'; | ||
} | ||
|
||
private set unusedSetter(w: number) { | ||
this.width = w; | ||
} | ||
|
||
area() { | ||
return this.width * this.height; | ||
} | ||
} |
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,11 @@ | ||
export enum Directions { | ||
North = 1, | ||
East = 2, | ||
South = 3, | ||
West = 4, | ||
} | ||
|
||
export enum Fruits { | ||
apple = 'apple', | ||
orange = 'orange', | ||
} |
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,9 @@ | ||
import { Rectangle } from './class.js'; | ||
import { Directions, Fruits } from './enums.js'; | ||
|
||
Directions.East; | ||
|
||
Fruits.apple; | ||
|
||
const rect = new Rectangle(); | ||
rect.area(); |
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 @@ | ||
{ | ||
"name": "@fixtures/fix-members" | ||
} |
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
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,80 @@ | ||
import { test } from 'bun:test'; | ||
import assert from 'node:assert/strict'; | ||
import { readFile, writeFile } from 'node:fs/promises'; | ||
import { main } from '../src/index.js'; | ||
import { join, resolve } from '../src/util/path.js'; | ||
import baseArguments from './helpers/baseArguments.js'; | ||
|
||
const cwd = resolve('fixtures/fix-members'); | ||
|
||
const readContents = async (fileName: string) => await readFile(join(cwd, fileName), 'utf8'); | ||
|
||
test('Remove exports and dependencies', async () => { | ||
const tests = [ | ||
[ | ||
'class.ts', | ||
await readContents('class.ts'), | ||
`export class Rectangle { | ||
constructor( | ||
public width: number, | ||
public height: number | ||
) {} | ||
` + | ||
' \n\n ' + | ||
` | ||
private set unusedSetter(w: number) { | ||
this.width = w; | ||
} | ||
area() { | ||
return this.width * this.height; | ||
} | ||
} | ||
`, | ||
], | ||
[ | ||
'enums.ts', | ||
await readContents('enums.ts'), | ||
`export enum Directions { | ||
` + | ||
' ' + | ||
` | ||
East = 2, | ||
` + | ||
' \n ' + | ||
` | ||
} | ||
export enum Fruits { | ||
apple = 'apple', | ||
` + | ||
' ' + | ||
` | ||
} | ||
`, | ||
], | ||
]; | ||
|
||
const { issues } = await main({ | ||
...baseArguments, | ||
cwd, | ||
includedIssueTypes: ['classMembers'], | ||
isFix: true, | ||
}); | ||
|
||
assert(issues.enumMembers['enums.ts']['orange']); | ||
assert(issues.enumMembers['enums.ts']['North']); | ||
assert(issues.enumMembers['enums.ts']['South']); | ||
assert(issues.enumMembers['enums.ts']['West']); | ||
assert(issues.classMembers['class.ts']['Key']); | ||
assert(issues.classMembers['class.ts']['unusedGetter']); | ||
|
||
for (const [fileName, before, after] of tests) { | ||
const filePath = join(cwd, fileName); | ||
const originalFile = await readFile(filePath); | ||
assert.equal(String(originalFile), after); | ||
await writeFile(filePath, before); | ||
} | ||
}); |
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