Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Fix interfaceName rule #4655

Merged
merged 1 commit into from Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/rules/interfaceNameRule.ts
Expand Up @@ -75,19 +75,17 @@ function walk(ctx: Lint.WalkContext<{ never: boolean }>): void {
}

function hasPrefixI(name: string): boolean {
return (
name.length >= 3 && name[0] === "I" && /^[A-Z]*$/.test(name[1]) && !/^[A-Z]*$/.test(name[2])
);
return name.length >= 3 && name[0] === "I" && /^[A-Z]*$/.test(name[1]);
}

function cantDecide(name: string): boolean {
return (
// Case ID
(name.length === 2 && name[0] === "I" && /^[A-Z]*$/.test(name[1])) ||
// Case IDB
// Case IDB or ID42
(name.length >= 2 &&
name[0] === "I" &&
/^[A-Z]*$/.test(name[1]) &&
/^[A-Z]*$/.test(name[2]))
!/^[a-z]*$/.test(name[2]))
);
}
10 changes: 10 additions & 0 deletions test/rules/interface-name/always-prefix/test.ts.lint
Expand Up @@ -14,6 +14,12 @@ interface IDBFactory {
interface II18nService {
}

interface IIS3Foobar {
}

interface IS3Foobar {
}

// invalid code
interface Options {
~~~~~~~ [interface name must start with a capitalized I]
Expand All @@ -22,3 +28,7 @@ interface Options {
interface Incomplete {
~~~~~~~~~~ [interface name must start with a capitalized I]
}

interface I18nService {
~~~~~~~~~~~ [interface name must start with a capitalized I]
}
9 changes: 9 additions & 0 deletions test/rules/interface-name/never-prefix/test.ts.lint
Expand Up @@ -17,6 +17,15 @@ interface IDBFactory {
interface I18nFactory {
}

interface II18nFactory {
}

interface IS3Foobar {
}

interface IIS3Foobar {
}

interface ABC {
}

Expand Down