Skip to content

Check syntax closure #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ how many line breaks to add when a block is missing.
- For type-checking rules, impacts parsing of types (through
[jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser) dependency)
- Check preferred tag names
- For `check-syntax`, determines aspects that may be enforced
- Disallows namepath on `@interface` for "closure" mode in `valid-types` (and
avoids checking in other rules)

Expand Down
12 changes: 11 additions & 1 deletion .README/rules/check-syntax.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
### `check-syntax`

Reports against Google Closure Compiler syntax.
Reports against syntax not encouraged for the mode (e.g., Google Closure Compiler
in "jsdoc" or "typescript" mode). Note that this rule will not chekc for types
that are wholly invalid for a given mode, as that is covered by `valid-types`.

Currently checks against:

- Use of `=` in "jsdoc" or "typescript" mode

Note that "jsdoc" actually allows Closure syntax, but with another
option available for optional parameters (enclosing the name in brackets), the
rule is enforced (except under "permissive" and "closure" modes).

|||
|---|---|
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ how many line breaks to add when a block is missing.
- For type-checking rules, impacts parsing of types (through
[jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser) dependency)
- Check preferred tag names
- For `check-syntax`, determines aspects that may be enforced
- Disallows namepath on `@interface` for "closure" mode in `valid-types` (and
avoids checking in other rules)

Expand Down Expand Up @@ -2464,7 +2465,17 @@ function quux (code = 1) {
<a name="eslint-plugin-jsdoc-rules-check-syntax"></a>
### <code>check-syntax</code>

Reports against Google Closure Compiler syntax.
Reports against syntax not encouraged for the mode (e.g., Google Closure Compiler
in "jsdoc" or "typescript" mode). Note that this rule will not chekc for types
that are wholly invalid for a given mode, as that is covered by `valid-types`.

Currently checks against:

- Use of `=` in "jsdoc" or "typescript" mode

Note that "jsdoc" actually allows Closure syntax, but with another
option available for optional parameters (enclosing the name in brackets), the
rule is enforced (except under "permissive" and "closure" modes).

|||
|---|---|
Expand All @@ -2486,6 +2497,14 @@ function quux (foo) {
The following patterns are not considered problems:

````js
/**
* @param {string=} foo
*/
function quux (foo) {

}
// Settings: {"jsdoc":{"mode":"closure"}}

/**
* @param {string} [foo]
*/
Expand Down
16 changes: 11 additions & 5 deletions src/rules/checkSyntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ import iterateJsdoc from '../iterateJsdoc';
export default iterateJsdoc(({
jsdoc,
report,
settings,
}) => {
if (!jsdoc.tags) {
return;
}

for (const tag of jsdoc.tags) {
if (tag.type.slice(-1) === '=') {
report('Syntax should not be Google Closure Compiler style.', null, tag);
break;
const {mode} = settings;

// Don't check for "permissive" and "closure"
if (mode === 'jsdoc' || mode === 'typescript') {
for (const tag of jsdoc.tags) {
if (tag.type.slice(-1) === '=') {
report('Syntax should not be Google Closure Compiler style.', null, tag);
break;
}
}
}
}, {
iterateAllJsdocs: true,
meta: {
docs: {
description: 'Reports against Google Closure Compiler syntax.',
description: 'Reports against syntax not valid for the mode (e.g., Google Closure Compiler in non-Closure mode).',
},
type: 'suggestion',
},
Expand Down
15 changes: 15 additions & 0 deletions test/rules/assertions/checkSyntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export default {
},
],
valid: [
{
code: `
/**
* @param {string=} foo
*/
function quux (foo) {

}
`,
settings: {
jsdoc: {
mode: 'closure',
},
},
},
{
code: `
/**
Expand Down