-
-
Notifications
You must be signed in to change notification settings - Fork 53
fix: disallow extra properties in rule options #410
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
base: master
Are you sure you want to change the base?
fix: disallow extra properties in rule options #410
Conversation
|
WalkthroughThe changes update the JSON schema definitions for rule options in several files to explicitly disallow additional, undeclared properties. In one file, a shared schema object is introduced for reuse and clarity, and a type definition is slightly broadened. No runtime logic or control flow is altered. Changes
Suggested labels
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/rules/dynamic-import-chunkname.tsOops! Something went wrong! :( ESLint: 9.31.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js src/rules/no-namespace.tsOops! Something went wrong! :( ESLint: 9.31.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js src/rules/extensions.tsOops! Something went wrong! :( ESLint: 9.31.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🧰 Additional context used🧠 Learnings (4)📓 Common learnings
src/rules/dynamic-import-chunkname.ts (6)
src/rules/no-namespace.ts (2)
src/rules/no-unused-modules.ts (12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (7)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
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.
Important
Looks good to me! 👍
Reviewed everything up to 51af82f in 52 seconds. Click for details.
- Reviewed
169
lines of code in4
files - Skipped
0
files when reviewing. - Skipped posting
5
draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/rules/dynamic-import-chunkname.ts:51
- Draft comment:
✅ AddedadditionalProperties: false
in the options schema to prevent unnoticed typos. Confirm that no valid extra options are required. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
2. src/rules/extensions.ts:61
- Draft comment:
✅ AddingadditionalProperties: false
ensures that only defined schema keys are allowed. This increases the rule’s strictness. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
3. src/rules/no-namespace.ts:35
- Draft comment:
✅additionalProperties: false
is set for the options, ensuring that typos or unintended properties are caught. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
4. src/rules/no-unused-modules.ts:445
- Draft comment:
⚠️ Changed themissingExports
option type from literaltrue
toboolean
. Verify that existing configurations are updated accordingly. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =20%
<= threshold50%
The comment is asking the author to verify that existing configurations are updated, which is against the rules. It does not provide a specific suggestion or ask for a specific test to be written. It is more of a general cautionary note.
5. src/rules/no-unused-modules.ts:498
- Draft comment:
✅ Reusing a shared schema (SHARED_OPTIONS_SCHEMA_PROPERTIES
) and addingadditionalProperties: false
in each anyOf branch helps enforce strict option validation. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
Workflow ID: wflow_IObtdHUzkcHY1Yrx
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
@@ -444,13 +444,47 @@ const fileIsInPkg = (file: string) => { | |||
export interface Options { | |||
src?: string[] | |||
ignoreExports?: string[] | |||
missingExports?: true | |||
missingExports?: boolean | |||
unusedExports?: boolean |
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.
Maybe we should change it to be true
to align the json schema instead?
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.
Technically, the first branch of anyOf
allows missingExports
to have any boolean value, so I thought I'd change the TypeScript type to reflect that.
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.
We should align all the schemas I think?
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.
As in, move the enum: [true]
of unusedExports
to SHARED_OPTIONS_SCHEMA_PROPERTIES
? Should the same be done to missingExports
? In general, constraining boolean properties to just a single value looks like an uncommon practice. I wonder if this is needed at all?
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.
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.
To be honest I would probably set the type as boolean. So it should be possible for someone to set it to false even if it is the default
commit: |
Some rules, for example
dynamic-import-chunkname
currently allow extra properties to be passed in options object, which should not be allowed. This makes it easier for typos in rule options to go unnoticed.This PR simply disallows extra properties in rules' schemas which currently allow them.
Important
Disallow extra properties in rule options for
dynamic-import-chunkname
,extensions
,no-namespace
, andno-unused-modules
by settingadditionalProperties: false
in their schemas.additionalProperties: false
in the schema.dynamic-import-chunkname
,extensions
,no-namespace
, andno-unused-modules
rules.dynamic-import-chunkname.ts
: AddedadditionalProperties: false
to the options schema.extensions.ts
: AddedadditionalProperties: false
to theproperties
schema.no-namespace.ts
: AddedadditionalProperties: false
to the options schema.no-unused-modules.ts
: AddedadditionalProperties: false
to the options schema in two places.This description was created by
for 51af82f. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
Refactor
New Features
Chores