JavaScript project style linter
$ npm install --save clinton
const clinton = require('clinton');
clinton.lint('/Users/sam/projects/clinton', {rules: {'license': ['error', 'MIT']}}).then(validations => {
console.log(validations);
/*
[
{
ruleId: 'license',
severity: 'error',
message: 'License is not of type MIT (http://www.opensource.org/licenses/MIT).'
}
]
*/
});
Instead of passing the rules as an option, you can also add them to your package.json
file.
{
"name": "foo",
"license": "ISC",
"clinton": {
"rules": {
"license": ["error", "MIT"]
}
}
}
Type: string
Project path.
Type: object
Override any of the default rules.
Type: boolean
Default: true
Inherit from the default rules. Set to false
if you want to start with a clean sheet.
Type: string[]
List of plugin names.
Type: string[]
Paths in .gitignore
are ignored by default. Additional ignores can be added here.
Type: string
Current working directory when linting local projects.
Usage
$ clinton [<path>]
Options
--no-inherit Prevent inheriting from the default rules.
--ignores Ignore files. Can be added multiple times.
--fix Automatically fix problems.
Examples
$ clinton
.editorconfig
⚠ Use .editorconfig to define and maintain consistent coding styles between editors. editorconfig
1 warning
$ clinton ~/projects/project
license
✖ No MIT license found. license-mit
1 error
Tip: Use the config in
package.json
whenever possible for maintainability and to make it easier for eventual other tools to read the config.
.gitignore
. (fixable)devDependencies
when Gulp is detected.keywords
in package.json
.package.json
. (fixable)package.json
. (fixable)dependencies
and devDependencies
in package.json
. (fixable)engines.node
field in package.json
.package.json
. (fixable)package.json
.package.json
. (fixable).travis.yml
. (fixable)package.json
.package.json
.Everyone can create plugins or custom rules that can be validated with Clinton
. The name of the plugin should be
clinton-plugin-*
where *
is the name of the plugin.
Let's create a clinton-plugin-file-exists
rule that checks if the file provided as argument really exists.
'use strict';
module.exports = ctx => {
const fileName = ctx.options[0];
if (!ctx.files.includes(fileName)) {
ctx.report({
message: `File ${fileName} does not exist.`
});
}
};
You can also return a promise if you are performing asynchronous operations.
You can wrap this up in a project, publish it to npm and install it in every project where you want to check if a file in your project really exists.
{
"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"]
}
}
}
When running npm test
, clinton
will execute your plugin and will use index.js
as the option argument. The first that is passed to the plugin, error
in this example, indicates the severity of the error.
MIT © Sam Verschueren