Lint

Lint filenames.

Usage

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

lint( [options,] clbk )

Asynchronously lints 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 files. May be either an absolute or relative directory path. Default: current working directory.
  • pattern: filename pattern. Default: '**/*'.

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

To limit the filename search to a subset of files, set the pattern option.

var opts = {
    'pattern': '**/*.js'
};

lint( opts, onLint );

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

lint.sync( [options] )

Synchronously lints 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.abc",
        "error": "filename must be lowercase."
    }
    
  • Only filenames which fail are returned.

Examples

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

lint( onLint );

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

CLI

Usage

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

Options:

  -h, --help             Print this message.
  -V, --version          Print the package version.
      --pattern pattern  Pattern to match files for linting.
      --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-filenames --split /\r?\n/
    
    # Escaped...
    $ <stdout> | lint-filenames --split /\\r?\\n/
    

Examples

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

To use as part of a standard stream pipeline,

$ echo -n $'beep.js\ta/b/c.md\tA.js' | lint-filenames --split /\\t/
{"name":"A.js","error":"filename must be lowercase."}