SamVerschueren / clinton

Project style linter
MIT License
122 stars 9 forks source link

Unable to create a plugin #85

Closed brekk closed 6 years ago

brekk commented 6 years ago

Hi there,

I love the idea for this library, thank you for creating it.

I was following the basic outline of the example, but as I was attempting to write tests for my plugin module, I noticed that the internal definition for plugins: https://github.com/SamVerschueren/clinton/blob/master/lib/utils/rule.js#L7 defaults to an array, and the following line uses .indexOf to test for plugin matching. Relative to the example providing:

{
        "plugins": {
            "file-exists": ["error", "index.js"]
        }
}

How is one supposed to supply plugins to the config? If it's as an object, then I am concerned that the existing test (plugins.indexOf(ruleId)) will never match anything. If it's as an array, then I don't know how to pass configuration to it, and the example code is mismatched.

Could you provide a simple standalone example of how to create a plugin with tests?

If needed I can publish my example code.

SamVerschueren commented 6 years ago

You are right, I believe the docs are wrong. I'll look into it and get back to you.

brekk commented 6 years ago

Any update on this?

SamVerschueren commented 6 years ago

Sorry for the late reply and thanks for pinging me back, lost this one out of sight. The package.json example should be like this.

{
    "name": "Unicorn",
    "description": "My unicorn package",
    "version": "1.0.0",
    "scripts": {
        "test": "clinton"
    },
    "devDependencies": {
        "clinton": "*",
        "clinton-plugin-file-exists": "1.0.0"
    },
    "clinton": {
        "plugins": [
            "file-exists"
        ],
        "rules": {
            "file-exists": ["error", "index.js"]
        }
    }
}

So yes, the plugins list is an array and just defines the additional plugins. And then you have to enable them in the rules object and you can pass in some parameters.