
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
eslint-plugin-headers
Advanced tools
A flexible and `--fix`able rule for checking, inserting, and formatting file headers.
A flexible and --fix
able rule for checking, inserting, and formatting file
headers.
Supports configurable usage of block or line comments, custom comment block prefixes and suffixes, custom line prefixes, and spacing between the header and code.
Useful for inserting, enforcing, and updating copyright or licensing notices while preserving pragma expressions in leading content blocks.
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-headers
:
npm install eslint-plugin-headers --save-dev
Add headers
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": ["headers"]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"headers/header-format": [
"error",
{
"source": "string",
"content": "Copyright 2023. All rights reserved."
}
]
}
}
Example 0:
Using the configuration from above, here's a file without a matching header:
module.exports = 42;
When the fix is applied, the file now appears so:
/**
* Copyright 2023. All rights reserved.
*/
module.exports = 42;
Example 1:
Using the same configuration, this file already has a header, this one containing pragmas:
/**
* @fileoverview This file contains a magic number.
* @author Rob Misasi
*/
module.exports = 42;
When the fix is applied, the file now appears so:
/**
* Copyright 2023. All rights reserved.
*
* @fileoverview This file contains a magic number.
* @author Rob Misasi
*/
module.exports = 42;
Options are supplied through a single object with the following properties:
Name | Type | Required | Default | Description |
---|---|---|---|---|
source | "file" | "string" | Yes | Indicates how the header content is supplied. | |
style | "line" | "jsdoc" | No | "jsdoc" | Indicates the comment style to enforce. A leading line-style comment block will only include adjacent line comments, although a line comment's content may be empty. |
content | string | When source: "string" | The string to enforce in the header comment. | |
path | string | When source: "file" | The path to a file containing the header content to enforce. | |
preservePragmas | boolean | No | true | Preserves existing pragma expressions in leading comments when updating header. No effect when style: "line" . |
blockPrefix | string | No | "*" + newline when style: "jsdoc" | Content at the start of the leading comment block. |
blockSuffix | string | No | newline + " " when style: "jsdoc" | Content at the end of the leading comment block. |
linePrefix | string | No | " * " when style: "jsdoc" , " " when style: "line" | Content prepended to the start of each line of content. |
trailingNewlines | number | No | Number of empty lines to enforce after the leading comment. |
@
symbol (e.g. eslint-disable)🔧 Automatically fixable by the --fix
CLI option.
Name | Description | 🔧 |
---|---|---|
header-format | Verifies the content and format of a file's leading comment block. | 🔧 |
FAQs
A flexible and `--fix`able rule for checking, inserting, and formatting file headers.
The npm package eslint-plugin-headers receives a total of 13,622 weekly downloads. As such, eslint-plugin-headers popularity was classified as popular.
We found that eslint-plugin-headers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.