Lint manifest.json dependencies to ensure all required packages are listed.
var lint = require( '@stdlib/_tools/lint/manifest-json-deps' );Asynchronously lints manifest.json dependencies by analyzing C source file #include directives and verifying that the corresponding @stdlib packages are listed in each configuration's dependencies array.
lint( onLint );
function onLint( error, errs ) {
if ( error ) {
throw error;
}
if ( errs && errs.length ) {
console.error( JSON.stringify( errs ) );
} else {
console.log( 'No detected errors.' );
}
}The function accepts the following options:
- dir: root directory from which to search for manifest.json files. May be either an absolute file path or a path relative to the current working directory. Default: current working directory.
- pattern: glob pattern for finding manifest.json files. Default:
**/@stdlib/**/manifest.json. - ignore: glob pattern(s) to exclude.
Each lint error is represented by an object having the following fields:
- file: manifest.json file path.
- errors: array of error objects, each with
message,conf, anddependencyfields.
To lint starting from a descendant directory, set the dir option.
var opts = {
'dir': '/foo/bar/baz'
};
lint( opts, onLint );
function onLint( error, errs ) {
if ( error ) {
throw error;
}
if ( errs && errs.length ) {
console.error( JSON.stringify( errs ) );
} else {
console.log( 'No detected errors.' );
}
}Synchronously lints manifest.json dependencies.
var errs = lint.sync();
if ( errs && errs.length ) {
console.error( JSON.stringify( errs ) );
} else {
console.log( 'No detected errors.' );
}The function accepts the same options as lint() above.
- The linter analyzes C source files (
.c) for#include "stdlib/..."directives and maps each include path to an@stdlibpackage name. - The mapping converts underscores in header paths to hyphens in package names (e.g.,
stdlib/napi/argv_double.hmaps to@stdlib/napi/argv-double). - For
buildconfigurations (non-WASM), the linter also scanssrc/addon.cif present, as it is compiled during builds but not listed in the manifest'ssrcarray. - Self-references (a package including its own headers) are automatically excluded.
- Fortran files (
.f) are skipped as they do not contain#includedirectives.
var lint = require( '@stdlib/_tools/lint/manifest-json-deps' );
var opts = {
'dir': './',
'pattern': '**/@stdlib/math/**/manifest.json'
};
lint( opts, onLint );
function onLint( error, errors ) {
if ( error ) {
throw error;
}
if ( errors && errors.length ) {
console.error( JSON.stringify( errors ) );
} else {
console.log( 'No detected errors.' );
}
}Usage: lint-manifest-json-deps [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 fmt Output format: 'pretty' or 'ndjson'. Default: '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-manifest-json-deps --ignore=node_modules/** --ignore=build/** --ignore=reports/**
$ lint-manifest-json-deps
/path/to/lib/node_modules/@stdlib/math/base/special/abs/manifest.json
message: Missing dependency "@stdlib/napi/argv-double" in conf [task:build, wasm:false].
conf: task:build, wasm:false
dependency: @stdlib/napi/argv-double
1 errorsTo output results as newline-delimited JSON (NDJSON),
$ lint-manifest-json-deps --format ndjson
{"file":"/path/to/manifest.json","message":"Missing dependency...","conf":"task:build","dependency":"@stdlib/napi/argv-double"}
...