Skip to content

Conversation

nzakas
Copy link
Member

@nzakas nzakas commented Mar 28, 2025

Prerequisites checklist

What is the purpose of this pull request?

To simplify and extend the existing types in the package.

What changes did you make? (Give an overview)

Primarily:

  1. Switched to using @import in JSDoc comments, which allows importing generic types. That allowed a bunch of optimizations.
  2. Removed IJSONLanguage and IJSONSourceCode, swapping them out for the actual classes, both of which now have an @implements directly on their declarations.
  3. Updated JSONRuleDefinition based on discussion with @fasttime.
  4. Updated all of the rules accordingly.
  5. Updated dedupe-types.js to take into account @import statements.

Specifics:

  • src/languages/json-language.js: Consolidated type definitions and import statements for @humanwhocodes/momoa and @eslint/core, and updated the JSONLanguage class to use the new consolidated types. [1] [2] [3]
  • src/languages/json-source-code.js: Consolidated type definitions and import statements, and updated the JSONSourceCode class to use the new consolidated types. [1] [2] [3] [4] [5] [6] [7] [8]
  • src/rules/no-duplicate-keys.js: Consolidated type definitions and import statements for @humanwhocodes/momoa and ../types.ts, and updated the rule definition to use the new consolidated types.
  • src/rules/no-empty-keys.js: Consolidated type definitions and import statements for ../types.ts, and updated the rule definition to use the new consolidated types.
  • src/rules/no-unnormalized-keys.js: Consolidated type definitions and import statements for ../types.ts, and updated the rule definition to use the new consolidated types.
  • src/rules/no-unsafe-values.js: Consolidated type definitions and import statements for ../types.ts, and updated the rule definition to use the new consolidated types.
  • src/rules/sort-keys.js: Consolidated type definitions and import statements for @humanwhocodes/momoa and ../types.ts, and updated the rule definition to use the new consolidated types.
  • src/rules/top-level-interop.js: Consolidated type definitions and import statements for ../types.ts, and updated the rule definition to use the new consolidated types.
  • src/types.ts: Removed redundant type definitions and consolidated imports, and updated the JSONRuleDefinition type to use a more flexible and consolidated structure. [1] [2] [3] [4]

Related Issues

refs eslint/eslint#19521

Is there anything you'd like reviewers to focus on?

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request simplifies and extends the package’s type definitions by consolidating imports and updating JSDoc comments for improved clarity and reuse. Key changes include:

  • Switching to using @import in JSDoc comments to allow importing generic types.
  • Consolidating and updating type definitions and import statements in both types and rule files.
  • Updating rule definitions (and their JSDoc typedefs) to work with the new consolidated types.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/types.ts Consolidated import statements and updated JSONRuleDefinition types.
src/rules/top-level-interop.js Updated JSDoc typedefs to use the new JSONRuleDefinition pattern.
src/rules/sort-keys.js Revised JSDoc typedefs with additional options and clear import usage.
src/rules/no-unsafe-values.js Updated JSDoc typedefs to reflect consolidated type definitions.
src/rules/no-unnormalized-keys.js Adjusted JSDoc typedefs to include a new options type.
src/rules/no-empty-keys.js Updated JSDoc typedefs to the new JSONRuleDefinition style.
src/rules/no-duplicate-keys.js Revised JSDoc typedefs and consolidated imports for clarity.
src/languages/json-source-code.js Consolidated JSDoc import statements and updated type annotations.
src/languages/json-language.js Updated JSDoc typedefs and type annotations for JSON parsing.
Comments suppressed due to low confidence (2)

src/languages/json-source-code.js:29

  • The import for JSONSyntaxElement uses a .js extension while other similar imports reference .ts. Ensure the file extension is consistent with the actual file to avoid import resolution issues.
* @import { JSONSyntaxElement } from "../types.js";

src/languages/json-language.js:35

  • The type annotation references JSONSourceCode but there is no corresponding import. Consider adding an import for JSONSourceCode from './json-source-code.js' to ensure type correctness.
* @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>} 

@nzakas
Copy link
Member Author

nzakas commented Mar 28, 2025

Okay, this is harder than I thought. 😦 Needing to convert into CommonJS is causing a big mess here.

@mrmckeb
Copy link
Contributor

mrmckeb commented Mar 29, 2025

Thanks for the continued improvements here, @nzakas!

@fasttime fasttime added this to Triage Apr 1, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Apr 1, 2025
@fasttime fasttime moved this from Needs Triage to Triaging in Triage Apr 1, 2025
@fasttime fasttime moved this from Triaging to Implementing in Triage Apr 1, 2025
fasttime
fasttime previously approved these changes Apr 1, 2025
Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is already looking good. Would like another review before merging.

@fasttime fasttime moved this from Implementing to Second Review Needed in Triage Apr 1, 2025
Co-authored-by: Francesco Trotta <github@fasttime.org>
Comment on lines -60 to +61
export { JSONLanguage, JSONSourceCode };
export { JSONSourceCode };
export * from "./languages/json-language.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? I don't see any diff in dist/ this change is causing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because JSONLanguageOptions type is defined in json-language.js, it can only be exported from a JS file using *. (If this were a .ts file we could export it directly.)

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit dce4601 into main Apr 2, 2025
16 checks passed
@mdjermanovic mdjermanovic deleted the types-cleanup branch April 2, 2025 07:50
@github-project-automation github-project-automation bot moved this from Second Review Needed to Complete in Triage Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

4 participants