Lint

Lint stdlib header filenames.

Usage

var lint = require( '@stdlib/_tools/lint/header-filenames' );

lint( [options,] clbk )

Asynchronously lints header filenames.

lint( onLint );

function onLint( error, errs ) {
    if ( error ) {
        throw error;
    }
    console.error( JSON.stringify( errs ) );
}

The function accepts the following options:

  • dir: root directory from which to search for header files. May be either an absolute or relative directory path. Default: current working directory.

To search from a specific directory, set the dir option.

var opts = {
    'dir': './'
};

lint( opts, onLint );

function onLint( error, errs ) {
    if ( error ) {
        throw error;
    }
    console.error( JSON.stringify( errs ) );
}

lint.sync( [options] )

Synchronously lints header filenames.

var errs = lint.sync();
// returns [...]

The function accepts the same options as lint() above.

Notes

  • If all filenames are valid, the returned result is an empty array.

  • Each failure is returned as an object with the following properties:

    • name: filename.
    • error: reason for failure.
    {
        "name": "path/to/failing/filename.h",
        "error": "duplicate header filename."
    }
    
  • Only filenames which fail are returned.

Examples

var lint = require( '@stdlib/_tools/lint/header-filenames' );

lint( onLint );

function onLint( error, errs ) {
    if ( error ) {
        throw error;
    }
    console.error( JSON.stringify( errs ) );
}

CLI

Usage

Usage: lint-header-filenames [options] [<dir>]

Options:

  -h,    --help          Print this message.
  -V,    --version       Print the package version.
         --split sep     Separator used to split stdin data. Default: /\\r?\\n/.

Notes

  • Filenames which fail are printed to stderr as newline-delimited JSON (NDJSON).

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

  • If the split separator is a regular expression, ensure that the split option is properly escaped.

    # Not escaped...
    $ <stdout> | lint-header-filenames --split /\r?\n/
    
    # Escaped...
    $ <stdout> | lint-header-filenames --split /\\r?\\n/
    

Examples

$ lint-header-filenames
{...}
{...}
...

To use as part of a standard stream pipeline,

$ echo -n $'beep.h\ta/b/c.h\tc.h' | lint-header-filenames --split /\\t/
{"name":"a/b/c.h","error":"duplicate header filename."}
{"name":"c.h","error":"duplicate header filename."}