Lint
package.jsonfiles.
var lint = require( '@stdlib/_tools/lint/pkg-json' );Asynchronously lints package.json files.
lint( done );
function done( error, errs ) {
if ( error ) {
throw error;
}
if ( errs ) {
console.dir( errs );
} else {
console.log( 'Success!' );
}
}The function accepts the following options:
- dir: root directory from which to search for packages. May be either an absolute file path or a path relative to the current working directory. Default: current working directory.
- pattern: glob pattern used to find packages. Default:
'**/package.json'(note: pattern must end withpackage.json). - ignore: list of glob patterns used to exclude matches.
To search from an alternative directory, set the dir option.
var opts = {
'dir': '/foo/bar/baz'
};
lint( opts, done );
function done( error, errs ) {
if ( error ) {
throw error;
}
if ( errs ) {
console.dir( errs );
} else {
console.log( 'Success!' );
}
}To provide an alternative include filter, set the pattern option.
var opts = {
'pattern': '**/foo/**/package.json'
};
lint( opts, done );
function done( error, errs ) {
if ( error ) {
throw error;
}
if ( errs ) {
console.dir( errs );
} else {
console.log( 'Success!' );
}
}To exclude matches, set the ignore option.
var opts = {
'ignore': [
'node_modules/**',
'build/**',
'reports/**'
]
};
lint( opts, done );
function done( error, errs ) {
if ( error ) {
throw error;
}
if ( errs ) {
console.dir( errs );
} else {
console.log( 'Success!' );
}
}Synchronously lints package.json files.
var errs = lint.sync();
if ( errs ) {
console.dir( errs );
} else {
console.log( 'Success!' );
}The function accepts the same options as lint() above.
var lint = require( '@stdlib/_tools/lint/pkg-json' );
lint( done );
function done( error, errs ) {
if ( error ) {
throw error;
}
if ( errs ) {
console.dir( errs );
} else {
console.log( 'Success!' );
}
}Usage: lint-pkg-json [options] [dir]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--pattern pattern Inclusion glob pattern.
--ignore pattern Exclusion glob pattern.
--format format Output format: ndjson, pretty.
--split sep Separator used to split stdin data. Default: /\\r?\\n/.
-
If part of a standard stream pipeline, results are written to
stdoutas newline-delimited JSON (NDJSON). Otherwise, results are pretty printed by default. -
If not provided a
dirargument, the current working directory is the search directory. -
To provide multiple exclusion glob patterns, set multiple
--ignoreoption arguments.$ lint-pkg-json --ignore=node_modules/** --ignore=build/** --ignore=reports/**
-
If the split separator is a regular expression, ensure that the
splitoption is properly escaped.# Not escaped... $ <stdout> | lint-pkg-json --split /\r?\n/ # Escaped... $ <stdout> | lint-pkg-json --split /\\r?\\n/
-
If provided a list of filenames via
stdin, each filename is resolved relative to the current working directory. To specify an alternative directory, provide adirargument.
$ lint-pkg-json
/path/to/package.json
message: should NOT have duplicate items (items ## 3 and 4 are identical)
field: .keywords
data: ["stdlib","tools","json","package","package","pkg","package.json","meta","validate","valid","check","test","isvalid","is","lint"]
message: should be object
field: .dependencies
data: null
message: should NOT have additional properties
field: .engines
data: {"":">=0.10.0"}
3 errorsTo output results as newline-delimited JSON (NDJSON),
$ lint-pkg-json --format ndjson
{"file":"...","errors":[...]}
{"file":"...","errors":[...]}
...To use as a part of a standard stream pipeline,
$ echo -n $'./package.json' | lint-pkg-json
...