Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 244 additions & 0 deletions lib/node_modules/@stdlib/_tools/lint/manifest-json-deps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Lint

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

<section class="usage">

## Usage

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
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.

</section>

<!-- /.usage -->

<section class="notes">

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

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

</section>

<!-- /.examples -->

* * *

<section class="cli">

## CLI

<section class="usage">

### Usage

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

</section>

<!-- /.usage -->

<section class="notes">

### Notes

- If part of a [standard stream][standard-stream] pipeline, results are written to `stdout` as newline-delimited JSON ([NDJSON][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.

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

</section>

<!-- /.notes -->

<section class="examples">

### Examples

```bash
$ 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][ndjson]),

```bash
$ lint-manifest-json-deps --format ndjson
{"file":"/path/to/manifest.json","message":"Missing dependency...","conf":"task:build","dependency":"@stdlib/napi/argv-double"}
...
```

</section>

<!-- /.examples -->

</section>

<!-- /.cli -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[ndjson]: http://ndjson.org/

[standard-stream]: https://en.wikipedia.org/wiki/Pipeline_%28Unix%29

</section>

<!-- /.links -->
Loading
Loading