-
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.
feat: update pascalCaseConstructId rules
- Loading branch information
1 parent
0e83f07
commit 9179479
Showing
2 changed files
with
130 additions
and
54 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 |
---|---|---|
@@ -1,71 +1,125 @@ | ||
import { RuleTester } from "eslint"; | ||
import { RuleTester } from "@typescript-eslint/rule-tester"; | ||
|
||
import { pascalCaseConstructId } from "../pascal-case-construct-id.mjs"; | ||
|
||
const ruleTester = new RuleTester({ | ||
languageOptions: { ecmaVersion: "latest", sourceType: "module" }, | ||
languageOptions: { | ||
parserOptions: { | ||
projectService: { | ||
allowDefaultProject: ["*.ts*"], | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
ruleTester.run("pascal-case-construct-id", pascalCaseConstructId, { | ||
valid: [ | ||
// WHEN: id is empty | ||
{ | ||
code: "const test = new TestClass('test');", | ||
}, | ||
{ | ||
code: "new TestClass('test');", | ||
code: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass('test'); | ||
`, | ||
}, | ||
// WHEN: id is object | ||
{ | ||
code: "const test = new TestClass('test', {sample: 'sample'});", | ||
}, | ||
{ | ||
code: "new TestClass('test', {sample: 'sample'});", | ||
code: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass('test', {sample: 'sample'});`, | ||
}, | ||
// WHEN: id is array | ||
{ | ||
code: "const test = new TestClass('test', ['sample']);", | ||
}, | ||
{ | ||
code: "new TestClass('test', ['sample']);", | ||
code: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass('test', ['sample']);`, | ||
}, | ||
// WHEN: id is number | ||
{ | ||
code: "const test = new TestClass('test', 1);", | ||
}, | ||
{ | ||
code: "new TestClass('test', 1);", | ||
code: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass('test', 1); | ||
`, | ||
}, | ||
// WHEN: id is PascalCase | ||
{ | ||
code: "const test = new TestClass('test', 'ValidId');", | ||
code: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass('test', 'ValidId');`, | ||
}, | ||
// WHEN: not extends Construct | ||
{ | ||
code: "new TestClass('test', 'ValidId');", | ||
code: ` | ||
class TestClass { | ||
constructor(public id: string) {} | ||
} | ||
const test = new TestClass('test', 'ValidId');`, | ||
}, | ||
], | ||
invalid: [ | ||
// WHEN: id is snake_case(double quote) | ||
{ | ||
code: 'new TestClass("test", "invalid_id");', | ||
errors: [{ messageId: "pascalCaseConstructId" }], | ||
output: 'new TestClass("test", "InvalidId");', | ||
}, | ||
{ | ||
code: 'const test = new TestClass("test", "invalid_id");', | ||
code: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass("test", "invalid_id");`, | ||
errors: [{ messageId: "pascalCaseConstructId" }], | ||
output: 'const test = new TestClass("test", "InvalidId");', | ||
output: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass("test", "InvalidId");`, | ||
}, | ||
// WHEN: id is camelCase(single quote) | ||
{ | ||
code: "new TestClass('test', 'invalidId');", | ||
errors: [{ messageId: "pascalCaseConstructId" }], | ||
output: "new TestClass('test', 'InvalidId');", | ||
}, | ||
{ | ||
code: "const test = new TestClass('test', 'invalidId');", | ||
code: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass('test', 'invalidId');`, | ||
errors: [{ messageId: "pascalCaseConstructId" }], | ||
output: "const test = new TestClass('test', 'InvalidId');", | ||
output: ` | ||
class Construct {} | ||
class TestClass extends Construct { | ||
constructor(props: any, id: string) { | ||
super(props, id); | ||
} | ||
} | ||
const test = new TestClass('test', 'InvalidId');`, | ||
}, | ||
], | ||
}); |
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