Skip to content

Conversation

straker
Copy link
Contributor

@straker straker commented Apr 28, 2025

Adds eslint rules to restrict import paths from #4758, as well as virtual node use in utils.

@straker straker requested a review from a team as a code owner April 28, 2025 20:42
Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

This update introduces stricter ESLint rules to enforce architectural boundaries regarding import patterns across the codebase. Several files have been refactored to source their dependencies from internal modules instead of external packages, aligning with the new linting constraints. The ESLint ignore list is also refined to target a specific file rather than a broader pattern. No changes are made to exported or public entities; all modifications are limited to configuration and import statements.

Changes

File(s) Change Summary
eslint.config.js Extended ESLint rules to enforce strict import boundaries and usage constraints across various directories; refined ESLint ignore list.
lib/commons/text/has-unicode.js
lib/commons/text/remove-unicode.js
Changed import of emojiRegexText from external 'emoji-regex' to named import from internal '../../core/imports'.
lib/core/base/audit.js Changed import of doT from external '@deque/dot' to named import from internal '../imports'.
lib/core/utils/css-parser.js Changed import of CssSelectorParser from external 'css-selector-parser' to internal '../imports'.
lib/core/utils/memoize.js Changed import of memoize from external 'memoizee' to named import from internal '../imports'.

Sequence Diagram(s)

sequenceDiagram
    participant File as Source File (e.g., utils, commons, base)
    participant Imports as Internal Imports Module
    participant External as External Package

    File->>Imports: import { dependency } from '../imports'
    Imports->>External: (internally sources dependency)
    File-->>File: Uses dependency as before
Loading

This diagram illustrates the new import flow, where source files now import dependencies from a centralized internal module, which in turn manages access to external packages. This enforces stricter boundaries and centralized control over third-party dependencies.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (5)
eslint.config.js (5)

162-187: Same pattern object issue as above

The regex key is repeated here; please update to group (or convert to plain pattern strings) to ensure the rule actually runs.


188-212: Repeated mis-configuration (regex key) – fix required


213-230: Repeated mis-configuration (regex key) – fix required


231-253: Repeated mis-configuration (regex key) – fix required


255-276: Repeated mis-configuration (regex key) – fix required

🧹 Nitpick comments (1)
eslint.config.js (1)

368-369: Duplicate ignore entry for lib/core/imports/polyfills.js

polyfills.js is already whitelisted in the dedicated polyfill block (lines 317-321).
Keeping the duplicate in the global ignore list is harmless but clutters the config.

-      'lib/core/imports/polyfills.js',
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 344c65b and 7e7c733.

📒 Files selected for processing (6)
  • eslint.config.js (2 hunks)
  • lib/commons/text/has-unicode.js (1 hunks)
  • lib/commons/text/remove-unicode.js (1 hunks)
  • lib/core/base/audit.js (1 hunks)
  • lib/core/utils/css-parser.js (1 hunks)
  • lib/core/utils/memoize.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Security Review
🔇 Additional comments (5)
lib/commons/text/remove-unicode.js (1)

7-7: Good import refactoring to follow architectural boundaries

The import for emojiRegexText has been updated to use the centralized imports module instead of directly importing from an external package. This aligns with the new ESLint rules and improves architectural consistency.

lib/commons/text/has-unicode.js (1)

7-7: Consistent import path update

The import for emojiRegexText has been correctly updated to use the internal imports module, matching the same pattern applied in other files. This ensures consistent dependency management and complies with the new ESLint rules.

lib/core/utils/css-parser.js (1)

1-1: Import refactored to use centralized imports module

The import for CssSelectorParser has been updated to use the internal imports module instead of directly importing from an external package. This change aligns with the PR objectives and follows the same pattern as other import updates.

lib/core/utils/memoize.js (1)

1-1: Import path updated to follow architectural pattern

The import for memoize has been properly updated to use the internal imports module, which centralizes external dependencies. This helps enforce the architectural boundaries specified in the new ESLint rules.

eslint.config.js (1)

277-300: Virtual-node ban looks good – legacy exceptions documented

The explicit allow-list for the four legacy files plus the generic ban elsewhere is clear and will prevent future regressions.

patterns: [
{
regex: '^[^.]',
message: 'Only core/imports files should import from node modules'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this could summarize why we use this pattern (either directly or with a reference to an appropriate readme section/issue); future maintainers are more likely to respect the rule if it's cleary why it exists.

(I think this is more important for this rule and for the "no vNode in utils" thing (see comment below) than the other cases; the other ones are more obviously enforcing a non-circular import structure, but those two rules aren't so obvious about why they're here)

{
// e.g. "../commons/aria/" or "../public/"
regex:
'.*\\.\\.\\/(commons|imports|public|checks|rules)\\/|.*\\.\\.\\/reporters\\/.*?\\.js',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also forbid importing from the index files of the forbidden directories (eg, to catch a normal usage of importing from '../imports')

Suggested change
'.*\\.\\.\\/(commons|imports|public|checks|rules)\\/|.*\\.\\.\\/reporters\\/.*?\\.js',
'.*\\.\\.\\/(commons|imports|public|checks|rules)(\\/|$)|.*\\.\\.\\/reporters\\/.*?\\.js',

(same comment for the other similar rules)

}
},
{
// generally don't use virtual node in utils
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "generally" mean? How will a future maintainer know whether to apply the rule in a specific case? This should either justify why not, or if there is no articulable justification and there are several exceptions already, it probably shouldn't be a rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants