@es-joy/jsdoc-eslint-parser

中文文档
0.29.0发布于 2026/08/11MITTypeScriptESM + CJS近 30 天下载 3648

Parser to support JavaScript with JSDoc comments and types available as AST

原始使用文档
文档目录12 节
  1. Use cases
  2. Approach for attaching AST
  3. Installation
  4. Parser options
  5. mode (Defaults to "jsdoc")
  6. maxLines (default: 1) and minLines (default: 0)
  7. indent (default: "")
  8. sourceType (defaults to @babel/eslint-parser 's default)
  9. babelOptions (default: none)
  10. ...parserOptions (default: none)
  11. Changelog
  12. Authors and license

@es-joy/jsdoc-eslint-parser

This project has not been well-tested and should be considered experimental.

This project aims to allow full @babel/eslint-parser configuration, but with comment-parser-based AST for JSDoc blocks and jsdoctypeparser AST for JSDoc types within those blocks.

There is also a @es-joy/jsdoc-eslint-parser/typescript.js parser which builds on @typescript-eslint/parser.

It is hoped that this may spur development of official ESTree acceptance of such AST.

You can run our lint-test script for an example.

Use cases

  1. Using no-restricted-syntax to prohibit certain comment or comment type AST
  2. Supplying comment or comment-type aware query selectors to contexts in eslint-plugin-jsdoc

Approach for attaching AST

In using the Babel ESLint parser, AST is produced which has the tokens on Program expected by ESLint as well as the range array expected on each Node.

We add comment AST--or, rather, JSDocBlock AST--by adding a jsdoc property to each item of the @babel/eslint-parser-parsed code which does not have a suitable ancestor to hold the comment block. We correspondingly update the visitor keys to ensure that for every key's array of visitable properties, jsdoc is added, so it can be separately traversable. We also ensure the comment-parser and jsdoctypeparser visitor keys are added to our parser's visitor keys.

And we add a parent for each Node so that our getJSDocComment method can find its way around (see below).

The tricky part with the jsdoc property comes in with determining which JSDoc should be associated with a given Node. In jsdoccomment, we have a getJSDocComment method, originally begun by ESLint itself to determine where that should be expected.

This detection of the comment for a given structure is not a trivial matter. For example, with:

/* A */
const /* B */ aFunc = /* C */ function () {};

... for the function expression, we might look for the JSDoc Block at point C or B first, but then if not present, look for it at point A. The getJSDocComment method uses such an algorithm, and we call this in our parser currently on each node. If there is no JSDoc block at point B or C, the node for the aFunc VariableDeclaration node should get the JSDoc Block at point A added instead of the FunctionExpression getting it.

Although abstractly, it may appear a better fit with FunctionExpression, the practical purposes of finding JSDoc blocks relates more to position and code generation, which should be easiest to work with if in a position closest to its actual location.

Note that the AST produced is described in the jsdoccomment project. Additionally, this parser adds to Program nodes, a jsdocBlocks property (corresponding to comments though for unattached comment blocks only), along with a commentsIndex integer proprerty to reflect the index to which this JSDoc block corresponds with the comments array.

Installation

npm i -D @es-joy/jsdoc-eslint-parser

Parser options

mode (Defaults to "jsdoc")

The jsdoctypeparser mode, jsdoc, typescript, closure, or permissive. The latter is not generally recommended.

maxLines (default: 1) and minLines (default: 0)

Determines how far up in terms of lines from a structure, we should allow the finding of comment blocks.

indent (default: "")

This is currently exposed but should probably not be changed and may be removed in the future. It indicates the indent to be used when parsing comments. (That may need to be auto-detected in the future.)

sourceType (defaults to @babel/eslint-parser's default)

For indicating script or module

babelOptions (default: none)

Extra options to pass on to Babel (if not using the typescript parser).

...parserOptions (default: none)

Any other options are passed onto the parser.

Changelog

The changelog can be found on the CHANGES.md.

Authors and license

Brett Zamir and contributors.

MIT License, see the included LICENSE-MIT.md file.

版本与发布记录

@es-joy/jsdoc-eslint-parser 共发布 47 个版本,首次发布于 2021/05/03;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.29.0latest2026/08/113 个月前
0.28.02026/08/073 个月前
0.27.02025/12/2910 个月前
0.26.02025/11/081 年前
0.25.02025/10/231.1 年前
0.24.02025/09/271.1 年前

关于 @es-joy/jsdoc-eslint-parser 的常见问题

@es-joy/jsdoc-eslint-parser 是什么?

Parser to support JavaScript with JSDoc comments and types available as AST

如何安装 @es-joy/jsdoc-eslint-parser?

在项目目录运行 npm install @es-joy/jsdoc-eslint-parser,或使用 pnpm add / yarn add / bun add。

@es-joy/jsdoc-eslint-parser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@es-joy/jsdoc-eslint-parser 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@es-joy/jsdoc-eslint-parser 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.19.0 || ^22.13.0 || >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@es-joy/jsdoc-eslint-parser 可以商用吗?

@es-joy/jsdoc-eslint-parser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@es-joy/jsdoc-eslint-parser 的下载量有多少?

根据 npm 官方下载统计,@es-joy/jsdoc-eslint-parser 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,648 次,日均约 122 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@es-joy/jsdoc-eslint-parser 还在维护吗?

最新版本 0.29.0 发布于 2026/08/11(3 个月前);至今共发布 47 个版本,其中过去 12 个月发布了 3 个;首次发布于 2021/05/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。