eslint-plugin-annotation
raw JSON → 1.1.6 verified Fri May 01 auth: no javascript
ESLint plugin providing lint rules to validate and auto-correct code based on JSDoc-like annotations in comments. Current stable version 1.1.6, released 2023. Supports Node 12, 14, 16+. Differentiators: allows enforcing sort order, uniqueness, and date format via annotation comments, with autofix support for sort and unique rules. Lightweight, no external runtime dependencies beyond ESLint peer dependency.
Common errors
error Error: Failed to load plugin 'annotation' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-annotation' ↓
cause Plugin not installed or not in node_modules.
fix
Run 'npm install eslint-plugin-annotation --save-dev'
error Oops! Something went wrong! :(. ESLint: 7.x encountered an unexpected error. ↓
cause ESLint version incompatible (may need ESLint >=8).
fix
Update ESLint to version 8 or later: 'npm install eslint@latest --save-dev'
error Parsing error: The keyword '@sort' is not supported ↓
cause Syntax error in annotation or using wrong format.
fix
Ensure annotation comment is on its own line above the target, e.g., '// @sort' or '/* @sort */'
Warnings
gotcha Rules only work if annotation comments are present in the code (e.g., @sort, @unique). Without them, rules silently pass. ↓
fix Add the appropriate annotation comment above the target code block.
gotcha Autofix for sort and sort-keys rules may change array or object order unexpectedly; review before committing. ↓
fix Use --fix-dry-run to preview changes.
gotcha Plugin only supports Node ^12.22.0 || ^14.17.0 || >=16.0.0; older Node versions not supported. ↓
fix Upgrade Node to supported version.
Install
npm install eslint-plugin-annotation yarn add eslint-plugin-annotation pnpm add eslint-plugin-annotation Imports
- plugin wrong
const annotation = require('eslint-plugin-annotation')correctimport annotation from 'eslint-plugin-annotation' - rules
import { rules } from 'eslint-plugin-annotation' - configs wrong
const configs = require('eslint-plugin-annotation').configscorrectimport { configs } from 'eslint-plugin-annotation'
Quickstart
// .eslintrc.js
module.exports = {
plugins: ['annotation'],
rules: {
'annotation/format-date': 'error',
'annotation/sort-keys': 'error',
'annotation/sort': 'error',
'annotation/unique': 'error',
},
};
// For programmatic usage (ESM):
// import annotation from 'eslint-plugin-annotation';
// const linter = new ESLint({ plugins: { annotation } });