Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get local eslint plugins to work with locally installed eslint

According to the docs plugins should work if they are npm modules named "eslint-plugin-"

Here's a plugin that follows that pattern. Source is here.

So, we make a new project

md foo
cd foo
npm init
... answer questions ..
npm install --save-dev eslint
npm install --save-dev eslint-plugin-require
echo "define(function(){});" > test.js
echo "{\"rules\":{\"require\": 2}}" > conf.json
node node_modules/eslint/bin/eslint.js -c conf.json --plugin eslint-plugin-require test.js

produces

~/node_modules/eslint/lib/eslint.js:569
                throw new Error("Definition for rule '" + key + "' was not
                      ^
Error: Definition for rule 'require' was not found. 

change the config to

echo "{\"rules\":{\"eslint-plugin-require\": 2}}" > conf.json

nor

echo "{\"rules\":{\"require-define\": 2}}" > conf.json

nor

echo "{\"rules\":{\"require-require-define\": 2}}" > conf.json

nor

echo "{\"rules\":{\"eslint-plugin-require-define\": 2}}" > conf.json

nor

echo "{\"rules\":{\"eslint-plugin-require-require-define\": 2}}" > conf.json

does not fix it

How do I use locally installed eslint plugins?

like image 218
gman Avatar asked Jan 05 '15 03:01

gman


1 Answers

It is fairly simple to use local plugins with a local eslint install, just not immediately obvious at first.

1. Install

Nothing different here from what you're already doing.

npm install --save-dev eslint
npm install --save-dev eslint-plugin-require

2. Configure

I'm using a .eslintrc file in my case, but the same principle should apply if you're passing a custom config file to the CLI. Note the difference in how rules are defined when it's a plugin.

{
    "plugins": [
        // Tell eslint about the require plugin
        "require"
    ],
    "rules": {
        // Built-in Rules
        "camelcase": 2,
        "no-trailing-spaces": 2,

        // Require Plugin Rules (note plugin prefix)
        "require/require-define": 2,
        "require/require-array-syntax": 2,
        "require/require-module-prefix": 2
    }
}
like image 130
cvisco Avatar answered Nov 14 '22 02:11

cvisco