GithubHelp home page GithubHelp logo

bhanditz / eslint-plugin-header Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stuk/eslint-plugin-header

0.0 2.0 0.0 45 KB

ESLint plugin to ensure that files begin with given comment

JavaScript 100.00%

eslint-plugin-header's Introduction

eslint-plugin-header

ESLint plugin to ensure that files begin with given comment.

Often you will want to have a copyright notice at the top of every file. This ESLint plugin checks that the first comment in every file has the contents defined in the rule settings.

Usage

This rule takes 1 or 2 arguments with an optional settings object.

1 argument

In the 1 argument form the argument is the filename of a file that contains the comment(s) that should appear at the top of every file:

{
    "plugins": [
        "header"
    ],
    "rules": {
        "header/header": [2, "config/header.js"]
    }
}

config/header.js:

// Copyright 2015
// My company

Due to limitations in eslint plugins, the file is read relative to the working directory that eslint is executed in. If you run eslint from elsewhere in your tree then the header file will not be found.

2 arguments

In the 2 argument form the first must be either "block" or "line" to indicate what style of comment should be used. The second is either a string (including newlines) of the comment, or an array of each line of the comment.

{
    "plugins": [
        "header"
    ],
    "rules": {
        "header/header": [2, "block", "Copyright 2015\nMy Company"]
    }
}

Regular expressions

Instead of a string to be checked for exact matching you can also supply a regular expression. Be aware that you have to escape backslashes:

{
    "plugins": [
        "header"
    ],
    "rules": {
        "header/header": [2, "block", [
            {"pattern": " Copyright \\d{4}"},
            "My Company"
        ]]
    }
}

This would match:

/* Copyright 2808
My Company*/

When you use a regular expression pattern, you can also provide a template property, to provide the comment value when using eslint --fix:

{
    "plugins": [
        "header"
    ],
    "rules": {
        "header/header": [2, "block", [
            {"pattern": " Copyright \\d{4}", "template": " Copyright 2019"}, 
            "My Company"
        ]]
    }
}

Line Endings

The rule works with both unix and windows line endings. For ESLint --fix, the rule will use the line ending format of the current operating system (via the node os package). This setting can be overwritten as follows:

"rules": {
    "header/header": [2, "block", ["Copyright 2018", "My Company"], {"lineEndings": "windows"}]
}

Possible values are unix for \n and windows for \r\n line endings.

Examples

The following examples are all valid.

"block", "Copyright 2015, My Company":

/*Copyright 2015, My Company*/
console.log(1);

"line", ["Copyright 2015", "My Company"]]:

//Copyright 2015
//My Company
console.log(1)

"line", [{pattern: "^Copyright \\d{4}$"}, {pattern: "^My Company$"}]]:

//Copyright 2017
//My Company
console.log(1)

With more decoration

"header/header": [2, "block", [
    "************************",
    " * Copyright 2015",
    " * My Company",
    " ************************"
]
/*************************
 * Copyright 2015
 * My Company
 *************************/
 console.log(1);

License

MIT

eslint-plugin-header's People

Contributors

stuk avatar tripodsan avatar mhagmajer avatar pranaygp avatar ctavan avatar bangsadrengur avatar herzog31 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.