eslint-plugin-use-decorator
v0.2.0
Published
This is a custom plugin for eslint which enforces the use of decorators on methods.
Downloads
4,476
Maintainers
Readme
eslint-plugin-use-decorator
This is a custom plugin for eslint which enforces the use of decorators on methods.
Note
This only works with the @typescript-eslint
plugin
Installation
npm install --save-dev eslint-plugin-use-decorator
Usage
Add this to your .eslintrc
// .eslintrc
{
"plugins": ["use-decorator"],
"rules": {
"use-decorator/use-decorator": [1, {
"params": [
{
"name": "assertParameter",
"public": true
}
],
"methods": [
{
"name": "assert",
"public": true
},
{
"name": "errorcatch",
"async": true,
"private": true
}
],
"class": [
{
"superClass": ["Vue", "Mixins"],
"name": "Component"
},
]
}]
}
}
Now methods and its parameters are checked for their decorators. Above rule would enforce following custom decorators:
class SomeClass {
@assert
someMethod(
@assertParameter
someParameter: number
): number {
return someParameter;
}
@errorcatch
private async somePrivateAsyncMethod(
someParameter: number
): Promise<number> {
return someParameter;
}
/**
* This one does not need a decorator, because its only async.
* It would need to be private as well for the linting to take effect.
*/
async someAsyncMethod(
someParameter: number
): Promise<number> {
return someParameter;
}
}
The options object looks like this:
Options
{
"params": [
{
"name": "string",
"private?": "boolean", // default: false
"public?": "boolean", // default: false
"async?": "boolean", // default: false,
"static?": "boolean" // default: false
}
],
"methods": [
{
"name": "assert",
"private?": "boolean", // default: false
"public?": "boolean", // default: false
"async?": "boolean", // default: false
"static?": "boolean" // default: false
}
]
}