Skip to content

Commit 676a617

Browse files
authored
Merge pull request #185 from vulkd/vk/rule-check-syntax
feat: add rule check syntax
2 parents 5c82899 + 3889927 commit 676a617

File tree

7 files changed

+102
-0
lines changed

7 files changed

+102
-0
lines changed

.README/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This table maps the rules between `eslint-plugin-jsdoc` and `jscs-jsdoc`.
1616
| --- | --- |
1717
| [`check-examples`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples) | N/A |
1818
| [`check-param-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names) | [`checkParamNames`](https://github.com/jscs-dev/jscs-jsdoc#checkparamnames) |
19+
| [`check-syntax`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-syntax) | N/A |
1920
| [`check-tag-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-tag-names) | N/A ~ [`checkAnnotations`](https://github.com/jscs-dev/jscs-jsdoc#checkannotations) |
2021
| [`check-types`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types) | [`checkTypes`](https://github.com/jscs-dev/jscs-jsdoc#checktypes) |
2122
| [`newline-after-description`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-newline-after-description) | [`requireNewlineAfterDescription`](https://github.com/jscs-dev/jscs-jsdoc#requirenewlineafterdescription) and [`disallowNewlineAfterDescription`](https://github.com/jscs-dev/jscs-jsdoc#disallownewlineafterdescription) |
@@ -73,6 +74,7 @@ Finally, enable all of the rules that you would like to use.
7374
"rules": {
7475
"jsdoc/check-examples": 1,
7576
"jsdoc/check-param-names": 1,
77+
"jsdoc/check-syntax": 1,
7678
"jsdoc/check-tag-names": 1,
7779
"jsdoc/check-types": 1,
7880
"jsdoc/newline-after-description": 1,
@@ -247,6 +249,7 @@ Finally, the following rule pertains to inline disable directives:
247249

248250
{"gitdown": "include", "file": "./rules/check-examples.md"}
249251
{"gitdown": "include", "file": "./rules/check-param-names.md"}
252+
{"gitdown": "include", "file": "./rules/check-syntax.md"}
250253
{"gitdown": "include", "file": "./rules/check-tag-names.md"}
251254
{"gitdown": "include", "file": "./rules/check-types.md"}
252255
{"gitdown": "include", "file": "./rules/newline-after-description.md"}

.README/rules/check-syntax.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### `check-syntax`
2+
3+
Reports against Google Closure Compiler syntax.
4+
5+
|||
6+
|---|---|
7+
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
8+
|Tags|N/A|
9+
10+
<!-- assertions checkSyntax -->

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ JSDoc linting rules for ESLint.
1919
* [Rules](#eslint-plugin-jsdoc-rules)
2020
* [`check-examples`](#eslint-plugin-jsdoc-rules-check-examples)
2121
* [`check-param-names`](#eslint-plugin-jsdoc-rules-check-param-names)
22+
* [`check-syntax`](#eslint-plugin-jsdoc-rules-check-syntax)
2223
* [`check-tag-names`](#eslint-plugin-jsdoc-rules-check-tag-names)
2324
* [`check-types`](#eslint-plugin-jsdoc-rules-check-types)
2425
* [`newline-after-description`](#eslint-plugin-jsdoc-rules-newline-after-description)
@@ -47,6 +48,7 @@ This table maps the rules between `eslint-plugin-jsdoc` and `jscs-jsdoc`.
4748
| --- | --- |
4849
| [`check-examples`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples) | N/A |
4950
| [`check-param-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names) | [`checkParamNames`](https://github.com/jscs-dev/jscs-jsdoc#checkparamnames) |
51+
| [`check-syntax`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-syntax) | N/A |
5052
| [`check-tag-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-tag-names) | N/A ~ [`checkAnnotations`](https://github.com/jscs-dev/jscs-jsdoc#checkannotations) |
5153
| [`check-types`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types) | [`checkTypes`](https://github.com/jscs-dev/jscs-jsdoc#checktypes) |
5254
| [`newline-after-description`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-newline-after-description) | [`requireNewlineAfterDescription`](https://github.com/jscs-dev/jscs-jsdoc#requirenewlineafterdescription) and [`disallowNewlineAfterDescription`](https://github.com/jscs-dev/jscs-jsdoc#disallownewlineafterdescription) |
@@ -106,6 +108,7 @@ Finally, enable all of the rules that you would like to use.
106108
"rules": {
107109
"jsdoc/check-examples": 1,
108110
"jsdoc/check-param-names": 1,
111+
"jsdoc/check-syntax": 1,
109112
"jsdoc/check-tag-names": 1,
110113
"jsdoc/check-types": 1,
111114
"jsdoc/newline-after-description": 1,
@@ -663,6 +666,40 @@ function quux ({
663666

664667
Likewise for the pattern `[a, b]` which is an [`ArrayPattern`](https://github.com/estree/estree/blob/master/es2015.md#arraypattern).
665668

669+
<a name="eslint-plugin-jsdoc-rules-check-syntax"></a>
670+
### <code>check-syntax</code>
671+
672+
Reports against Google Closure Compiler syntax.
673+
674+
|||
675+
|---|---|
676+
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
677+
|Tags|N/A|
678+
679+
The following patterns are considered problems:
680+
681+
````js
682+
/**
683+
* @param {string=} foo
684+
*/
685+
function quux (foo) {
686+
687+
}
688+
// Message: Syntax should not be Google Closure Compiler style.
689+
````
690+
691+
The following patterns are not considered problems:
692+
693+
````js
694+
/**
695+
* @param {string} [foo]
696+
*/
697+
function quux (foo) {
698+
699+
}
700+
````
701+
702+
666703
<a name="eslint-plugin-jsdoc-rules-check-tag-names"></a>
667704
### <code>check-tag-names</code>
668705

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)