eslint-plugin-import-x
eslint-plugin-import-x copied to clipboard
fix: disallow extra properties in rule options
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-modulesby settingadditionalProperties: falsein their schemas.
- Behavior:
- Disallow extra properties in rule options by setting
additionalProperties: falsein the schema.- Affects
dynamic-import-chunkname,extensions,no-namespace, andno-unused-modulesrules.- Schema Changes:
dynamic-import-chunkname.ts: AddedadditionalProperties: falseto the options schema.extensions.ts: AddedadditionalProperties: falseto thepropertiesschema.no-namespace.ts: AddedadditionalProperties: falseto the options schema.no-unused-modules.ts: AddedadditionalProperties: falseto the options schema in two places.This description was created by
for 51af82fe2a05001c2759aec8746b27a61a2e7987. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
-
Refactor
- Improved the configuration validation for several rules by restricting options to only allow explicitly defined properties.
- Consolidated and clarified schema definitions for rule options to enhance maintainability.
-
New Features
- Rule options now provide stricter validation, preventing unrecognized properties in configurations.
-
Chores
- Updated the type of an option in one rule to allow for clearer configuration.
⚠️ No Changeset found
Latest commit: 51af82fe2a05001c2759aec8746b27a61a2e7987
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Walkthrough
The 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
| File(s) | Change Summary |
|---|---|
| src/rules/dynamic-import-chunkname.ts, src/rules/extensions.ts, src/rules/no-namespace.ts |
Added "additionalProperties": false to JSON schema definitions for rule options, restricting options to declared fields. |
| src/rules/no-unused-modules.ts | Refactored schema using a shared schema object, set "additionalProperties": false, and changed an interface property type from true to boolean. |
Suggested labels
refactor
Poem
In the warren, schemas grow neat and tight,
No stray carrots hiding out of sight.
Properties declared, the rest kept at bay—
A rabbit’s rules, clear as the day!
Hopping through code, with schemas refined,
Bugs and confusion are left behind.
🥕
[!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
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
src/rules/dynamic-import-chunkname.ts
Oops! Something went wrong! :(
ESLint: 9.31.0
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js at finalizeResolution (node:internal/modules/esm/resolve:274:11) at moduleResolve (node:internal/modules/esm/resolve:859:10) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38) at #link (node:internal/modules/esm/module_job:202:49)
src/rules/no-namespace.ts
Oops! Something went wrong! :(
ESLint: 9.31.0
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js at finalizeResolution (node:internal/modules/esm/resolve:274:11) at moduleResolve (node:internal/modules/esm/resolve:859:10) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38) at #link (node:internal/modules/esm/module_job:202:49)
src/rules/extensions.ts
Oops! Something went wrong! :(
ESLint: 9.31.0
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js at finalizeResolution (node:internal/modules/esm/resolve:274:11) at moduleResolve (node:internal/modules/esm/resolve:859:10) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38) at #link (node:internal/modules/esm/module_job:202:49)
- 1 others
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between d0a78167791f41804e880356c9c69d7a45c4b45d and 51af82fe2a05001c2759aec8746b27a61a2e7987.
📒 Files selected for processing (4)
src/rules/dynamic-import-chunkname.ts(1 hunks)src/rules/extensions.ts(1 hunks)src/rules/no-namespace.ts(1 hunks)src/rules/no-unused-modules.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: ESLint core ExternalSpecifier interface has optional name and url string properties. The current eslint-plugin-import-x implementation correctly uses this structure for the rule property within replacedBy arrays in DeprecatedInfo objects.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: The current implementation in eslint-plugin-import-x uses the correct ESLint core DeprecatedInfo structure: deprecatedSince field and replacedBy array with objects containing rule properties that match the ExternalSpecifier type with name and url fields.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#386
File: src/rules/prefer-namespace-import.ts:41-46
Timestamp: 2025-06-18T15:22:38.532Z
Learning: In eslint-plugin-import-x, JounQin prefers to throw on invalid rule options rather than handling them gracefully with try/catch blocks and reporting configuration errors.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#271
File: test/rules/no-unused-modules.spec.ts:1528-1532
Timestamp: 2025-03-30T09:06:59.006Z
Learning: The import from 'eslint8.56/use-at-your-own-risk' has incorrect TypeScript types but works correctly at runtime, which is properly handled with a `@ts-expect-error` comment.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: The ESLint core DeprecatedInfo type uses `deprecatedSince` field (not `since`) and the current structure with `replacedBy` containing objects with a `rule` property is correct according to the official ESLint core type definitions.
src/rules/dynamic-import-chunkname.ts (6)
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: ESLint core ExternalSpecifier interface has optional name and url string properties. The current eslint-plugin-import-x implementation correctly uses this structure for the rule property within replacedBy arrays in DeprecatedInfo objects.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#271
File: test/rules/no-unused-modules.spec.ts:1528-1532
Timestamp: 2025-03-30T09:06:59.006Z
Learning: The import from 'eslint8.56/use-at-your-own-risk' has incorrect TypeScript types but works correctly at runtime, which is properly handled with a `@ts-expect-error` comment.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: The current implementation in eslint-plugin-import-x uses the correct ESLint core DeprecatedInfo structure: deprecatedSince field and replacedBy array with objects containing rule properties that match the ExternalSpecifier type with name and url fields.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#386
File: src/rules/prefer-namespace-import.ts:41-46
Timestamp: 2025-06-18T15:22:38.532Z
Learning: In eslint-plugin-import-x, JounQin prefers to throw on invalid rule options rather than handling them gracefully with try/catch blocks and reporting configuration errors.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#362
File: src/utils/import-declaration.ts:1-2
Timestamp: 2025-05-31T03:11:08.864Z
Learning: TypeScript type-only imports (using `import type`) are stripped during compilation and do not affect production dependencies or bundle size. Only runtime imports need to be considered when managing production dependencies in TypeScript projects.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#362
File: src/utils/create-rule.ts:0-0
Timestamp: 2025-05-31T03:10:38.972Z
Learning: When `rewriteRelativeImportExtensions` is enabled in TypeScript configuration, using `.ts` extensions in import paths is correct and necessary for Node.js ESM compatibility. TypeScript will rewrite these to `.js` during compilation.
src/rules/no-namespace.ts (2)
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: ESLint core ExternalSpecifier interface has optional name and url string properties. The current eslint-plugin-import-x implementation correctly uses this structure for the rule property within replacedBy arrays in DeprecatedInfo objects.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#386
File: src/rules/prefer-namespace-import.ts:41-46
Timestamp: 2025-06-18T15:22:38.532Z
Learning: In eslint-plugin-import-x, JounQin prefers to throw on invalid rule options rather than handling them gracefully with try/catch blocks and reporting configuration errors.
src/rules/no-unused-modules.ts (12)
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: The current implementation in eslint-plugin-import-x uses the correct ESLint core DeprecatedInfo structure: deprecatedSince field and replacedBy array with objects containing rule properties that match the ExternalSpecifier type with name and url fields.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: ESLint core ExternalSpecifier interface has optional name and url string properties. The current eslint-plugin-import-x implementation correctly uses this structure for the rule property within replacedBy arrays in DeprecatedInfo objects.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#271
File: test/rules/no-unused-modules.spec.ts:1528-1532
Timestamp: 2025-03-30T09:06:59.006Z
Learning: The import from 'eslint8.56/use-at-your-own-risk' has incorrect TypeScript types but works correctly at runtime, which is properly handled with a `@ts-expect-error` comment.
Learnt from: 43081j
PR: un-ts/eslint-plugin-import-x#304
File: src/rules/avoid-barrel-files.ts:74-85
Timestamp: 2025-05-07T09:03:58.638Z
Learning: According to the ESTree specification, an `ExportDefaultDeclaration` node always has a `declaration` property, making optional chaining (`?.`) unnecessary when accessing `n.declaration.type`.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#362
File: src/utils/import-declaration.ts:1-2
Timestamp: 2025-05-31T03:11:08.864Z
Learning: TypeScript type-only imports (using `import type`) are stripped during compilation and do not affect production dependencies or bundle size. Only runtime imports need to be considered when managing production dependencies in TypeScript projects.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#378
File: src/rules/imports-first.ts:10-19
Timestamp: 2025-06-08T12:09:38.535Z
Learning: The ESLint core DeprecatedInfo type uses `deprecatedSince` field (not `since`) and the current structure with `replacedBy` containing objects with a `rule` property is correct according to the official ESLint core type definitions.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#362
File: src/utils/create-rule.ts:0-0
Timestamp: 2025-05-31T03:10:38.972Z
Learning: When `rewriteRelativeImportExtensions` is enabled in TypeScript configuration, using `.ts` extensions in import paths is correct and necessary for Node.js ESM compatibility. TypeScript will rewrite these to `.js` during compilation.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#357
File: package.json:160-160
Timestamp: 2025-05-30T15:39:53.248Z
Learning: The `typescript-eslint` package (without the `@typescript-eslint/` namespace) is the official unified entry package for ESLint flat config, not an incorrect package name.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#272
File: test/rules/no-unresolved.spec.ts:293-325
Timestamp: 2025-05-30T13:24:29.760Z
Learning: Node.js ES6 import statements do not support plain Windows absolute paths like `C:\path\to\file.js` because import specifiers are resolved as URLs, not plain file paths. Plain Windows absolute paths conflict with URL schemes and create ambiguity. For absolute imports on Windows, you must use `file://` URLs instead.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#385
File: src/rules/prefer-namespace-import.ts:0-0
Timestamp: 2025-06-18T12:49:41.795Z
Learning: The eslint-plugin-import-x project requires Node versions `^18.18.0 || ^20.9.0 || >=21.1.0` as specified in package.json, so modern JavaScript features like String.prototype.at() are safe to use.
Learnt from: SukkaW
PR: un-ts/eslint-plugin-import-x#272
File: src/utils/resolve.ts:0-0
Timestamp: 2025-03-30T14:44:11.779Z
Learning: In eslint-plugin-import-x's node resolver, the `modules` parameter of `createNodeResolver` function accepts both string and string array types, making it flexible when passing values like `moduleDirectory`.
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#386
File: src/rules/prefer-namespace-import.ts:41-46
Timestamp: 2025-06-18T15:22:38.532Z
Learning: In eslint-plugin-import-x, JounQin prefers to throw on invalid rule options rather than handling them gracefully with try/catch blocks and reporting configuration errors.
⏰ 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)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (7)
src/rules/extensions.ts (1)
61-61: LGTM! Schema restriction correctly implemented.The addition of
additionalProperties: falseproperly restricts the rule options to only allow explicitly defined properties, preventing typos in rule configuration from being silently ignored.src/rules/no-namespace.ts (1)
35-35: LGTM! Consistent schema restriction applied.The addition of
additionalProperties: falsecorrectly restricts the options object to only allow the definedignoreproperty, maintaining consistency with the PR's objective to prevent typos in rule options.src/rules/dynamic-import-chunkname.ts (1)
51-51: LGTM! Schema validation properly tightened.The addition of
additionalProperties: falsecorrectly restricts the options object to only allow the three explicitly defined properties (importFunctions,allowEmpty,webpackChunknameFormat), preventing configuration typos from being silently accepted.src/rules/no-unused-modules.ts (4)
9-9: LGTM! Proper import added for schema typing.The addition of
JSONSchemaimport is necessary for properly typing the shared schema object introduced later in the file.
447-447: LGTM! Type definition appropriately broadened.The change from
missingExports?: truetomissingExports?: booleanis a reasonable broadening of the type while still enforcing thetruevalue through the schema enum constraint.
454-486: LGTM! Excellent schema refactoring for reusability.The introduction of
SHARED_OPTIONS_SCHEMA_PROPERTIESis a good practice that:
- Reduces code duplication
- Centralizes schema property definitions
- Improves maintainability
- Provides clear descriptions for each property
503-530: LGTM! Schema properly updated with shared properties and restrictions.The changes correctly:
- Utilize the shared schema properties to reduce duplication
- Add
additionalProperties: falseto both option objects in theanyOfarray- Maintain proper schema validation while preventing extra properties
- Keep the required enum constraints for
unusedExportsandmissingExportsThis effectively implements the PR objective while improving code organization.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
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.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need 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)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
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.