npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-notice

v1.0.0

Published

An eslint rule that checks the top of files and --fix them too!

Downloads

318,203

Readme

Build Status

eslint-plugin-notice

An eslint rule that checks the top of files and --fix them too!

Usage

npm i -D eslint-plugin-notice

Flag config

eslint.config.js

import notice from "eslint-plugin-notice";

export default [
  {
    files: ["**/*.js"],
    plugins: {
      notice,
    },
    rules: {
      "notice/notice": [
        "error",
        { mustMatch: "Copyright \\(c\\) [0-9]{0,4}, Nick Deis" },
      ],
    },
  },
];

eslintrc

Throw an error when a file doesn't have copyright notice

{
  "plugins": ["notice"],
  "rules": {
    "notice/notice": [
      "error",
      { "mustMatch": "Copyright \\(c\\) [0-9]{0,4}, Nick Deis" }
    ]
  }
}

Add a template to --fix it

{
  "notice/notice": [
    "error",
    {
      "mustMatch": "Copyright \\(c\\) [0-9]{0,4}, Nick Deis",
      "template": "/** Copyright (c) <%= YEAR %>, Nick Deis **/"
    }
  ]
}

or use a file

config/copyright.js

/**
 * Copyright (c) <%= YEAR %>, Nick Deis
 */
{
  "notice/notice": [
    "error",
    {
      "mustMatch": "Copyright \\(c\\) [0-9]{0,4}, Nick Deis",
      "templateFile": "config/copyright.js"
    }
  ]
}

or just use your template, eslint-plugin-notice will reverse into a pattern for mustMatch

{
  "notice/notice": [
    "error",
    {
      "templateFile": "config/copyright.js"
    }
  ]
}

Want a more expressive template? Add templateVars and varRegexps config/copyright.js

/**
 * Copyright (c) <%= YEAR %>, <%= NAME %>
 */
{
    "notice/notice":["error",
        {
        templateFile:"config/copyright.js",
        //YEAR will still be added unless you add your own value
        templateVars:{NAME:"Nick Deis"},
        //The regexp for YEAR is /20\d{2}/ and is automatically added
        varRegexps:{NAME:/(Nick|Nicholas) Deis/}
        }
    ]
}

Options

| Option | Description | Default/Required/Optional | Type | | ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | ---------------------- | | mustMatch | A pattern that must be present in the notice | Required unless template is set | RegExp/string | | template | A lodash template that will be used to fix files that do not match mustMatch or are less than nonMatchingTolerance | Optional unless mustMatch is not set | string | | templateFile | template will override this setting. A file which contains the template | Optional | string | | chars | The number of characters to check for the mustMatch pattern | 1000 | number | | templateVars | The variables to be used with the lodash template, always contains the variable YEAR | {YEAR:new Date().getFullYear()} | object | | onNonMatchingHeader | Action that should be taken when there is a header comment, but it does not match mustMatch or is less than nonMatchingTolerance | "prepend" | string | | nonMatchingTolerance | Optional fallback for mustMatch. Compares a non-matching header comment (if it exists) to the resolved template using Metric Longest Common Subsequence. 1 means the strings must be exactly the same, where anything less is varying degrees of dissimiliar. .70 seems like a good choice | Optional | number between 0 and 1 | | varRegexps | If mustMatch is not set and template is set, a regexp that will be replaced in the template to create a regexp for mustMatch | {YEAR:/20\d{2}/} | object | | messages | Allows you to change the error messages. See messages | Optional | object |

onNonMatchingHeader

  • prepend: Prepends the fix template, if it exists, leaving the former header comment intact.
  • replace: Replaces the former header comment with the fix template if it exists
  • report: Does not apply fix, simply reports it based on the level assigned to the rule ("error" or "warn")

messages

The messages option allows you to change the default error messages. There are three messages you can change by passing in an object with the pairs you wish to change. For example, if you want to change the default message for when a header does not match mustMatch:

{
    "notice/notice":["error",
        {
            "mustMatch":"Apache License",
            "templateFile":"config/apache.js",
            "messages":{
                "whenFailedToMatch":"Couldn't find 'Apache License', are you sure you added it?"
            }
        }
    ]
}

The three configurable messages are:

  • whenFailedToMatch: When the header fails to match the mustMatch pattern.
  • reportAndSkip: When using "onNonMatchingHeader":"report" and a non-matching notice is found.
  • whenOutsideTolerance: When you using nonMatchingTolerance to check for notice similarity and it fails to be similar enough. Passes in similarity as a template variable (eg "The similarity is {{ similarity }}")