🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

eslint-plugin-headers

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-headers

A flexible and `--fix`able rule for checking, inserting, and formatting file headers.

1.0.5
Source
npm
Version published
Weekly downloads
16K
33.81%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-headers

A flexible and --fixable 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.

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-headers:

npm install eslint-plugin-headers --save-dev

Usage

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

Options are supplied through a single object with the following properties:

NameTypeRequiredDefaultDescription
source"file" | "string"YesIndicates 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.
contentstringWhen source: "string"The string to enforce in the header comment.
pathstringWhen source: "file"The path to a file containing the header content to enforce.
preservePragmasbooleanNotruePreserves existing pragma expressions in leading comments when updating header. No effect when style: "line".
blockPrefixstringNo"*" + newline when style: "jsdoc"Content at the start of the leading comment block.
blockSuffixstringNonewline + " " when style: "jsdoc"Content at the end of the leading comment block.
linePrefixstringNo" * " when style: "jsdoc", " " when style: "line"Content prepended to the start of each line of content.
trailingNewlinesnumberNoNumber of empty lines to enforce after the leading comment.

Future

  • Add support for common pragma expressions that don't utilize the @ symbol (e.g. eslint-disable)

Rules

🔧 Automatically fixable by the --fix CLI option.

Name         Description🔧
header-formatVerifies the content and format of a file's leading comment block.🔧

Keywords

eslint

FAQs

Package last updated on 05 Jan 2024

Did you know?

Socket

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.

Install

Related posts