Skip to content

fix(extensions): always calculate fix option #393

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

Merged
merged 5 commits into from
Jun 24, 2025

Conversation

lnhrdt
Copy link
Contributor

@lnhrdt lnhrdt commented Jun 23, 2025

close #391

Initially, it only adds failing test cases that expose the broken autofix behavior of the extensions rule.

Root issue

Autofix does not work unless both fix: true and a pattern object are set — even if the pattern is empty. This behavior is not intuitive, not documented, and not consistent with how autofix works in other ESLint rules.

Suggested solution

The rule should apply autofixes by default when it is safe to do so. The fix option should be removed entirely.

This PR starts by adding tests to document the current (broken) behavior.

Notes

  • There are around 80 tests in extensions.spec.ts, but none of the existing tests asserted on the actual output field, which is what validates whether autofixes are being applied. That gap likely contributed to this issue being missed.
  • The new tests are intentionally simple and direct, and I haven't attempted to deduplicate or reorganize them within the file. The test suite is already quite dense, and my focus was on surfacing the issue as clearly as possible.
  • This PR is open to edits by maintainers. If you'd like to continue from here and iterate toward a fix, feel free to push directly.
  • For an easier-to-follow standalone reproduction, see: https://github.com/lnhrdt/un-ts-eslint-plugin-import-x-issue-391

Important

Add failing tests in extensions.spec.ts to expose broken autofix behavior of extensions rule requiring both fix: true and a pattern object.

  • Tests:
    • Add failing test cases in extensions.spec.ts to expose broken autofix behavior of extensions rule.
    • Tests show autofix requires both fix: true and a pattern object, even if empty, to work.
    • Tests include cases for default autofix, fix: true, fix: true with pattern, and fix: false.

This description was created by Ellipsis for d51f400. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Tests
    • Added new test cases to verify autofix and suggestion behaviors for import path file extensions under different autofix settings.
  • Bug Fixes
    • Ensured consistent handling of the autofix option for import path extensions.
  • Documentation
    • Clarified that automatic fixing of import extensions requires explicit enabling of the fix option, with examples and future default behavior noted.

Copy link

changeset-bot bot commented Jun 23, 2025

🦋 Changeset detected

Latest commit: bd5a7b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-import-x Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Jun 23, 2025

Walkthrough

The test suite for the 'extensions' ESLint rule was updated by adding four new invalid test cases. These cases focus on verifying the rule's autofix behavior regarding '.js' file extensions in import statements, under various configurations of the fix option, including when autofix is enabled, disabled, or suggestions are provided. Additionally, the internal processing order of the fix option assignment was adjusted in the rule's option parsing logic.

Changes

File(s) Change Summary
test/rules/extensions.spec.ts Added four new invalid test cases to verify autofix and suggestion behaviors for import extensions.
src/rules/extensions.ts Moved the assignment of the fix property earlier in the option parsing sequence without changing logic.
.changeset/angry-lions-learn.md Added a changeset documenting a patch update fixing the calculation of the fix option.
docs/rules/extensions.md Added note clarifying autofix requires fix: true option and provided example configuration.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant ExtensionsRule

    TestRunner->>ExtensionsRule: Run with 'never' and various fix options
    ExtensionsRule-->>TestRunner: Detects '.js' extension in import
    alt fix enabled (default/true)
        ExtensionsRule-->>TestRunner: Returns autofixed import (extension removed)
    else fix false
        ExtensionsRule-->>TestRunner: Returns suggestion, no autofix
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Verify autofix works only when fix: true is set (Issue #391)
Verify autofix does not require a pattern object to be present to enable autofix (Issue #391) The fix option is assigned and respected regardless of the presence of a pattern object.
Confirm autofix is opt-in via fix: true and documented behavior (Issue #391) The tests and code reflect that autofix occurs only when fix: true is set explicitly.

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Possibly related PRs

Suggested labels

bug

Poem

Four new tests hop in with glee,
Checking if fixes work as they should be.
With or without ".js" in sight,
Autofix makes the imports right.
If fix is false, a suggestion appears—
The rabbit coder gives three cheers! 🐇✨


📜 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 e0ca333 and bd5a7b5.

📒 Files selected for processing (1)
  • docs/rules/extensions.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/rules/extensions.md
⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js lts/* and ESLint 9 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 24 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8.56 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8.56 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8.56 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 9 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 24 and ESLint 8.56 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8.56 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 24 and ESLint 9 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8.56 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 9 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on macos-latest
  • GitHub Check: Codacy Static Code Analysis

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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

Copy link

codesandbox-ci bot commented Jun 23, 2025

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.

Copy link

@ellipsis-dev ellipsis-dev bot left a 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 d51f400 in 1 minute and 20 seconds. Click for details.
  • Reviewed 78 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 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. test/rules/extensions.spec.ts:177
  • Draft comment:
    Good test: 'extensions should autofix by default' clearly checks that the autofix output is applied without an explicit fix option. Consider adding an inline comment referencing issue #391.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is purely informative, acknowledging a good test and suggesting an inline comment for reference. It doesn't provide a specific code suggestion or highlight a potential issue.
2. test/rules/extensions.spec.ts:190
  • Draft comment:
    The 'fix: true' test is clear and repeats the expected behavior. In future, consider consolidating similar cases to reduce duplication.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. test/rules/extensions.spec.ts:204
  • Draft comment:
    This test confirms that adding an empty pattern object with fix: true behaves like the basic case. The explicit nature of this test is good for future maintenance.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, as it describes what the test does and praises its explicit nature. It doesn't provide any actionable feedback or suggestions for improvement.
4. test/rules/extensions.spec.ts:218
  • Draft comment:
    The test for 'extensions should not autofix when fix is set to false' correctly checks that autofix is suppressed and suggestions are provided instead. This use of suggestions is clear and appropriate.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, as it simply states that the test is correct and appropriate. It does not provide any actionable feedback or suggestions for improvement.

Workflow ID: wflow_tVc2kLeFJtemCPAM

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

lnhrdt and others added 3 commits June 24, 2025 22:36
Follow-up to un-ts#391

These tests demonstrate that the `import-x/extensions` rule only applies autofixes when
both `fix: true` and a `pattern` object are set—even if the pattern is empty. This behavior
is unintuitive, undocumented, and inconsistent with how autofix typically works in ESLint.

The tests assert on the `output` field to document the current (broken) behavior and provide
a basis for resolving the issue.

In addition to fixing the logic, I recommend removing the `fix` option entirely, as it is
undocumented and not used in any other rule in the plugin.
@JounQin JounQin force-pushed the fix-extensions-autofix branch from 9c2f168 to 42b062f Compare June 24, 2025 14:59
@JounQin JounQin changed the title test(extensions): add failing tests to expose broken autofix behavior fix(extensions): always calculate fix option Jun 24, 2025
Signed-off-by: JounQin <admin@1stg.me>
Copy link

pkg-pr-new bot commented Jun 24, 2025

Open in StackBlitz

npm i https://pkg.pr.new/eslint-plugin-import-x@393

commit: bd5a7b5

@JounQin JounQin self-assigned this Jun 24, 2025
@JounQin JounQin added the bug Something isn't working label Jun 24, 2025
@JounQin JounQin merged commit 14cb948 into un-ts:master Jun 24, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extensions rule autofix requires strange configuration options to work
2 participants