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

Commit

Permalink
Fix interfaceName rule (#4655)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and Josh Goldberg committed Apr 13, 2019
1 parent d7c514e commit 35db430
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
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

0 comments on commit 35db430

Please sign in to comment.