Skip to content

fix(eslint-plugin-tsdoc): declare eslint as a peer dependency - #483

Open
Christopher Pruijsen (cpruijsen) wants to merge 1 commit into
microsoft:mainfrom
cpruijsen:fix/issue-479
Open

fix(eslint-plugin-tsdoc): declare eslint as a peer dependency#483
Christopher Pruijsen (cpruijsen) wants to merge 1 commit into
microsoft:mainfrom
cpruijsen:fix/issue-479

Conversation

@cpruijsen

Copy link
Copy Markdown

Declare "peerDependencies": { "eslint": ">=7" } so the consumer's ESLint is linked into the plugin and the published typings bind to the same types the config is checked against. eslint remains a devDependency for this repo's tests. Add a test that every non-relative import in the emitted lib/index.d.ts is listed in dependencies or peerDependencies.

Published lib/index.d.ts does import type * as eslint from 'eslint', but eslint-plugin-tsdoc did not declare eslint as a dependency or peer (only a devDependency). Under pnpm and Yarn PnP, TypeScript can resolve that import to a transitive @types/eslint instead of the consumer's ESLint. A // @ts-checked flat config with plugins: { tsdoc } then fails (IPlugin not assignable to Plugin because RuleModule is not RuleDefinition).

Fixes #479

Decision

The range is the one in the issue, which the reporter verified via pnpm packageExtensions. The issue repro (eslint-plugin-tsdoc@0.5.2, eslint@10.8.0, typescript@6.0.3, pnpm, @types/eslint-scope) is tsc --noEmit failing, then exiting 0 with packageExtensions eslint: ">=7". That isolated consumer was not re-run in this tree.

The other option is to remove the 'eslint' type import from the public surface and type the plugin with @typescript-eslint/utils (already a runtime dependency) or @eslint/core. That is the "more durable" option in the issue and is the direction of draft PR #425. The peer declaration is the smallest reversible packaging change, and it matches how @rushstack/eslint-plugin (already in this repo) declares ESLint. Rewriting IPlugin can reintroduce assignability failures against ESLint 10's Plugin type.

Can switch to the types-only approach, or to a tighter peer range (^8 || ^9 || ^10). >=7 may be wider than runtime support: this package already uses context.filename with no getFilename() fallback, and @typescript-eslint/utils@~8.56.0 peers ^8.57 || ^9 || ^10.

Test plan

  • rush test --only eslint-plugin-tsdoc (existing tsdoc/syntax RuleTester cases plus the new packaging invariant).
  • Packaging test fails when the peer is removed (missingPackageNames is ["eslint"]) and passes when it is restored.
  • rush change --verify against main.
  • rush install / rush update with the new peer: no pnpm-lock.yaml change required (eslint is already a devDependency).
  • Confirm no new peer warnings on a real ESLint 8/9/10 app that already depends on eslint; report if ESLint 7 should be dropped from the range.

The last box was not run.

Published typings import from 'eslint', so consumers under pnpm and Yarn PnP need it declared for TypeScript to resolve against the consumer's ESLint.
@cpruijsen

Copy link
Copy Markdown
Author

Christopher Pruijsen (Christopher Pruijsen (@cpruijsen)) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eslint-plugin-tsdoc: published typings import from 'eslint' without declaring it as a peer dependency

1 participant