gulp-patternlint
Pattern Lint is a generic plugin for linting any set of files for patterns, specified as either strings or regular expressions.
This can be used to enforce project-specific guidelines or team-specific practices on files in your projects, or anything that's too specific for more general, filetype-specific linters.
Usage
First, install gulp-patternlint
as a development dependency:
npm install --save-dev gulp-patternlint
Then, add it to your gulpfile.js
:
var patternlint = ; gulp;
API
Rule Configuration
You can pass rules as an array of objects.
gulp;
Strings
String
s should be specified as the pattern
property.
Regular Expressions
Regular expressions should be specified as the regexp
property. Please leave off the opening and closing slashes.
You can also add a flags property to specify additional regular expression flags. There is no need to add g: all rules get searched for globally.
gulp;
patternlintrc
Type: String
If no rules array is passed in, Pattern Lint will look for .patternlintrc
in the root of your project, where you can specify the rules as JSON (double-quotes, please). You can pass in a string to use a different rules file.
gulp ;
Results
Adds the following properties to the file object:
filepatternlintsuccess = true; // or falsefilepatternlinterrorCount = 0; // number of errors returned by PatternLintfilepatternlintresults = ; // PatternLint errorsfilepatternlintrules = {}; // The rules you passed to PatternLint
Custom Reporters
Pattern Lint has a lovely default reporter that sends output to your gulp process with information about linting problems. But if you'd like to make your own, custom reporter functions can be passed as patternlint.reporter(reporterFunc)
. The reporter function will be called for each linted file and passed the file object as described above.
var patternlint = ;var gutil = ; var { gutil; filepatternlintresults;}; gulp;
Acknowledgements
This plugin is almost a fork of @lazd's gulp-csslint plugin, which I used as a model to learn how to write a Gulp plugin.