Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/eslint-plugin-jsdoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v33.0.0
Choose a base ref
...
head repository: gajus/eslint-plugin-jsdoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v33.1.0
Choose a head ref
  • 6 commits
  • 45 files changed
  • 1 contributor

Commits on May 5, 2021

  1. feat: support comment-selector-based contexts

    INCOMPLETE:
        1. Finish require-description tests and add at least one test to other files (ensuring full coverage)?
        1. Remove console.log's in iterateJsdoc
    brettz9 committed May 5, 2021
    Copy the full SHA
    6e835fd View commit details
  2. Copy the full SHA
    74333d4 View commit details
  3. feat: support comment-selector-based contexts

    feat(`no-restricted-syntax`, `no-missing-syntax`): add new rules
    brettz9 committed May 5, 2021
    Copy the full SHA
    f73c72c View commit details
  4. Copy the full SHA
    cee5236 View commit details
  5. Copy the full SHA
    8ee80d6 View commit details
  6. Copy the full SHA
    6b6d908 View commit details
Showing with 1,670 additions and 276 deletions.
  1. +41 −1 .README/README.md
  2. +2 −2 .README/rules/implements-on-classes.md
  3. +3 −2 .README/rules/match-description.md
  4. +2 −2 .README/rules/no-defaults.md
  5. +62 −0 .README/rules/no-missing-syntax.md
  6. +42 −0 .README/rules/no-restricted-syntax.md
  7. +2 −2 .README/rules/no-types.md
  8. +3 −2 .README/rules/require-example.md
  9. +2 −2 .README/rules/require-param-description.md
  10. +2 −2 .README/rules/require-param-name.md
  11. +2 −2 .README/rules/require-param-type.md
  12. +3 −3 .README/rules/require-param.md
  13. +2 −2 .README/rules/require-returns-description.md
  14. +2 −2 .README/rules/require-returns-type.md
  15. +2 −1 .README/rules/require-returns.md
  16. +2 −1 .README/rules/require-throws.md
  17. +2 −1 .README/rules/require-yields.md
  18. +446 −87 README.md
  19. +4 −3 package.json
  20. +6 −0 src/index.js
  21. +75 −128 src/iterateJsdoc.js
  22. +19 −3 src/jsdocUtils.js
  23. +17 −1 src/rules/implementsOnClasses.js
  24. +17 −1 src/rules/matchDescription.js
  25. +17 −1 src/rules/noDefaults.js
  26. +121 −0 src/rules/noMissingSyntax.js
  27. +74 −0 src/rules/noRestrictedSyntax.js
  28. +17 −1 src/rules/noTypes.js
  29. +17 −1 src/rules/requireDescription.js
  30. +17 −1 src/rules/requireExample.js
  31. +18 −12 src/rules/requireJsdoc.js
  32. +17 −1 src/rules/requireParam.js
  33. +17 −1 src/rules/requireParamDescription.js
  34. +17 −1 src/rules/requireParamName.js
  35. +17 −1 src/rules/requireParamType.js
  36. +17 −1 src/rules/requireReturns.js
  37. +17 −1 src/rules/requireReturnsDescription.js
  38. +17 −1 src/rules/requireReturnsType.js
  39. +17 −1 src/rules/requireThrows.js
  40. +17 −1 src/rules/requireYields.js
  41. +17 −1 src/rules/requireYieldsCheck.js
  42. +164 −0 test/rules/assertions/noMissingSyntax.js
  43. +149 −0 test/rules/assertions/noRestrictedSyntax.js
  44. +144 −0 test/rules/assertions/requireDescription.js
  45. +2 −0 test/rules/index.js
42 changes: 41 additions & 1 deletion .README/README.md
Original file line number Diff line number Diff line change
@@ -461,6 +461,42 @@ your files' code which are of interest to check. However, in
`eslint-plugin-jsdoc`, we also allow you to use these selectors to define
additional contexts where you wish our own rules to be applied.

#### `contexts` format

While at their simplest, these can be an array of string selectors, one can
also supply an object with `context` (in place of the string) and one of two
properties:

1. For `require-jsdoc`, there is also a `inlineCommentBlock` property. See
that rule for details.
1. For `no-missing-syntax` and `no-restricted-syntax`, there is also a
`message` property which allows customization of the message to be shown
when the rule is triggered.
1. For `no-missing-syntax`, there is also a `minimum` property. See that rule.
1. For other rules, there is a `comment` property which adds to the `context`
in requiring that the `comment` AST condition is also met, e.g., to
require that certain tags are present and/or or types and type operators
are in use. Note that this AST (either for `JSDoc*` or `JSDocType*` AST)
has not been standardized and should be considered experimental.
Note that this property might also become obsolete if parsers begin to
include JSDoc-structured AST. A
[parser](https://github.com/brettz9/jsdoc-eslint-parser/) is available
which aims to support comment AST as
a first class citizen where comment/comment types can be used anywhere
within a normal AST selector but this should only be considered
experimental. When using such a parser, you need not use `comment` and
can just use a plain string context. The determination of the node on
which the comment is attached is also subject to change. It may be
currently possible for different structures to map to the same comment
block. This is because normally when querying to find either the
declaration of the function expression for
`const quux = function () {}`, the associated comment would,
in both cases, generally be expected to be on the line above both, rather
than to be immediately preceding the funciton (in the case of the
function).

#### Discovering available AST definitions

To know all of the AST definitions one may target, it will depend on the
[parser](https://eslint.org/docs/user-guide/configuring#specifying-parser)
you are using with ESLint (e.g., `espree` is the default parser for ESLint,
@@ -473,11 +509,13 @@ So you can look up a particular parser to see its rules, e.g., browse through
the [ESTree docs](https://github.com/estree/estree) as used by Espree or see
ESLint's [overview of the structure of AST](https://eslint.org/docs/developer-guide/working-with-custom-parsers#the-ast-specification).

However, it can sometimes be even more helpful to get an idea of ASt by just
However, it can sometimes be even more helpful to get an idea of AST by just
providing some of your JavaScript to the wonderful
[AST Explorer](https://astexplorer.net/) tool and see what AST is built out
of your code. You can set the tool to the specific parser which you are using.

#### Uses/Tips for AST

And if you wish to introspect on the AST of code within your projects, you can
use [eslint-plugin-query](https://github.com/brettz9/eslint-plugin-query).
Though it also works as a plugin, you can use it with its own CLI, e.g.,
@@ -515,6 +553,8 @@ selector).
{"gitdown": "include", "file": "./rules/newline-after-description.md"}
{"gitdown": "include", "file": "./rules/no-bad-blocks.md"}
{"gitdown": "include", "file": "./rules/no-defaults.md"}
{"gitdown": "include", "file": "./rules/no-missing-syntax.md"}
{"gitdown": "include", "file": "./rules/no-restricted-syntax.md"}
{"gitdown": "include", "file": "./rules/no-types.md"}
{"gitdown": "include", "file": "./rules/no-undefined-types.md"}
{"gitdown": "include", "file": "./rules/require-description-complete-sentence.md"}
4 changes: 2 additions & 2 deletions .README/rules/implements-on-classes.md
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ function is adhering.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.

Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
5 changes: 3 additions & 2 deletions .README/rules/match-description.md
Original file line number Diff line number Diff line change
@@ -96,8 +96,9 @@ checking it by setting it to `false`.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
(e.g., `ClassDeclaration` for ES6
classes). Overrides the default contexts (see below). Set to `"any"` if you
want the rule to apply to any jsdoc block throughout your files.

4 changes: 2 additions & 2 deletions .README/rules/no-defaults.md
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ the presence of ES6 default parameters (bearing in mind that such

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
62 changes: 62 additions & 0 deletions .README/rules/no-missing-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
### `no-missing-syntax`

This rule lets you report when certain comment structures are always expected.
This rule might be especially useful with [`overrides`](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work)
where you need only require tags and/or types within specific directories
(e.g., to enforce that a plugins or locale directory always has a certain form
of export).

This (along with `no-restricted-syntax`) is a bit similar to Schematron for
XML or jsontron for JSON--you can validate expectations of there being
arbitrary structures.

This differs from the rule of the same name in [`eslint-plugin-query`](https://github.com/brettz9/eslint-plugin-query)
in that this always looks for a comment above a structure (whether or not
you have a `comment` condition).

In addition to being generally useful for precision in requiring contexts,
it is hoped that the ability to specify required tags on structures can
be used for requiring `@type` or other types for a minimalist yet adequate
specification of types which can be used to compile JavaScript+JSDoc (JJ)
to WebAssembly (e.g., by converting it to TypeSscript and then using
AssemblyScript to convert to WebAssembly). (It may be possible that one
will need to require types with certain structures beyond function
declarations and the like, as well as optionally requiring specification
of number types.)

Note that you can use selectors which make use of negators like `:not()`
including with asterisk, e.g., `*:not(FunctionDeclaration)` to indicate types
which are not adequate to satisfy a condition, e.g.,
`FunctionDeclaration:not(FunctionDeclaration[id.name="ignoreMe"])` would
not report if there were only a function declaration of the name "ignoreMe"
(though it would report by function declarations of other names).

#### Options

##### `contexts`

Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.

Use the `minimum` property (defaults to 1) to indicate how many are required
for the rule to be reported.

Use the `message` property to indicate the specific error to be shown when an
error is reported for that context being found missing.

Set to `"any"` if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
function declaration or expression, i.e., `@callback` or `@function` (or its
aliases `@func` or `@method`) (including those associated with an `@interface`).

See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
section of our README for more on the expected format.

|||
|---|---|
|Context|None except those indicated by `contexts`|
|Tags|Any if indicated by AST|
|Recommended|false|
|Options|`contexts`|

<!-- assertions noMissingSyntax -->
42 changes: 42 additions & 0 deletions .README/rules/no-restricted-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
### `no-restricted-syntax`

Reports when certain comment structures are present.

Note that this rule differs from ESLint's [no-restricted-syntax](https://eslint.org/docs/rules/no-restricted-syntax)
rule in expecting values within a single options object's
`contexts` property, and with the property `context` being used in place of
`selector` (as well as allowing for `comment`). The format also differs from
the format expected by [`eslint-plugin-query`](https://github.com/brettz9/eslint-plugin-query).

Unlike those rules, this is specific to finding comments attached to
structures, (whether or not you add a specific `comment` condition).

Note that if your parser supports comment AST (as [jsdoc-eslint-parser/](https://github.com/brettz9/jsdoc-eslint-parser/) is designed to do), you can just use ESLint's
rule.

#### Options

##### `contexts`

Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.

Use the `message` property to indicate the specific error to be shown when an
error is reported for that context being found.

Set to `"any"` if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
function declaration or expression, i.e., `@callback` or `@function` (or its
aliases `@func` or `@method`) (including those associated with an `@interface`).

See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
section of our README for more on the expected format.

|||
|---|---|
|Context|None except those indicated by `contexts`|
|Tags|Any if indicated by AST|
|Recommended|false|
|Options|`contexts`|

<!-- assertions noRestrictedSyntax -->
4 changes: 2 additions & 2 deletions .README/rules/no-types.md
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ the type information would be redundant with TypeScript.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
5 changes: 3 additions & 2 deletions .README/rules/require-example.md
Original file line number Diff line number Diff line change
@@ -25,8 +25,9 @@ missing `@example` declarations.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
(e.g., `ClassDeclaration` for ES6
classes). Overrides the default contexts (see below). Set to `"any"` if you
want the rule to apply to any jsdoc block throughout your files.

4 changes: 2 additions & 2 deletions .README/rules/require-param-description.md
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ Requires that each `@param` tag has a `description` value.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
4 changes: 2 additions & 2 deletions .README/rules/require-param-name.md
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ Requires that all function parameters have names.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
4 changes: 2 additions & 2 deletions .README/rules/require-param-type.md
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ Requires that each `@param` tag has a `type` value.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
6 changes: 3 additions & 3 deletions .README/rules/require-param.md
Original file line number Diff line number Diff line change
@@ -324,9 +324,9 @@ need destructuring.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied. Overrides the default
contexts (see below). May be useful for adding such as
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). May be useful for adding such as
`TSMethodSignature` in TypeScript or restricting the contexts
which are checked.

4 changes: 2 additions & 2 deletions .README/rules/require-returns-description.md
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ or if it is `Promise<void>` or `Promise<undefined>`.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
4 changes: 2 additions & 2 deletions .README/rules/require-returns-type.md
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ Requires that `@returns` tag has `type` value.

##### `contexts`

Set this to an array of strings representing the AST context
where you wish the rule to be applied.
Set this to an array of strings representing the AST context (or an object with
`context` and `comment` properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
3 changes: 2 additions & 1 deletion .README/rules/require-returns.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@ Will also report if multiple `@returns` tags are present.
object. This may be useful for flagging that there has been consideration
of return type. Defaults to `false`.
- `contexts` - Set this to an array of strings representing the AST context
where you wish the rule to be applied.
(or an object with `context` and `comment` properties) where you wish
the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
3 changes: 2 additions & 1 deletion .README/rules/require-throws.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@ Requires that throw statements are documented.
so be sure to add back `inheritdoc` if you wish its presence to cause
exemption of the rule.
- `contexts` - Set this to an array of strings representing the AST context
where you wish the rule to be applied.
(or an object with `context` and `comment` properties) where you wish
the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
3 changes: 2 additions & 1 deletion .README/rules/require-yields.md
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@ option to expect a non-standard `@next` tag.
that a project is aware of an `undefined`/`void` yield. Defaults to
`false`.
- `contexts` - Set this to an array of strings representing the AST context
where you wish the rule to be applied.
(or an object with `context` and `comment` properties) where you wish
the rule to be applied.
Overrides the default contexts (see below). Set to `"any"` if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
Loading