eslint-plugin-notice
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
ESLint plugin that enforces a copyright or license notice at the top of source files. Version 1.0.0 provides a single rule `notice/notice` with an `--fix` option to automatically prepend missing headers. Unlike generic file-header linting, it uses configurable patterns, templates, and per-file overrides. Compatible with ESLint 3+. Low churn (single stable release); good for projects requiring consistent legal boilerplate.
Common errors
error Definition for rule 'notice/notice' was not found ↓
cause The plugin is not registered in the ESLint config.
fix
Add 'plugins: ["notice"]' to your .eslintrc.
error Cannot find module 'eslint-plugin-notice' ↓
cause Package is not installed or missing from node_modules.
fix
Run 'npm install eslint-plugin-notice --save-dev'.
error Invalid option 'nonMatchingTolerance' for rule notice/notice ↓
cause Misspelled or deprecated option name; use 'onNonMatchingHeader'.
fix
Replace 'nonMatchingTolerance' with 'onNonMatchingHeader' in rule options.
Warnings
gotcha The rule will error if no matching header is found, even if the file is empty. ↓
fix Add an allowEmptyFiles option or ensure all files have at least a header.
gotcha The '--fix' mode only prepends the header; it does not remove existing non-matching headers unless onNonMatchingHeader is set to 'replace'. ↓
fix Set onNonMatchingHeader: 'replace' to replace existing headers.
deprecated The option 'nonMatchingTolerance' is deprecated and may be removed in a future version. ↓
fix Use 'onNonMatchingHeader' with 'report' or 'prepend' instead.
Install
npm install eslint-plugin-notice yarn add eslint-plugin-notice pnpm add eslint-plugin-notice Imports
- plugin wrong
import plugin from 'eslint-plugin-notice';correctconst plugin = require('eslint-plugin-notice'); - rules['notice/notice'] wrong
module.exports = { rules: { 'notice/notice': ... } };correctmodule.exports = { plugins: ['notice'], rules: { 'notice/notice': ['error', { ... }] } }; - options.template wrong
const options = { template: 'Copyright (c) 2022 My Company' };correctconst options = { template: 'Copyright (c) {{year}} {{author}}' };
Quickstart
// .eslintrc.js
module.exports = {
plugins: ['notice'],
rules: {
'notice/notice': ['error', {
template: '/* Copyright (c) {{year}} {{author}} */\n',
authors: ['John Doe'],
onNonMatchingHeader: 'prepend', // or 'replace', 'report'
var: { year: new Date().getFullYear().toString() }
}]
}
};