Skip to content

Commit f55f362

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 1feedd0 + cc1d22e commit f55f362

29 files changed

Lines changed: 1086 additions & 1 deletion

File tree

etc/eslint/rules/stdlib.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,6 +3758,16 @@ rules[ 'stdlib/jsdoc-main-export' ] = 'error';
37583758
*/
37593759
rules[ 'stdlib/module-exports-last' ] = 'error';
37603760

3761+
/**
3762+
* Enforce that a namespace `index.js` exports all packages in the respective namespace directory.
3763+
*
3764+
* @name namespace-export-all
3765+
* @memberof rules
3766+
* @type {string}
3767+
* @default 'error'
3768+
*/
3769+
rules[ 'stdlib/namespace-export-all' ] = 'error';
3770+
37613771
/**
37623772
* Enforce that packages in a namespace `index.js` file are listed in alphabetical order.
37633773
*

lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,15 @@ setReadOnly( rules, 'jsdoc-unordered-list-marker-style', require( '@stdlib/_tool
729729
*/
730730
setReadOnly( rules, 'module-exports-last', require( '@stdlib/_tools/eslint/rules/module-exports-last' ) );
731731

732+
/**
733+
* @name namespace-export-all
734+
* @memberof rules
735+
* @readonly
736+
* @type {Function}
737+
* @see {@link module:@stdlib/_tools/eslint/rules/namespace-export-all}
738+
*/
739+
setReadOnly( rules, 'namespace-export-all', require( '@stdlib/_tools/eslint/rules/namespace-export-all' ) );
740+
732741
/**
733742
* @name namespace-index-order
734743
* @memberof rules
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 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+
# namespace-export-all
22+
23+
> [ESLint rule][eslint-rules] to enforce that a namespace `index.js` exports all packages in the respective namespace directory.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var rule = require( '@stdlib/_tools/eslint/rules/namespace-export-all' );
37+
```
38+
39+
#### rule
40+
41+
[ESLint rule][eslint-rules] to enforce that a namespace `index.js` exports all packages in the respective namespace directory. The rule is applied when a file contains a comment with the following content:
42+
43+
> `When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.`.
44+
45+
Assuming a `@stdlib/constants/array` folder with `max-array-length` and `max-typed-array-length` package directories, the rule will validate as follows:
46+
47+
**Bad**:
48+
49+
```javascript
50+
/*
51+
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
52+
*/
53+
54+
// MODULES //
55+
56+
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
57+
58+
59+
// MAIN //
60+
61+
var ns = {};
62+
63+
/**
64+
* @name MAX_ARRAY_LENGTH
65+
* @memberof ns
66+
* @readonly
67+
* @constant
68+
* @type {number}
69+
* @see {@link module:@stdlib/constants/array/max-array-length}
70+
*/
71+
setReadOnly( ns, 'MAX_ARRAY_LENGTH', require( '@stdlib/constants/array/max-array-length' ) );
72+
```
73+
74+
**Good**:
75+
76+
```javascript
77+
/*
78+
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
79+
*/
80+
81+
// MODULES //
82+
83+
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
84+
85+
86+
// MAIN //
87+
88+
var ns = {};
89+
90+
/**
91+
* @name MAX_ARRAY_LENGTH
92+
* @memberof ns
93+
* @readonly
94+
* @constant
95+
* @type {number}
96+
* @see {@link module:@stdlib/constants/array/max-array-length}
97+
*/
98+
setReadOnly( ns, 'MAX_ARRAY_LENGTH', require( '@stdlib/constants/array/max-array-length' ) );
99+
100+
/**
101+
* @name MAX_TYPED_ARRAY_LENGTH
102+
* @memberof ns
103+
* @readonly
104+
* @constant
105+
* @type {number}
106+
* @see {@link module:@stdlib/constants/array/max-typed-array-length}
107+
*/
108+
setReadOnly( ns, 'MAX_TYPED_ARRAY_LENGTH', require( '@stdlib/constants/array/max-typed-array-length' ) );
109+
```
110+
111+
</section>
112+
113+
<!-- /.usage -->
114+
115+
<section class="examples">
116+
117+
## Examples
118+
119+
<!-- eslint no-undef: "error" -->
120+
121+
```javascript
122+
var join = require( 'path' ).join;
123+
var Linter = require( 'eslint' ).Linter;
124+
var rule = require( '@stdlib/_tools/eslint/rules/namespace-export-all' );
125+
126+
var linter = new Linter();
127+
var result;
128+
var config;
129+
var code;
130+
131+
code = [
132+
'/*',
133+
'* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.',
134+
'*/',
135+
'',
136+
'// MODULES //',
137+
'',
138+
'var setReadOnly = require( \'@stdlib/utils/define-read-only-property\' );',
139+
'',
140+
'',
141+
'// MAIN //',
142+
'',
143+
'/**',
144+
'* Top-level namespace.',
145+
'*',
146+
'* @namespace ns',
147+
'*/',
148+
'var ns = {};',
149+
'',
150+
'/**',
151+
'* @name error2json',
152+
'* @memberof ns',
153+
'* @readonly',
154+
'* @type {Function}',
155+
'* @see {@link module:@stdlib/error/to-json}',
156+
'*/',
157+
'setReadOnly( ns, \'error2json\', require( \'@stdlib/error/to-json\' ) );'
158+
].join( '\n' );
159+
160+
linter.defineRule( 'namespace-export-all', rule );
161+
162+
config = {
163+
'rules': {
164+
'namespace-export-all': 'error'
165+
}
166+
};
167+
result = linter.verify( code, config, {
168+
'filename': join( __dirname, 'fixtures', 'lib', 'index.js' )
169+
});
170+
console.log( result );
171+
/* =>
172+
{
173+
'ruleId': 'namespace-export-all',
174+
'severity': 2,
175+
'message': '`reviver` is not exported from `index.js`',
176+
'line': 7,
177+
'column': 1,
178+
'nodeType': 'Program',
179+
'endLine': 26,
180+
'endColumn': 69
181+
}
182+
*/
183+
```
184+
185+
</section>
186+
187+
<!-- /.examples -->
188+
189+
<section class="links">
190+
191+
[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules
192+
193+
</section>
194+
195+
<!-- /.links -->

lib/node_modules/@stdlib/_tools/eslint/rules/namespace-export-all/examples/fixtures/reviver/.gitkeep

Whitespace-only changes.

lib/node_modules/@stdlib/_tools/eslint/rules/namespace-export-all/examples/fixtures/to-json/.gitkeep

Whitespace-only changes.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var join = require( 'path' ).join;
22+
var Linter = require( 'eslint' ).Linter;
23+
var rule = require( './../lib' );
24+
25+
var linter = new Linter();
26+
var result;
27+
var config;
28+
var code;
29+
30+
code = [
31+
'/*',
32+
'* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.',
33+
'*/',
34+
'',
35+
'// MODULES //',
36+
'',
37+
'var setReadOnly = require( \'@stdlib/utils/define-read-only-property\' );',
38+
'',
39+
'',
40+
'// MAIN //',
41+
'',
42+
'/**',
43+
'* Top-level namespace.',
44+
'*',
45+
'* @namespace ns',
46+
'*/',
47+
'var ns = {};',
48+
'',
49+
'/**',
50+
'* @name error2json',
51+
'* @memberof ns',
52+
'* @readonly',
53+
'* @type {Function}',
54+
'* @see {@link module:@stdlib/error/to-json}',
55+
'*/',
56+
'setReadOnly( ns, \'error2json\', require( \'@stdlib/error/to-json\' ) );'
57+
].join( '\n' );
58+
59+
linter.defineRule( 'namespace-export-all', rule );
60+
61+
config = {
62+
'rules': {
63+
'namespace-export-all': 'error'
64+
}
65+
};
66+
result = linter.verify( code, config, {
67+
'filename': join( __dirname, 'fixtures', 'lib', 'index.js' )
68+
});
69+
console.log( result );
70+
/* =>
71+
{
72+
'ruleId': 'namespace-export-all',
73+
'severity': 2,
74+
'message': '`reviver` is not exported from `index.js`',
75+
'line': 7,
76+
'column': 1,
77+
'nodeType': 'Program',
78+
'endLine': 26,
79+
'endColumn': 69
80+
}
81+
*/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* ESLint rule to enforce that a namespace `index.js` exports all packages in the respective namespace directory.
23+
*
24+
* @module @stdlib/_tools/eslint/rules/namespace-export-all
25+
*
26+
* @example
27+
* var rule = require( '@stdlib/_tools/eslint/rules/namespace-export-all' );
28+
*
29+
* console.log( rule );
30+
*/
31+
32+
// MODULES //
33+
34+
var main = require( './main.js' );
35+
36+
37+
// EXPORTS //
38+
39+
module.exports = main;

0 commit comments

Comments
 (0)