Lint rules to validate and auto-correct annotation-based policies
npm install eslint-plugin-annotationAn ESLint plugin that collects rules to exceptionally validate and autocorrect code with annotations in comments.
| annotation/sort | annotation/sort-keys
|---|---|
| !sort | !sort-keys |
npm i eslint --save-dev
`Next, install
eslint-plugin-annotation:
`
npm i eslint-plugin-annotation --save-dev
`Usage
Here’s a suggested ESLint configuration that:
`javascript
{
"parserOptions": { ... }, // Nothing changed
"plugins": [..., "annotation"], // Add 'annotation' next to old plugins
"rules": {
...
// Add below rules next to old rules
'annotation/format-date': 'error',
'annotation/sort-keys': 'error',
'annotation/sort': 'error',
'annotation/unique': 'error',
}
}
`Supported Rules
| Rule | Description | Autofix |
|---|---|---|
| format-date | Ensure dates in strings match the specified @format-date annotation | ❌ |
| sort-keys | Sort interface properties or object keys if has @sort-keys annotation | ✔️ |
| sort | Sort array values if has @sort annotation | ✔️ |
| unique | Ensure array values are unique if annotated with @unique` | ✔️ |
[npm-image]: http://img.shields.io/npm/v/eslint-plugin-annotation.svg
[npm-url]: https://npmjs.org/package/eslint-plugin-annotation
[build-image]: http://img.shields.io/github/workflow/status/ronparkdev/eslint-plugin-annotation/Build%20and%20unit%20test.svg
[build-url]: https://github.com/ronparkdev/eslint-plugin-annotation/actions/workflows/ci.yml