Skip to content

Commit e03be63

Browse files
committed
feat: add rule check-syntax
1 parent 070f535 commit e03be63

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable import/max-dependencies */
22
import checkExamples from './rules/checkExamples';
33
import checkParamNames from './rules/checkParamNames';
4+
import checkSyntax from './rules/checkSyntax';
45
import checkTagNames from './rules/checkTagNames';
56
import checkTypes from './rules/checkTypes';
67
import newlineAfterDescription from './rules/newlineAfterDescription';
@@ -25,6 +26,7 @@ export default {
2526
rules: {
2627
'jsdoc/check-examples': 'off',
2728
'jsdoc/check-param-names': 'warn',
29+
'jsdoc/check-syntax': 'off',
2830
'jsdoc/check-tag-names': 'warn',
2931
'jsdoc/check-types': 'warn',
3032
'jsdoc/newline-after-description': 'warn',
@@ -48,6 +50,7 @@ export default {
4850
rules: {
4951
'check-examples': checkExamples,
5052
'check-param-names': checkParamNames,
53+
'check-syntax': checkSyntax,
5154
'check-tag-names': checkTagNames,
5255
'check-types': checkTypes,
5356
'newline-after-description': newlineAfterDescription,

src/rules/checkSyntax.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import iterateJsdoc from '../iterateJsdoc';
2+
3+
export default iterateJsdoc(({
4+
jsdoc,
5+
report
6+
}) => {
7+
if (!jsdoc.tags.length) {
8+
return;
9+
}
10+
11+
for (const tag of jsdoc.tags) {
12+
if (tag.type.slice(-1) === '=') {
13+
report('Syntax should not be Google Closure Compiler style.');
14+
break;
15+
}
16+
}
17+
});

test/rules/assertions/checkSyntax.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export default {
2+
invalid: [
3+
{
4+
code: `
5+
/**
6+
* @param {string=} foo
7+
*/
8+
function quux (foo) {
9+
10+
}
11+
`,
12+
errors: [
13+
{
14+
message: 'Syntax should not be Google Closure Compiler style.'
15+
}
16+
]
17+
}
18+
],
19+
valid: [
20+
{
21+
code: `
22+
/**
23+
* @param {string} [foo]
24+
*/
25+
function quux (foo) {
26+
27+
}
28+
`
29+
}
30+
]
31+
};

test/rules/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ruleTester = new RuleTester();
99
_.forEach([
1010
'check-examples',
1111
'check-param-names',
12+
'check-syntax',
1213
'check-tag-names',
1314
'check-types',
1415
'newline-after-description',

0 commit comments

Comments
 (0)