Skip to content

Latest commit

 

History

History
244 lines (161 loc) · 5.95 KB

File metadata and controls

244 lines (161 loc) · 5.95 KB

Lint

Lint manifest.json dependencies to ensure all required packages are listed.

Usage

var lint = require( '@stdlib/_tools/lint/manifest-json-deps' );

lint( [options,] clbk )

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, and dependency fields.

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.' );
    }
}

lint.sync( [options] )

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.

Notes

  • The linter analyzes C source files (.c) for #include "stdlib/..." directives and maps each include path to an @stdlib package name.
  • The mapping converts underscores in header paths to hyphens in package names (e.g., stdlib/napi/argv_double.h maps to @stdlib/napi/argv-double).
  • For build configurations (non-WASM), the linter also scans src/addon.c if present, as it is compiled during builds but not listed in the manifest's src array.
  • Self-references (a package including its own headers) are automatically excluded.
  • Fortran files (.f) are skipped as they do not contain #include directives.

Examples

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.' );
    }
}

CLI

Usage

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/.

Notes

  • If part of a standard stream pipeline, results are written to stdout as newline-delimited JSON (NDJSON). Otherwise, results are pretty printed by default.

  • If not provided a dir argument, the current working directory is the search directory.

  • To provide multiple exclusion glob patterns, set multiple --ignore option arguments.

    $ lint-manifest-json-deps --ignore=node_modules/** --ignore=build/** --ignore=reports/**

Examples

$ 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 errors

To 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"}
...