Skip to content

Change Request: Make the data property stricter #310

@lumirlumir

Description

@lumirlumir

Which packages would you like to change?

  • @eslint/compat
  • @eslint/config-array
  • @eslint/config-helpers
  • @eslint/core
  • @eslint/mcp
  • @eslint/migrate-config
  • @eslint/object-schema
  • @eslint/plugin-kit

What problem do you want to solve?

This request proposes tightening the SuggestedEditBase's data property, which is used by context.report.

export interface SuggestedEditBase {
/**
* The data to insert into the message.
*/
data?: Record<string, unknown> | undefined;
/**
* The fix to be applied for the suggestion.
*/
fix: RuleFixer;
}

In PR #298, the data property's type was widened from Record<string, string> to Record<string, unknown>.

However, I think this type is overly broad for the following reason:


Image

All data properties can be stringified, but I'm not sure using unknown here is the best approach. I think it's too broad a type to accept.

Although Symbol, Function, and Object values can be stringified, the result is often meaningless to be used as a message and they aren't stringified like normal primitive values. For example:

console.log(String(Symbol("symbol")));

// Output: Symbol(symbol)

console.log(
	String({
		hi: {
			bye: {
				hi: "hi",
			},
		},
	}),
);

// Output: [object Object]

console.log(String(() => {}));

// Output: () => {}

For the following reason, I think using string | number | boolean | bigint, or adding another type if necessary, would be more appropriate here.

What do you think is the correct solution?

Narrow the type to string | number | boolean | bigint (or something similar) from unknown.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Feedback Needed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions