-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add type tests #65
Conversation
rules: { | ||
rules: /** @type {const} */ ({ | ||
"json/no-duplicate-keys": "error", | ||
"json/no-empty-keys": "error", | ||
"json/no-unsafe-values": "error", | ||
}, | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is const
cast syntax. I'm using this to ensure that properties in the rules
object have type "error"
rather than string
, because string
is too wide to be assigned to a severity:
type StringSeverity = "off" | "warn" | "error";
https://github.com/eslint/eslint/blob/v9.15.0/lib/types/index.d.ts#L917
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat trick!
@@ -9,7 +9,7 @@ | |||
|
|||
export default { | |||
meta: { | |||
type: "problem", | |||
type: /** @type {const} */ ("problem"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures that the type
property has type "problem"
rather than string
so it matches the definition in the interface:
type?: "problem" | "suggestion" | "layout" | undefined;
https://github.com/eslint/eslint/blob/v9.15.0/lib/types/index.d.ts#L760
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This is really cool. Thanks!
Prerequisites checklist
What is the purpose of this pull request?
Add type tests and fix some problems in the types.
What changes did you make? (Give an overview)
Added type tests to the CI workflow. I had to fix some minor issues in the typings of rules metadata and in the recommended config to match the signature of
ESLint.Plugin
. This is why this pull request is taggedfix:
.Related Issues
fixes #61
Is there anything you'd like reviewers to focus on?