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

Handle I18n case #4486

Merged
merged 5 commits into from Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 2 additions & 3 deletions src/rules/interfaceNameRule.ts
Expand Up @@ -19,7 +19,7 @@ import * as utils from "tsutils";
import * as ts from "typescript";

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

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

function hasPrefixI(name: string): boolean {
// Allow IndexedDB interfaces
return name.length >= 2 && name[0] === "I" && isUpperCase(name[1]) && !name.startsWith("IDB");
return name.length >= 3 && name[0] === "I" && !isLowerCase(name[1]) && !isUpperCase(name[2]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some test cases in always-prefix/test.ts.lint as well? I feel like this will affect that option's behavior.

with always-prefix, I think the behavior should be:

  • failures: ID
  • valid: IDB (or, any all-caps interface name starting with I)

I know it feels a little silly since these are edge cases in naming, but we should try to be consistent in some way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add test yes.
But I didn't change the behaviour for the always-prefix rule.

Actually the test check only if the first letter is I.
Now I'm thinking about it, an interface called Information should return an error but it doesn't.

With always-prefix, I think ID should return no error.
You can create an A interface, called IA with prefix. The same way a D interface would be named ID with prefix.

To be consistent the best way is to check
always-prefix && !hasPrefixI && !EdgeCase or never-prefix && hasPrefixI
Where EdgeCase are two letters upercase interface starting by I.

}
3 changes: 3 additions & 0 deletions test/rules/interface-name/never-prefix/test.ts.lint
Expand Up @@ -8,6 +8,9 @@ interface I {
interface IDBFactory {
}

interface I18nFactory {
}

interface ABC {
}

Expand Down