You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/_tools/lint/pkg-json-names/README.md
+70-18Lines changed: 70 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ limitations under the License.
20
20
21
21
# Lint
22
22
23
-
> Lint @stdlibpackage.json names to ensure they match their directory location.
23
+
> Lint package.json names to ensure they match their directory location.
24
24
25
25
<sectionclass="usage">
26
26
@@ -32,7 +32,7 @@ var lint = require( '@stdlib/_tools/lint/pkg-json-names' );
32
32
33
33
#### lint( \[options,] clbk )
34
34
35
-
Asynchronously lints @stdlibpackage.json names to ensure that each package name matches its directory location within the stdlib project structure.
35
+
Asynchronously lints package.json names to ensure that each package name matches its directory location within the project structure.
36
36
37
37
```javascript
38
38
lint( onLint );
@@ -41,7 +41,7 @@ function onLint( error, errs ) {
41
41
if ( error ) {
42
42
throw error;
43
43
}
44
-
if ( errs.length ) {
44
+
if ( errs&&errs.length ) {
45
45
console.error( JSON.stringify( errs ) );
46
46
} else {
47
47
console.log( 'No detected errors.' );
@@ -51,22 +51,22 @@ function onLint( error, errs ) {
51
51
52
52
The function accepts the following `options`:
53
53
54
-
-**dir**: root directory from which to search for @stdlib package.json files to lint. May be either an absolute file path or a path relative to the `stdlib/lib/node_modules/`directory. Default: `/path/to/stdlib/lib/node_modules/`.
55
-
-**pattern**: glob pattern for finding @stdlibpackage.json files. Default: `**/@stdlib/**/package.json`.
54
+
-**dir**: root directory from which to search for packages. May be either an absolute file path or a path relative to the current working directory. Default: current working directory.
55
+
-**pattern**: glob pattern for finding package.json files. Default: `**/@stdlib/**/package.json`.
56
56
-**ignore**: glob pattern(s) to exclude.
57
57
58
58
Each lint error is represented by an `object` having the following fields:
59
59
60
-
-**file**: @stdlibpackage.json file path.
61
-
-**expected**: expected @stdlibpackage name based on directory location.
60
+
-**file**: package.json file path.
61
+
-**expected**: expected package name based on directory location.
62
62
-**actual**: actual package name found in package.json.
63
63
-**message**: error message describing the mismatch.
64
64
65
65
To lint starting from a descendant directory, set the `dir` option.
66
66
67
67
```javascript
68
68
var opts = {
69
-
'dir':'./@stdlib/math/base'
69
+
'dir':'/foo/bar/baz'
70
70
};
71
71
72
72
lint( opts, onLint );
@@ -75,7 +75,7 @@ function onLint( error, errs ) {
75
75
if ( error ) {
76
76
throw error;
77
77
}
78
-
if ( errs.length ) {
78
+
if ( errs&&errs.length ) {
79
79
console.error( JSON.stringify( errs ) );
80
80
} else {
81
81
console.log( 'No detected errors.' );
@@ -85,11 +85,11 @@ function onLint( error, errs ) {
85
85
86
86
#### lint.sync( \[options] )
87
87
88
-
Synchronously lints @stdlibpackage.json names to ensure that each package name matches its directory location within the stdlib project structure.
88
+
Synchronously lints package.json names to ensure that each package name matches its directory location within the project structure.
89
89
90
90
```javascript
91
91
var errs =lint.sync();
92
-
if ( errs.length ) {
92
+
if ( errs&&errs.length ) {
93
93
console.error( JSON.stringify( errs ) );
94
94
} else {
95
95
console.log( 'No detected errors.' );
@@ -107,9 +107,8 @@ The function accepts the same `options` as `lint()` above.
107
107
## Notes
108
108
109
109
- The function only lints packages under the `@stdlib` scope.
110
-
-@stdlib package names must start with `@stdlib/` and match their directory location exactly.
110
+
-Package names must start with `@stdlib/` and match their directory location exactly.
111
111
- For example, a package located at `lib/node_modules/@stdlib/math/base/special/abs/` must be named `@stdlib/math/base/special/abs`.
112
-
- The tool validates that the package name corresponds to the actual directory structure within the stdlib project.
113
112
114
113
</section>
115
114
@@ -125,7 +124,8 @@ The function accepts the same `options` as `lint()` above.
125
124
var lint =require( '@stdlib/_tools/lint/pkg-json-names' );
126
125
127
126
var opts = {
128
-
'dir':'./'
127
+
'dir':'./',
128
+
'pattern':'**/@stdlib/utils/**/package.json'
129
129
};
130
130
131
131
lint( opts, onLint );
@@ -134,7 +134,7 @@ function onLint( error, errors ) {
134
134
if ( error ) {
135
135
throw error;
136
136
}
137
-
if ( errors.length ) {
137
+
if ( errors&&errors.length ) {
138
138
console.error( JSON.stringify( errors ) );
139
139
} else {
140
140
console.log( 'No detected errors.' );
@@ -157,14 +157,16 @@ function onLint( error, errors ) {
--pattern pattern Pattern to match files for linting.
167
167
--ignore pattern Exclusion glob pattern.
168
+
--split sep Separator used to split stdin data. Default: /\\r?\\n/.
169
+
--format fmt Output format: 'pretty' or 'ndjson'. Default: 'pretty'.
168
170
```
169
171
170
172
</section>
@@ -175,7 +177,28 @@ Options:
175
177
176
178
### Notes
177
179
178
-
- If not provided a `dir` argument, the search directory is the current working directory.
180
+
181
+
- 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.
182
+
183
+
- If not provided a `dir` argument, the current working directory is the search directory.
184
+
185
+
- To provide multiple exclusion glob patterns, set multiple `--ignore` option arguments.
- If the split separator is a [regular expression][regexp], ensure that the `split` option is properly **escaped**.
192
+
193
+
```bash
194
+
# Not escaped...
195
+
$ <stdout>| lint-pkg-json-names --split /\r?\n/
196
+
197
+
# Escaped...
198
+
$ <stdout>| lint-pkg-json-names --split /\\r?\\n/
199
+
```
200
+
201
+
- 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.
message: Package name "@stdlib/math/base/special/sin" does not match directory structure (expected: "@stdlib/math/base/special/abs")
217
+
expected: @stdlib/math/base/special/abs
218
+
actual: @stdlib/math/base/special/sin
219
+
220
+
1 errors
221
+
```
222
+
223
+
To output results as newline-delimited JSON ([NDJSON][ndjson]),
224
+
225
+
```bash
226
+
$ lint-pkg-json-names --format ndjson
227
+
{"file":"/path/to/package.json","message":"Package name \"@stdlib/math/base/special/sin\" does not match directory structure (expected: \"@stdlib/math/base/special/abs\")","expected":"@stdlib/math/base/special/abs","actual":"@stdlib/math/base/special/sin"}
228
+
...
229
+
```
230
+
231
+
To use as a part of a [standard stream][standard-stream] pipeline,
0 commit comments