-
Notifications
You must be signed in to change notification settings - Fork 889
Conversation
Instead of adding a special case just for "I18n", would a better solution be to check if the name without the "I" is a valid identifier? "18nFactory" isn't a valid identifier because it starts with a number, so the "I" prefix must be allowed. This, of course, wouldn't work for "IDB", though I'm not sure why that was added as a hard-coded special case in the first place. |
@reduckted It seems to hard to check what is a valid identifier. I cant say every number are not valid identifier, because 3rdParty, 1rstItem, 2ndElement can be. |
None of those are valid identifiers.
|
@reduckted Ok, need to do a regex so. BTW, IDB was added as a short cup for IndexedDataBase, i think. |
/cc @adidahiya, from the linked issue. |
Yeah, I agree the existing hard-coded "IDB" special case is weird, but we should keep it around to avoid regressions.
sounds good to me |
After some reflexion, I'm not sure it's a good idea to check
A good rule seems to be : And best way to check if |
@@ -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]); |
There was a problem hiding this comment.
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 withI
)
I know it feels a little silly since these are edge cases in naming, but we should try to be consistent in some way
There was a problem hiding this comment.
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.
@adidahiya @JoshuaKGoldberg I added a lot of test and then fix the edge cases. |
I think this change caused a regression, I'm noticing now that correctly prefixed interfaces that have a number in it (e.g. |
thanks so much! |
PR checklist
Overview of change:
Interface name (never-prefix) doesn't return error for I18nSomething
CHANGELOG.md entry:
[bugfix]
interface-name
now handles interface starting with "I18n" correctly