Giter Site home page Giter Site logo

captainhook-eslint's Introduction

CI Latest Stable Version

moxio/captainhook-eslint

This project is a plugin for CaptainHook to check JavaScript files using ESLint in a git pre-commit hook. By default all *.js and *.mjs files are checked, and the commit is blocked when one or more errors are found. Warnings produced by ESLint are ignored.

Installation

Install as a development dependency using composer:

$ composer require --dev moxio/captainhook-eslint

Usage

Add ESLint validation as a pre-commit to your captainhook.json configuration file:

{
    "pre-commit": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Moxio\\CaptainHook\\ESLint\\ESLintAction"
            }
        ]
    }
}

The action expects ESLint to be installed as a local NPM package (i.e. available at node_modules/.bin/eslint). It should be configured in a way that automatically finds the appropriate configuration, e.g. as an .eslintrc.* file or with the eslintConfig field in package.json.

Conditional usage

If you want to perform ESLint validation only when ESLint is installed (i.e. available at node_modules/.bin/eslint), you can add a corresponding condition to the action:

{
    "pre-commit": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Moxio\\CaptainHook\\ESLint\\ESLintAction",
                "conditions": [
                    {
                        "exec": "\\Moxio\\CaptainHook\\ESLint\\Condition\\ESLintInstalled"
                    }
                ]
            }
        ]
    }
}

This may be useful in scenarios where you have a shared CaptainHook configuration file that is included both in projects that use ESLint and projects that don't. If ESLint is installed, the action is run. In projects without ESLint, the validation is skipped.

Configuring checked file extensions

By default, committed files with a .js or .mjs extension will be checked. If you want to customize this, e.g. to also validate TypeScript files, you can do so with the extensions option, which accepts an array with extensions of files to lint:

{
    "pre-commit": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Moxio\\CaptainHook\\ESLint\\ESLintAction",
                "options": {
                    "extensions": [ "js", "mjs", "ts", "tsx" ]
                }
            }
        ]
    }
}

Versioning

This project adheres to Semantic Versioning.

License

This project is released under the MIT license.

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.