eslint-plugin-prefix-types
v2.0.0
Published
An eslint plugin to enforce the prefixing of types and interfaces.
Downloads
45
Maintainers
Readme
eslint-plugin-prefix-types
An ESLint plugin to enforce or prevent the prefixing of interfaces, types, and styled components. Includes code fixing to fix the errors found.
Rules:
eslint-plugin-prefix-types
supports 2 main rules types:
- enforcing prefixing
- preventing prefixing
Enforcing prefixes
- Interfaces should start with the letter I
- Types should start with the letter T
- Styled components should start with the letter S
| Valid | Invalid |
| -------------------------------------------- | ------------------------------------------- |
| interface IProps { preview: boolean; }
| interface Props { preview: boolean; }
|
| type TMyType = "Single"
| type MyType = "Single"
|
| const SCard = styled.div``display: flex;
| const Card = styled.div``display: flex;
|
Preventing prefixing
- Interfaces should not start with the letter I
- Types should not start with the letter T
- Styled components should not start with the letter S
| Valid | Invalid |
| ------------------------------------------- | -------------------------------------------- |
| interface Props { preview: boolean; }
| interface IProps { preview: boolean; }
|
| type MyType = "Single"
| type TMyType = "Single"
|
| const Card = styled.div``display: flex;
| const SCard = styled.div``display: flex;
|
In both rules, this plugin follows the convention that interface and type names should use Pascal case. This means some names might be changed to something new. For example, myProps
would be changed to IMyProps
.
Installation
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-prefix-types
:
npm install eslint-plugin-prefix-types --save-dev
Usage
Add prefix-types
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": ["prefix-types"]
}
Then configure the rules you want to use under the rules section. Set allow: "always"
to enforce prefixing, or allow: "never"
to prevent it.
{
"rules": {
"prefix-types/prefer-interface-prefix": ["error", { "allow": "always" }],
"prefix-types/prefer-type-prefix": ["error", { "allow": "always" }],
"prefix-types/prefer-styled-component-prefix": ["error", { "allow": "always" }]
}
}