|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Lint |
| 22 | + |
| 23 | +> Lint `manifest.json` files. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var lint = require( '@stdlib/_tools/lint/manifest-json' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### lint( \[options,] clbk ) |
| 34 | + |
| 35 | +Asynchronously lints `manifest.json` files. |
| 36 | + |
| 37 | +```javascript |
| 38 | +lint( done ); |
| 39 | + |
| 40 | +function done( error, errs ) { |
| 41 | + if ( error ) { |
| 42 | + throw error; |
| 43 | + } |
| 44 | + if ( errs ) { |
| 45 | + console.dir( errs ); |
| 46 | + } else { |
| 47 | + console.log( 'Success!' ); |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +The function accepts the following `options`: |
| 53 | + |
| 54 | +- **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. |
| 55 | +- **pattern**: glob pattern used to find manifest.json files. Default: `'**/@stdlib/**/manifest.json'` (note: pattern **must** end with `manifest.json`). |
| 56 | +- **ignore**: list of glob patterns used to exclude matches. |
| 57 | + |
| 58 | +To search from an alternative directory, set the `dir` option. |
| 59 | + |
| 60 | +```javascript |
| 61 | +var opts = { |
| 62 | + 'dir': '/foo/bar/baz' |
| 63 | +}; |
| 64 | + |
| 65 | +lint( opts, done ); |
| 66 | + |
| 67 | +function done( error, errs ) { |
| 68 | + if ( error ) { |
| 69 | + throw error; |
| 70 | + } |
| 71 | + if ( errs ) { |
| 72 | + console.dir( errs ); |
| 73 | + } else { |
| 74 | + console.log( 'Success!' ); |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +To provide an alternative include filter, set the `pattern` option. |
| 80 | + |
| 81 | +```javascript |
| 82 | +var opts = { |
| 83 | + 'pattern': '**/@stdlib/math/**/manifest.json' |
| 84 | +}; |
| 85 | + |
| 86 | +lint( opts, done ); |
| 87 | + |
| 88 | +function done( error, errs ) { |
| 89 | + if ( error ) { |
| 90 | + throw error; |
| 91 | + } |
| 92 | + if ( errs ) { |
| 93 | + console.dir( errs ); |
| 94 | + } else { |
| 95 | + console.log( 'Success!' ); |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +To exclude matches, set the `ignore` option. |
| 101 | + |
| 102 | +```javascript |
| 103 | +var opts = { |
| 104 | + 'ignore': [ |
| 105 | + 'node_modules/**', |
| 106 | + 'build/**', |
| 107 | + 'reports/**' |
| 108 | + ] |
| 109 | +}; |
| 110 | + |
| 111 | +lint( opts, done ); |
| 112 | + |
| 113 | +function done( error, errs ) { |
| 114 | + if ( error ) { |
| 115 | + throw error; |
| 116 | + } |
| 117 | + if ( errs ) { |
| 118 | + console.dir( errs ); |
| 119 | + } else { |
| 120 | + console.log( 'Success!' ); |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +#### lint.sync( \[options] ) |
| 126 | + |
| 127 | +Synchronously lints `manifest.json` files. |
| 128 | + |
| 129 | +```javascript |
| 130 | +var errs = lint.sync(); |
| 131 | +if ( errs ) { |
| 132 | + console.dir( errs ); |
| 133 | +} else { |
| 134 | + console.log( 'Success!' ); |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +The function accepts the same `options` as `lint()` above. |
| 139 | + |
| 140 | +</section> |
| 141 | + |
| 142 | +<!-- /.usage --> |
| 143 | + |
| 144 | +<section class="notes"> |
| 145 | + |
| 146 | +</section> |
| 147 | + |
| 148 | +<!-- /.notes --> |
| 149 | + |
| 150 | +<section class="examples"> |
| 151 | + |
| 152 | +## Examples |
| 153 | + |
| 154 | +<!-- eslint no-undef: "error" --> |
| 155 | + |
| 156 | +```javascript |
| 157 | +var lint = require( '@stdlib/_tools/lint/manifest-json' ); |
| 158 | + |
| 159 | +lint( done ); |
| 160 | + |
| 161 | +function done( error, errs ) { |
| 162 | + if ( error ) { |
| 163 | + throw error; |
| 164 | + } |
| 165 | + if ( errs ) { |
| 166 | + console.dir( errs ); |
| 167 | + } else { |
| 168 | + console.log( 'Success!' ); |
| 169 | + } |
| 170 | +} |
| 171 | +``` |
| 172 | + |
| 173 | +</section> |
| 174 | + |
| 175 | +<!-- /.examples --> |
| 176 | + |
| 177 | +* * * |
| 178 | + |
| 179 | +<section class="cli"> |
| 180 | + |
| 181 | +## CLI |
| 182 | + |
| 183 | +<section class="usage"> |
| 184 | + |
| 185 | +### Usage |
| 186 | + |
| 187 | +```text |
| 188 | +Usage: lint-manifest-json [options] [dir] |
| 189 | +
|
| 190 | +Options: |
| 191 | +
|
| 192 | + -h, --help Print this message. |
| 193 | + -V, --version Print the package version. |
| 194 | + --pattern pattern Inclusion glob pattern. |
| 195 | + --ignore pattern Exclusion glob pattern. |
| 196 | + --format format Output format: ndjson, pretty. |
| 197 | + --split sep Separator used to split stdin data. Default: /\\r?\\n/. |
| 198 | +``` |
| 199 | + |
| 200 | +</section> |
| 201 | + |
| 202 | +<!-- /.usage --> |
| 203 | + |
| 204 | +<section class="notes"> |
| 205 | + |
| 206 | +### Notes |
| 207 | + |
| 208 | +- 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. |
| 209 | + |
| 210 | +- If not provided a `dir` argument, the current working directory is the search directory. |
| 211 | + |
| 212 | +- To provide multiple exclusion glob patterns, set multiple `--ignore` option arguments. |
| 213 | + |
| 214 | + ```bash |
| 215 | + $ lint-manifest-json --ignore=node_modules/** --ignore=build/** --ignore=reports/** |
| 216 | + ``` |
| 217 | + |
| 218 | +- If the split separator is a [regular expression][regexp], ensure that the `split` option is properly **escaped**. |
| 219 | + |
| 220 | + ```bash |
| 221 | + # Not escaped... |
| 222 | + $ <stdout> | lint-manifest-json --split /\r?\n/ |
| 223 | +
|
| 224 | + # Escaped... |
| 225 | + $ <stdout> | lint-manifest-json --split /\\r?\\n/ |
| 226 | + ``` |
| 227 | + |
| 228 | +- If provided a list of filenames via `stdin`, each filename is resolved relative to the current working directory. To specify an alternative directory, provide a `dir` argument. |
| 229 | + |
| 230 | +</section> |
| 231 | + |
| 232 | +<!-- /.notes --> |
| 233 | + |
| 234 | +<section class="examples"> |
| 235 | + |
| 236 | +### Examples |
| 237 | + |
| 238 | +```bash |
| 239 | +$ lint-manifest-json |
| 240 | +
|
| 241 | +/path/to/manifest.json |
| 242 | +
|
| 243 | + message: should have required property 'confs' |
| 244 | + field: . |
| 245 | + data: {"options":{},"fields":[]} |
| 246 | +
|
| 247 | +1 errors |
| 248 | +``` |
| 249 | + |
| 250 | +To output results as newline-delimited JSON ([NDJSON][ndjson]), |
| 251 | + |
| 252 | +```bash |
| 253 | +$ lint-manifest-json --format ndjson |
| 254 | +{"file":"...","errors":[...]} |
| 255 | +{"file":"...","errors":[...]} |
| 256 | +... |
| 257 | +``` |
| 258 | + |
| 259 | +To use as a part of a [standard stream][standard-stream] pipeline, |
| 260 | + |
| 261 | +```bash |
| 262 | +$ echo -n $'./manifest.json' | lint-manifest-json |
| 263 | +... |
| 264 | +``` |
| 265 | + |
| 266 | +</section> |
| 267 | + |
| 268 | +<!-- /.examples --> |
| 269 | + |
| 270 | +</section> |
| 271 | + |
| 272 | +<!-- /.cli --> |
| 273 | + |
| 274 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 275 | + |
| 276 | +<section class="related"> |
| 277 | + |
| 278 | +</section> |
| 279 | + |
| 280 | +<!-- /.related --> |
| 281 | + |
| 282 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 283 | + |
| 284 | +<section class="links"> |
| 285 | + |
| 286 | +[ndjson]: http://ndjson.org/ |
| 287 | + |
| 288 | +[regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions |
| 289 | + |
| 290 | +[standard-stream]: https://en.wikipedia.org/wiki/Pipeline_%28Unix%29 |
| 291 | + |
| 292 | +</section> |
| 293 | + |
| 294 | +<!-- /.links --> |
0 commit comments