Require that interface names should or should not prefixed with I (interface-name-prefix)
Interfaces often represent important software contracts, so it can be helpful to prefix their names with I
. The unprefixed name is then available for a class that provides a standard implementation of the interface. Alternatively, the contributor guidelines for the TypeScript repo suggest never prefixing interfaces with I
.
DEPRECATED
This rule has been deprecated in favour of the naming-convention
rule. It will be removed in a future version of this plugin.
Rule Details
This rule enforces whether or not the I
prefix is required for interface names. The _
prefix is sometimes used to designate a private declaration, so the rule also supports a private interface that might be named _IAnimal
instead of IAnimal
.
Options
This rule has an object option:
{ "prefixWithI": "never" }
: (default) disallows all interfaces being prefixed with"I"
or"_I"
{ "prefixWithI": "always" }
: requires all interfaces be prefixed with"I"
(but does not allow"_I"
){ "prefixWithI": "always", "allowUnderscorePrefix": true }
: requires all interfaces be prefixed with either"I"
or"_I"
For backwards compatibility, this rule supports a string option instead:
"never"
: Equivalent to{ "prefixWithI": "never" }
"always"
: Equivalent to{ "prefixWithI": "always" }
Examples
never
Configuration: { "prefixWithI": "never" }
The following patterns are considered warnings:
The following patterns are not warnings:
always
Configuration: { "prefixWithI": "always" }
The following patterns are considered warnings:
The following patterns are not warnings:
always and allowing underscores
Configuration: { "prefixWithI": "always", "allowUnderscorePrefix": true }
The following patterns are considered warnings:
The following patterns are not warnings:
When Not To Use It
If you do not want to enforce interface name prefixing.
Further Reading
TypeScript Interfaces
Compatibility
TSLint: interface-name
Last updated