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

Fix interface name rule #4626

Merged
merged 1 commit into from Apr 4, 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
14 changes: 10 additions & 4 deletions src/rules/interfaceNameRule.ts
Expand Up @@ -19,7 +19,6 @@ import * as utils from "tsutils";
import * as ts from "typescript";

import * as Lint from "../index";
import { isLowerCase, isUpperCase } from "../utils";

const OPTION_ALWAYS = "always-prefix";
const OPTION_NEVER = "never-prefix";
Expand Down Expand Up @@ -76,12 +75,19 @@ function walk(ctx: Lint.WalkContext<{ never: boolean }>): void {
}

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

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

interface II18nService {
}

// invalid code
interface Options {
~~~~~~~ [interface name must start with a capitalized I]
Expand Down