• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Project style linter

clinton

Build Status: Linux Build status: Windows Coverage Status

JavaScript project style linter

Install

$ npm install --save clinton

Usage

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"]
		}
	}
}

API

.lint(path, [options])

path

Type: string

Project path.

options

rules

Type: object

Override any of the default rules.

inherit

Type: boolean
Default: true

Inherit from the default rules. Set to false if you want to start with a clean sheet.

plugins

Type: string[]

List of plugin names.

ignores

Type: string[]

Paths in .gitignore are ignored by default. Additional ignores can be added here.

cwd

Type: string

Current working directory when linting local projects.

CLI

    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.

Rules

  • ava - Enforces the use of AVA. (fixable)
  • cli - Enforces the existance and executability of the cli file.
  • editorconfig - Enforces the use and rules of EditorConfig.
  • filename-case - Enforce a case style for filenames.
  • gitignore - Enforce the use of .gitignore. (fixable)
  • gulp - Enforces the correct devDependencies when Gulp is detected.
  • keywords - Enforces the use of keywords in package.json.
  • license - Enforce the use of a specific license.
  • max-depth - Enforce the maximum depth of the directory structure.
  • no-callback - Enforces the use of promises instead of callbacks.
  • no-dup-keywords - Enforce not having duplicate keywords in package.json. (fixable)
  • no-empty-keywords - Enforce not having empty keywords in package.json. (fixable)
  • no-git-merge-conflict - Prevents having Git merge conflict markers.
  • pkg-dependency-order - Enforces alphabetical order of dependencies and devDependencies in package.json. (fixable)
  • pkg-description - Enforces the description to start with a capital letter and not end with a dot. (fixable)
  • pkg-engine - Enforces the use of a engines.node field in package.json.
  • pkg-main - Enforces the existance of the main file.
  • pkg-name - Enforces a valid package name.
  • pkg-normalize - Enforces package normalization. (fixable)
  • pkg-property-order - Enforces order of properties in in package.json. (fixable)
  • pkg-schema - Enforces a valid package.json.
  • pkg-shorthand-repository - Enforces the use of the shorthand repository URL. (fixable)
  • pkg-user-order - Enforces order of properties in user objects in package.json. (fixable)
  • readme - Enforce having a readme.
  • test-script - Enforces the use of tests.
  • travis - Enforces the correct versions in .travis.yml. (fixable)
  • use-travis - Enforces the use of Travis CI.
  • valid-properties - Enforce recommended properties in package.json.
  • valid-version - Enforces a valid version identifier in package.json.
  • xo - Enforces the use of XO. (fixable)

Plugins

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.

Example

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.

Related

License

MIT © Sam Verschueren

More Repositories

1

listr

Terminal task list
JavaScript
3,194
star
2

tsd

Check TypeScript type definitions
TypeScript
2,116
star
3

alfred-fkill

Alfred 3 workflow to fabulously search and kill processes
JavaScript
473
star
4

dev-time-cli

Get the current local time of a GitHub user.
JavaScript
181
star
5

generator-alfred

Scaffold out an Alfred workflow
JavaScript
169
star
6

babel-engine-plugin

Webpack plugin that transpiles dependencies targeting Node.js versions newer than Node.js 0.10
JavaScript
166
star
7

decode-uri-component

A better decodeURIComponent
JavaScript
144
star
8

alfred-updater

Alfred workflow updater
JavaScript
107
star
9

mobicon-cli

Mobile icon generator
JavaScript
102
star
10

expiry-map

A Map implementation with expirable items
TypeScript
92
star
11

vscode-yo

Yeoman plugin for VS Code
TypeScript
88
star
12

uppercamelcase

Convert a dash/dot/underscore/space separated string to UpperCamelCase: foo-bar → FooBar
JavaScript
81
star
13

vscode-ava

Snippets for AVA
72
star
14

alfred-notifier

Update notifications for your Alfred workflow
JavaScript
71
star
15

alfred-link

Make your Alfred workflows installable from npm
JavaScript
68
star
16

mobisplash-cli

Mobile app splash screen generator
JavaScript
65
star
17

clean-regexp

Clean up regular expressions
JavaScript
61
star
18

dynongo

MongoDB like syntax for DynamoDB
TypeScript
58
star
19

dev-time

Get the current local time of a GitHub user.
JavaScript
57
star
20

aws-lambda-mock-context

AWS Lambda mock context object
JavaScript
52
star
21

mongoose-seeder

Seed your MongoDB database easily
JavaScript
48
star
22

bragg

AWS λ web framework
JavaScript
47
star
23

ngx-ow

Angular form validation on steroids
TypeScript
45
star
24

mobisplash

Mobile app splash screen generator
JavaScript
45
star
25

alfred-ng

Search through the Angular documentation on angular.io
JavaScript
44
star
26

obsify

Observableify a callback-style function
JavaScript
41
star
27

alfred-config

Allow easy user configurations for your Alfred workflows
JavaScript
41
star
28

gulp-cordova

Documentation of gulp-cordova
40
star
29

ngx-monaco

Monaco Editor for Angular
TypeScript
39
star
30

alfred-font-awesome

Alfred workflow to search for font-awesome icons
JavaScript
37
star
31

listr-update-renderer

Listr update renderer
JavaScript
37
star
32

listr-input

Input module for Listr
JavaScript
33
star
33

aws-lambda-stop-server

AWS Lambda function that will stop servers.
JavaScript
32
star
34

alfred-rxjs

Search through the RxJS documentation
JavaScript
29
star
35

angular2-polyfill

Angular2 polyfill for Angular1
TypeScript
29
star
36

got4aws

Convenience wrapper for Got to interact with AWS v4 signed APIs
TypeScript
27
star
37

observable-conf

Listen for changes in your conf config
JavaScript
27
star
38

aws-lambda-start-server

AWS Lambda function that will start servers.
TypeScript
25
star
39

mobicon

Mobile icon generator
JavaScript
25
star
40

kap-s3

Kap plugin - Share on Amazon S3
JavaScript
25
star
41

tsd-typescript

TypeScript with some extras for type-checking.
JavaScript
22
star
42

vscode-final-newline

Inserts a final newline when saving the document.
TypeScript
22
star
43

aws-lambda-invoke

Invoke AWS Lambda functions with ease
JavaScript
22
star
44

cache-conf

Simple cache config handling for your app or module
JavaScript
21
star
45

alfy-test

Test your Alfy workflows
JavaScript
21
star
46

alfred-aws

Search through the AWS JavaScript SDK
JavaScript
21
star
47

alfred-node

Alfred 3 workflow to search for Node.js documentation
JavaScript
19
star
48

map-age-cleaner

Cleanup expired items in a Map
TypeScript
18
star
49

expiry-set

A Set implementation with expirable keys
TypeScript
16
star
50

stats-map

Map that keeps track of the hits and misses
JavaScript
16
star
51

generator-aws-lambda

Scaffold out an AWS Lambda module.
JavaScript
16
star
52

gulp-cordova-build-android

Gulp plugin for building an android Cordova project
JavaScript
14
star
53

vinyl-read

Create vinyl files from glob patterns
JavaScript
13
star
54

cordova-config

Parse and edit the config.xml file of a cordova project
JavaScript
13
star
55

listr-verbose-renderer

Listr verbose renderer
JavaScript
13
star
56

obj-clean

Remove empty objects, empty strings, null and undefined values from objects.
JavaScript
12
star
57

aws-sns-publish

Publish messages to AWS SNS
JavaScript
12
star
58

vali-date

Validate a date
JavaScript
12
star
59

resolve-alfred-prefs

Resolve the path of Alfred.alfredpreferences
JavaScript
11
star
60

dynamo-seeder

Seed your DynamoDB database easily
JavaScript
11
star
61

angular-ga

Google Analytics for your Angular application
TypeScript
11
star
62

tz-format

Format a date with timezone
JavaScript
10
star
63

ng2-hello-world

Angular2 Hello World starter application
JavaScript
10
star
64

rfpify

[DEPRECATED] Promisify a result-first callback function.
JavaScript
10
star
65

aws-lambda-pify

Promisify an AWS lambda function.
JavaScript
9
star
66

get-gravatar-cli

Get a Gravatar image
JavaScript
9
star
67

kap-plugin-test

Test your Kap plugins
JavaScript
9
star
68

gulp-api-doc

RESTful web API Documentation Generator for Gulp
JavaScript
9
star
69

alfred-css-triggers

Alfred workflow to search through csstriggers.com
JavaScript
8
star
70

listr-silent-renderer

Supress Listr rendering output
JavaScript
8
star
71

ngx-api-gateway-client

AWS API Gateway Client for Angular
TypeScript
8
star
72

travis-got

Convenience wrapper for `got` to interact with the Travis API
JavaScript
7
star
73

github-parse-link

Parse GitHub `link` header response
JavaScript
7
star
74

npm-publish-index-test

JavaScript
6
star
75

kap-plugin-mock-context

Kap plugin mock context
JavaScript
6
star
76

parse-aws-lambda-name

Parse an AWS Lambda function name into a name and a qualifier
JavaScript
6
star
77

beRail

beRail is a BlackBerry 10 application for the belgian railways.
C++
5
star
78

promise-concurrent

Execute a list of promises with a limited concurrency
JavaScript
5
star
79

alfred-ionic

Search through the Ionic documentation
JavaScript
5
star
80

capture-pdf

Capture html in a pdf buffer
JavaScript
5
star
81

BB10-OAuth

OAuth framework for BlackBerry10
C++
5
star
82

latest-push

Get the latest push of a GitHub user.
JavaScript
5
star
83

node-mongoose-validator

Easily validate mongoose schema paths.
JavaScript
5
star
84

gulp-cordova-plugin

This library adds a cordova plugin to the cordova project
JavaScript
4
star
85

string-occurrence

Get the number of occurrences of a string in a string
JavaScript
4
star
86

sam-playground

JavaScript
4
star
87

dynongo-pager

Easy paging for DynamoDB with dynongo
TypeScript
4
star
88

ng2-hello-world-lazy-routing

Angular2 Hello World lazy routing application
JavaScript
4
star
89

gh-lint-brainstorm

Brainstorming repository for a repository linter
4
star
90

regex-occurrence

Get the number of occurrences of a RegExp in a string
JavaScript
4
star
91

is-d

Check if a file is a directory
JavaScript
3
star
92

Take-A-Look-Inside-Web

Web version for take a look inside
JavaScript
3
star
93

gulp-cordova-build-ios

Gulp plugin for building an iOS Cordova project
JavaScript
3
star
94

dynamo-discovery-service

Discovery service like etcd but implemented with DynamoDB
JavaScript
3
star
95

lambda-update-alias

Update or create a AWS lambda alias
JavaScript
2
star
96

dynamo-discovery-service-cli

CLI for the discovery service
JavaScript
2
star
97

amplify-starter

JavaScript
2
star
98

get-exec-file

Promisify execFile
JavaScript
2
star
99

angular2-polyfill-heroes

Tour of Heroes implementation with angular2-polyfill
TypeScript
2
star
100

bragg-sns

SNS middleware for bragg
JavaScript
2
star