8000 feat: Add config types in @eslint/core by nzakas · Pull Request #237 · eslint/rewrite · GitHub
[go: up one dir, main page]

Skip to content

Conversation

nzakas
Copy link
Member
@nzakas nzakas commented Jul 9, 2025

Prerequisites checklist

What is the purpose of this pull request?

Copied config-related types over from the eslint package into @eslint/core

What changes did you make? (Give an overview)

  • Updated package.json files in packages/compat, packages/config-helpers, and packages/migrate-config to move @eslint/core to the dependencies section, ensuring it is available at runtime. [1] [2] [3]
  • Replaced eslint type imports with @eslint/core in packages/compat/src/fixup-rules.js, packages/compat/src/ignore-file.js, packages/config-helpers/src/define-config.js, packages/config-helpers/src/global-ignores.js, packages/config-helpers/src/types.ts, and packages/migrate-config/src/migrate-config.js. This includes updates to typedefs like Config, Plugin, RuleEntry, and others to their corresponding @eslint/core counterparts. [1] [2] [3] [4] [5] [6]
  • Renamed or adjusted type aliases for improved consistency, such as RuleEntry to RuleConfig and Linter.Config to ConfigObject. [1] [2]
  • Updated @typescript-eslint/array-type to enforce consistent array type definitions in TypeScript files. The rule is configured to use generic for default array types and array for readonly arrays.

Related Issues

fixes #226

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

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jul 9, 2025
@nzakas nzakas requested a review from Copilot July 9, 2025 19:15
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 PR centralizes config-related types in the @eslint/core package, updates downstream packages to import those types, and enforces a consistent array type syntax.

  • Moved or added @eslint/core as a dependency and replaced eslint type imports with @eslint/core equivalents in compat, config-helpers, and migrate-config.
  • Renamed several type aliases for consistency (e.g., RuleEntryRuleConfig, Linter.ConfigConfigObject).
  • Enabled the @typescript-eslint/array-type rule and updated all array type declarations to the generic form.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/migrate-config/src/migrate-config.js Updated JSDoc typedefs to import new config types from @eslint/core.
packages/migrate-config/package.json Replaced @types/eslint with @eslint/core in devDependencies.
packages/config-helpers/src/types.ts Switched imports and array type syntax to use @eslint/core and Array<T>.
packages/config-helpers/src/global-ignores.js Updated JSDoc typedef to use @eslint/core ConfigObject.
packages/config-helpers/src/define-config.js Replaced several JSDoc typedefs to import types from @eslint/core.
packages/config-helpers/package.json Moved @eslint/core from devDependencies to dependencies.
packages/compat/src/ignore-file.js Updated typedef to import ConfigObject from @eslint/core.
packages/compat/src/fixup-rules.js Replaced JSDoc typedefs to import plugin, rule, and config types from core.
packages/compat/package.json Moved @eslint/core from devDependencies to dependencies.
packages/core/src/types.ts Converted all T[] and any[] usages to Array<T> and added new config types.
eslint.config.js Enforced the @typescript-eslint/array-type rule (generic for default arrays).
Comments suppressed due to low confidence (2)

packages/core/src/types.ts:723

  • It may be helpful to add type-level tests (e.g., with dtslint) for the new ConfigObject and related types to ensure they enforce the intended constraints and catch future regressions.
export interface ConfigObject<Rules extends RulesConfig = RulesConfig> {

packages/core/src/types.ts:103

  • [nitpick] This file has grown significantly in size and responsibility. Consider splitting core, config, and legacy type definitions into separate modules to improve readability and maintainability.
	((...args: Array<any>) => void) | undefined

/**
* The configuration for a set of files.
*/
export interface ConfigObject<Rules extends RulesConfig = RulesConfig> {
Copy link
Member Author

Choose a reason for hiding this comment

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

I used ConfigObject instead of Config to disambiguate with the Config class in eslint.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, this has been a mild confusion for me for a while!

/* eslint-disable @typescript-eslint/consistent-indexed-object-style, @typescript-eslint/no-explicit-any -- needed for backward compatibility */

/** @deprecated Only supported in legacy eslintrc config format. */
export type GlobalAccess =
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed from GlobalConf for clarity.

| "writeable";

/** @deprecated Only supported in legacy eslintrc config format. */
export interface GlobalsConfig {
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed from Globals for clarity.

/**
* The type of JavaScript source code.
*/
type JavaScriptSourceType = "script" | "module" | "commonjs";
Copy link
Member Author

Choose a reason for hiding this comment

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

renamed from SourceType for clarity

* @deprecated Only supported in legacy eslintrc config format.
* @see [Specifying Parser Options](https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options)
*/
export interface JavaScriptParserOptionsConfig {
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed from ParserOptions for clarity.

}

/** @deprecated Only supported in legacy eslintrc config format. */
export interface EnvironmentConfig {
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed from Environments for clarity.

* @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/)
*/
// https://github.com/eslint/eslint/blob/v8.57.0/conf/config-schema.js
export interface LegacyConfigObject<
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed from LegacyConfig to match ConfigObject

@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Jul 15, 2025
@lumirlumir
Copy link
Member

Hi, it looks like the CI is currently failing. Would you mind taking a look when you have a moment?

Copy link
Contributor
@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

🔥 Lovely! I'm really excited to have @eslint/core provide these types as a full dependency.

I'd like to see input from @kirkwaiblinger since Kirk has been working more deeply on the types integrations. This structure looks good to me and on playing around with the types, but if there's some deep intricate issue I might not know it.

*/
interface LintSuggestion {
/** A short description. */

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

/**
* The configuration for a set of files.
*/
export interface ConfigObject<Rules extends RulesConfig = RulesConfig> {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, this has been a mild confusion for me for a while!

*/
fix?: RuleFixer | null | undefined;
fix?: RuleTextEdit | undefined;

Copy link
Contributor

Choose a reason for hiding this comment

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

Just confirming, was this actual change intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the original one was incorrect.

* An object containing settings related to how JavaScript is configured for
* linting.
*/
languageOptions?: LanguageOptions;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that LanguageOptions is just Record<string, unknown> for now...

Can it include a parser field with a real Parser type (also exported)?

I had a hard time finding an ESLint-authored type for a parser, see https://github.com/typescript-eslint/typescript-eslint/pull/11190/files#diff-4f6c93a5b54f249fc56a41d19a39f8279bb5f633f2f379c7b8a2272aca3b68ebR13-R15

Copy link
Member Author

Choose a reason for hiding this comment

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

parser is a JavaScript-specific language option, and this is meant to work for all languages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see. All the same can a Parser type be exported for downstream use? (Ie not enforced within languageOptions but just the type made available)

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this can be a separate request/followup too

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, please open a separate issue for that.

@nzakas
Copy link
Member Author
nzakas commented Jul 29, 2025

I think this is finally ready. 🎉

Copy link
linux-foundation-easycla bot commented Jul 31, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@fasttime
Copy link
Member
fasttime commented Aug 1, 2025

It looks like something went wrong with the rebase. Can you check?

@nzakas
Copy link
Member Author
nzakas commented Aug 22, 2025

Okay, I think I fixed the rebase issues and addressed the other feedback.

fasttime
fasttime previously approved these changes Aug 25, 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.

Just a few minor suggestions, then LGTM. Leaving open for @mdjermanovic to review as requested.

@fasttime fasttime moved this from Implementing to Second Review Needed in Triage Aug 25, 2025
Co-authored-by: Francesco Trotta <github@fasttime.org>
nzakas and others added 2 commits August 25, 2025 10:46
Co-authored-by: Francesco Trotta <github@fasttime.org>
Co-authored-by: Francesco Trotta <github@fasttime.org>
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 7b6dd37 into main Aug 27, 2025
21 checks passed
@mdjermanovic mdjermanovic deleted the types-move branch August 27, 2025 16:58
@github-project-automation github-project-automation bot moved this from Second Review Needed to Complete in Triage Aug 27, 2025
@github-actions github-actions bot mentioned this pull request Aug 25, 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.

Bug: config-helpers lacks a dependency on eslint required by exported types

6 participants

0