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

Commit

Permalink
Fix interface name rule handling of numeric characters (#4626)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and adidahiya committed Apr 4, 2019
1 parent 76b14a4 commit ab3c4d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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

0 comments on commit ab3c4d7

Please sign in to comment.