Skip to content

Commit 00702eb

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 924fdb7 + 11fb04d commit 00702eb

File tree

36 files changed

+1313
-114
lines changed

36 files changed

+1313
-114
lines changed

etc/eslint/rules/stdlib.js

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,8 +2069,8 @@ rules[ 'stdlib/jsdoc-no-literal-urls' ] = 'error';
20692069
* *
20702070
* * Hello World.
20712071
* * - Foo
2072-
* * 1. Yes
2073-
* * 2. No
2072+
* * 1. Yes
2073+
* * 2. No
20742074
* * - Bar
20752075
* *
20762076
* * @returns {string} a value
@@ -2095,10 +2095,10 @@ rules[ 'stdlib/jsdoc-no-literal-urls' ] = 'error';
20952095
* *
20962096
* * Hello World.
20972097
* *
2098-
* * - Foo
2099-
* * 1. Yes
2098+
* * - Foo
2099+
* * 1. Yes
21002100
* *
2101-
* * 2. No
2101+
* * 2. No
21022102
* *
21032103
* * - Bar
21042104
* *
@@ -3173,6 +3173,47 @@ rules[ 'stdlib/jsdoc-tag-spacing' ] = 'error';
31733173
*/
31743174
rules[ 'stdlib/jsdoc-unordered-list-marker-style' ] = [ 'error', '-' ];
31753175

3176+
/**
3177+
* Enforce that only variables and functions are assigned to `module.exports`.
3178+
*
3179+
* @name module-exports-assignments
3180+
* @memberof rules
3181+
* @type {string}
3182+
* @default 'error'
3183+
*
3184+
* @example
3185+
* // Bad...
3186+
* var normal = require( '@stdlib/random/base/normal' );
3187+
* var beta = require( '@stdlib/random/base/beta' );
3188+
*
3189+
*
3190+
* // EXPORTS //
3191+
*
3192+
* module.exports = {
3193+
* 'normal': normal,
3194+
* 'beta': beta
3195+
* };
3196+
*
3197+
* @example
3198+
* // Good...
3199+
* var normal = require( '@stdlib/random/base/normal' );
3200+
* var beta = require( '@stdlib/random/base/beta' );
3201+
*
3202+
*
3203+
* // VARIABLES //
3204+
*
3205+
* var ns = {
3206+
* 'normal': normal,
3207+
* 'beta': beta
3208+
* };
3209+
*
3210+
*
3211+
* // EXPORTS //
3212+
*
3213+
* module.exports = ns;
3214+
*/
3215+
rules[ 'stdlib/module-exports-assignments' ] = 'error';
3216+
31763217
/**
31773218
* Enforce that export statements are placed at the end of a file.
31783219
*
@@ -3579,6 +3620,7 @@ rules[ 'stdlib/require-globals' ] = [ 'error', {
35793620
'Int8Array',
35803621
'Int16Array',
35813622
'Int32Array',
3623+
'Number',
35823624
'SharedArrayBuffer',
35833625
'Uint8Array',
35843626
'Uint8ClampedArray',

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,15 @@ setReadOnly( rules, 'jsdoc-tag-spacing', require( '@stdlib/_tools/eslint/rules/j
612612
*/
613613
setReadOnly( rules, 'jsdoc-unordered-list-marker-style', require( '@stdlib/_tools/eslint/rules/jsdoc-unordered-list-marker-style' ) );
614614

615+
/**
616+
* @name module-exports-assignments
617+
* @memberof rules
618+
* @readonly
619+
* @type {Function}
620+
* @see {@link module:@stdlib/_tools/eslint/rules/module-exports-assignments}
621+
*/
622+
setReadOnly( rules, 'module-exports-assignments', require( '@stdlib/_tools/eslint/rules/module-exports-assignments' ) );
623+
615624
/**
616625
* @name module-exports-last
617626
* @memberof rules
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# module-exports-assignments
22+
23+
> [ESLint rule][eslint-rules] enforcing that only variables and functions are assigned to `module.exports`.
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/module-exports-assignments' );
37+
```
38+
39+
#### rule
40+
41+
[ESLint rule][eslint-rules] enforcing that only variables and functions are assigned to `module.exports`.
42+
43+
**Bad**:
44+
45+
<!-- eslint-disable stdlib/module-exports-assignments -->
46+
47+
```javascript
48+
var normal = require( '@stdlib/random/base/normal' );
49+
var beta = require( '@stdlib/random/base/beta' );
50+
51+
52+
// EXPORTS //
53+
54+
module.exports = {
55+
'normal': normal,
56+
'beta': beta
57+
};
58+
```
59+
60+
**Good**:
61+
62+
```javascript
63+
var normal = require( '@stdlib/random/base/normal' );
64+
var beta = require( '@stdlib/random/base/beta' );
65+
66+
67+
// VARIABLES //
68+
69+
var ns = {
70+
'normal': normal,
71+
'beta': beta
72+
};
73+
74+
75+
// EXPORTS //
76+
77+
module.exports = ns;
78+
```
79+
80+
</section>
81+
82+
<!-- /.usage -->
83+
84+
<section class="examples">
85+
86+
## Examples
87+
88+
<!-- eslint no-undef: "error" -->
89+
90+
```javascript
91+
var Linter = require( 'eslint' ).Linter;
92+
var rule = require( '@stdlib/_tools/eslint/rules/module-exports-assignments' );
93+
94+
var linter = new Linter();
95+
var result;
96+
var code;
97+
98+
code = [
99+
'module.exports = fun();',
100+
'',
101+
'function fun() {',
102+
' return 3.14;',
103+
'}'
104+
].join( '\n' );
105+
106+
linter.defineRule( 'module-exports-assignments', rule );
107+
108+
result = linter.verify( code, {
109+
'rules': {
110+
'module-exports-assignments': 'error'
111+
}
112+
});
113+
/* returns
114+
[
115+
{
116+
'ruleId': 'module-exports-assignments',
117+
'severity': 2,
118+
'message': 'Only variables and functions should be assigned to `module.exports`',
119+
'line': 1,
120+
'column': 1,
121+
'nodeType': 'AssignmentExpression',
122+
'source': 'module.exports = fun();',
123+
'endLine': 1,
124+
'endColumn': 23
125+
}
126+
]
127+
*/
128+
```
129+
130+
</section>
131+
132+
<!-- /.examples -->
133+
134+
<section class="links">
135+
136+
[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules
137+
138+
</section>
139+
140+
<!-- /.links -->
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 Linter = require( 'eslint' ).Linter;
22+
var rule = require( './../lib' );
23+
24+
var linter = new Linter();
25+
var result;
26+
var code;
27+
28+
code = [
29+
'module.exports = fun();',
30+
'',
31+
'function fun() {',
32+
' return 3.14;',
33+
'}'
34+
].join( '\n' );
35+
36+
linter.defineRule( 'module-exports-assignments', rule );
37+
38+
result = linter.verify( code, {
39+
'rules': {
40+
'module-exports-assignments': 'error'
41+
}
42+
});
43+
console.log( result );
44+
/* =>
45+
[
46+
{
47+
'ruleId': 'module-exports-assignments',
48+
'severity': 2,
49+
'message': 'Only variables and functions should be assigned to `module.exports`',
50+
'line': 1,
51+
'column': 1,
52+
'nodeType': 'AssignmentExpression',
53+
'source': 'module.exports = fun();',
54+
'endLine': 1,
55+
'endColumn': 23
56+
}
57+
]
58+
*/
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) 2018 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 enforcing that only variables and functions are assigned to `module.exports`.
23+
*
24+
* @module @stdlib/_tools/eslint/rules/module-exports-assignments
25+
*
26+
* @example
27+
* var rule = require( '@stdlib/_tools/eslint/rules/module-exports-assignments' );
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)