Skip to content

Commit a802811

Browse files
committed
feat: add lint rule to prevent space-aligned asterisks for JSDoc comments
1 parent abf4da5 commit a802811

9 files changed

Lines changed: 1016 additions & 0 deletions

File tree

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 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+
# No Space-Aligned Asterisks
22+
23+
> [ESLint rule][eslint-rules] to prevent prevent space-aligned asterisks for JSDoc comments.
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/jsdoc-no-space-aligned-asterisks' );
37+
```
38+
39+
#### rule
40+
41+
[ESLint rule][eslint-rules] to prevent space-aligned asterisks for JSDoc comments.
42+
43+
**Bad**:
44+
45+
<!-- eslint-disable stdlib/jsdoc-no-space-aligned-asterisks -->
46+
47+
```javascript
48+
/**
49+
* Boop beep.
50+
*
51+
* @returns {string} a value
52+
*
53+
* @example
54+
* var str = beep();
55+
* // returns 'boop'
56+
*/
57+
function beep() {
58+
return 'boop';
59+
}
60+
```
61+
62+
**Good**:
63+
64+
```javascript
65+
/**
66+
* Boop beep.
67+
*
68+
* @returns {string} a value
69+
*
70+
* @example
71+
* var str = beep();
72+
* // returns 'boop'
73+
*/
74+
function beep() {
75+
return 'boop';
76+
}
77+
```
78+
79+
</section>
80+
81+
<!-- /.usage -->
82+
83+
<section class="examples">
84+
85+
## Examples
86+
87+
<!-- eslint no-undef: "error" -->
88+
89+
```javascript
90+
var Linter = require( 'eslint' ).Linter;
91+
var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-no-space-aligned-asterisks' );
92+
93+
var linter = new Linter();
94+
var result;
95+
var code;
96+
97+
// Generate our source code:
98+
code = [
99+
'/**',
100+
' * Beep boop.',
101+
' *',
102+
' * @param {string} str - input value',
103+
' * @returns {string} output value',
104+
' *',
105+
' * @example',
106+
' * var out = beep( "boop" );',
107+
' * // returns "beepboop"',
108+
' */',
109+
'function beep( str ) {',
110+
'\treturn "beep" + str;',
111+
'}'
112+
].join( '\n' );
113+
114+
// Register the ESLint rule:
115+
linter.defineRule( 'jsdoc-no-space-aligned-asterisks', rule );
116+
117+
// Lint the code:
118+
result = linter.verify( code, {
119+
'rules': {
120+
'jsdoc-no-space-aligned-asterisks': 'error'
121+
}
122+
});
123+
console.log( result );
124+
/* =>
125+
[
126+
{
127+
'ruleId': 'jsdoc-no-space-aligned-asterisks',
128+
'severity': 2,
129+
'message': 'JSDoc comments should not have space-aligned asterisks',
130+
'line': 1,
131+
'column':1,
132+
'nodeType': null,
133+
'endLine': 10,
134+
'endColumn': 4
135+
'fix': {
136+
'range': [...],
137+
'text': '...'
138+
}
139+
}
140+
]
141+
*/
142+
```
143+
144+
</section>
145+
146+
<!-- /.examples -->
147+
148+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
149+
150+
<section class="related">
151+
152+
</section>
153+
154+
<!-- /.related -->
155+
156+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
157+
158+
<section class="links">
159+
160+
[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules
161+
162+
</section>
163+
164+
<!-- /.links -->
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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+
// Generate our source code:
29+
code = [
30+
'/**',
31+
' * Beep boop.',
32+
' *',
33+
' * @param {string} str - input value',
34+
' * @returns {string} output value',
35+
' *',
36+
' * @example',
37+
' * var out = beep( "boop" );',
38+
' * // returns "beepboop"',
39+
' */',
40+
'function beep( str ) {',
41+
'\treturn "beep" + str;',
42+
'}'
43+
].join( '\n' );
44+
45+
// Register the ESLint rule:
46+
linter.defineRule( 'jsdoc-no-space-aligned-asterisks', rule );
47+
48+
// Lint the code:
49+
result = linter.verify( code, {
50+
'rules': {
51+
'jsdoc-no-space-aligned-asterisks': 'error'
52+
}
53+
});
54+
console.log( result );
55+
/* =>
56+
[
57+
{
58+
'ruleId': 'jsdoc-no-space-aligned-asterisks',
59+
'severity': 2,
60+
'message': 'JSDoc comments should not have space-aligned asterisks',
61+
'line': 1,
62+
'column':1,
63+
'nodeType': null,
64+
'endLine': 10,
65+
'endColumn': 4
66+
'fix': {
67+
'range': [...],
68+
'text': '...'
69+
}
70+
}
71+
]
72+
*/
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) 2023 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 disallow space-aligned asterisks for JSDoc comments.
23+
*
24+
* @module @stdlib/_tools/eslint/rules/jsdoc-no-space-aligned-asterisks
25+
*
26+
* @example
27+
* var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-no-space-aligned-asterisks' );
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)