Skip to content

Conversation

@crutch12
Copy link
Contributor

@crutch12 crutch12 commented Dec 2, 2025

Summary

Continuation of this PR: #6594

  • remove eslint's import/order rules to keep imports order consistency with prettier only
  • run prettier on lint-staged hook

To Test

  1. Change js/ts/md file
  2. Run git commit

Every new commit should trigger prettier --write with changed files

Background

Performance on my pc for the whole project:

  • npx eslint . --fix - 65 seconds
  • npx eslint . --fix --concurrency auto - 45 seconds

Summary by CodeRabbit

  • New Features

    • Introduced automated import sorting to standardize code organization across the codebase.
    • Extended pre-commit linting to additional file types (markdown, JSON, CSS, HTML, YAML).
  • Chores

    • Refactored Prettier configuration for improved code formatting consistency.
    • Updated ESLint configuration to delegate import ordering to Prettier.
    • Updated lint-staged dependency for enhanced pre-commit workflow.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 2, 2025

@crutch12 is attempting to deploy a commit to the cow-dev Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Walkthrough

This PR consolidates and restructures Prettier configuration across the monorepo by introducing a root prettier.config.js with import-sort rules and app-specific overrides, removes the root .prettierrc, expands lint-staged to handle additional file types with separate Prettier and ESLint passes, and adds import-sort-ignore comments to test files. Additionally, the install-sdk-preview script is refactored for safety.

Changes

Cohort / File(s) Summary
Prettier Configuration
.prettierignore, .prettierrc, prettier.config.js, apps/cow-fi/prettier.config.js, apps/cowswap-frontend/.prettierrc, apps/cowswap-frontend/prettier.config.js
Removed root .prettierrc; introduced new root prettier.config.js with import-sort plugin, import ordering rules, and configuration exports; updated .prettierignore with generated ABI and changelog entries; created app-specific configs in cow-fi and cowswap-frontend that extend or override base config.
Linting Configuration
eslint.config.js, lint-staged.config.js
Expanded ESLint ignores list (.nx/, **/.next/, build/, dist/); disabled import/order rule with note that it's now enforced via Prettier; restructured lint-staged to handle .{ts,tsx,js,jsx,mjs,mts,md,json,css,html,yaml,yml} files with separate Prettier and ESLint passes.
Test File Annotations
apps/cowswap-frontend/src/modules/application/containers/App/FaviconAnimationUpdater.test.ts, apps/cowswap-frontend/src/modules/application/utils/faviconAnimation/controller.test.ts, apps/cowswap-frontend/src/modules/sounds/utils/sound.test.ts, apps/cowswap-frontend/src/modules/tradeQuote/services/fetchAndProcessQuote.test.ts
Added // sort-imports-ignore // disabled for tests comment at top of each file.
Dependencies
package.json
Added @trivago/prettier-plugin-sort-imports dependency; bumped lint-staged from ^16.1.2 to ^16.2.7.
Import Organization
libs/abis/src/index.ts, libs/core/src/jotaiStore.ts
Moved legacy ABI imports to top in libs/abis; added AsyncStringStorage import in libs/core.
Build & Script Updates
apps/cowswap-frontend/vite.config.mts, tools/scripts/install-sdk-preview.js
Consolidated duplicate plugin imports in vite config; refactored install-sdk-preview.js script into run() function with early validation checks and npmrc registry configuration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas requiring extra attention:
    • Verify prettier.config.js import ordering rules align with project conventions and do not conflict with existing tooling
    • Confirm app-specific Prettier configs (prettier.config.js in cow-fi and cowswap-frontend) correctly extend/override base config without causing formatting inconsistencies
    • Review lint-staged changes to ensure Prettier and ESLint execution order and file filtering work correctly together
    • Validate tools/scripts/install-sdk-preview.js refactoring maintains intended behavior with early guard checks and npmrc configuration

Possibly related PRs

  • PR #6313: Modifies tools/scripts/install-sdk-preview.js to restructure the SDK preview installation script logic
  • PR #6331: Updates favicon-related test files with similar annotations and configuration adjustments

Suggested reviewers

  • alfetopito
  • elena-zh
  • cowdan

Poem

🐰 Prettier paths now align with grace,
Import sorting finds its rightful place,
Linting rules defer to Prettier's hand,
The monorepo now follows one grand plan,
Tests stay quiet, ignoring the sort,
Config blessed in each respected court!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: running Prettier on lint-staged, and notes the blocking dependency.
Description check ✅ Passed The description follows the template with Summary, To Test, and Background sections; all required information is present and complete.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@socket-security
Copy link

@socket-security
Copy link

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn Critical
Critical CVE: Babel vulnerable to arbitrary code execution when compiling specifically crafted malicious code in npm @babel/traverse

CVE: GHSA-67hx-6x53-jw92 Babel vulnerable to arbitrary code execution when compiling specifically crafted malicious code (CRITICAL)

Affected versions: < 7.23.2; >= 8.0.0-alpha.0 < 8.0.0-alpha.4

Patched version: 7.23.2

From: ?npm/@babel/[email protected]

ℹ Read more on: This package | This alert | What is a critical CVE?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Remove or replace dependencies that include known critical CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@babel/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

Copy link
Contributor

@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: 1

♻️ Duplicate comments (3)
apps/cowswap-frontend/src/modules/application/containers/App/FaviconAnimationUpdater.test.ts (1)

1-2: Same sort-imports-ignore comment consideration as other tests

Same note as in fetchAndProcessQuote.test.ts: consider putting // sort-imports-ignore on its own line with the explanation on the next line to ensure the Prettier sort-imports plugin reliably honors the ignore.

apps/cowswap-frontend/src/modules/application/utils/faviconAnimation/controller.test.ts (1)

1-2: Consistent handling of sort-imports-ignore

To stay consistent and avoid any chance of the plugin missing the directive, consider using:

// sort-imports-ignore
// disabled for tests

as in the earlier recommendation.

apps/cowswap-frontend/src/modules/sounds/utils/sound.test.ts (1)

1-2: Apply the same sort-imports-ignore pattern here

As with the other test files, consider:

// sort-imports-ignore
// disabled for tests

to ensure the sort-imports Prettier plugin reliably respects the ignore in this file too.

🧹 Nitpick comments (2)
apps/cowswap-frontend/prettier.config.js (1)

1-5: Thin wrapper over root Prettier config is fine (optional simplification)

This correctly reuses the root config. If you don’t plan per‑app overrides here, you could simplify to module.exports = require('../../prettier.config'), but the current form is perfectly acceptable.

apps/cow-fi/prettier.config.js (1)

1-15: Harden plugin pruning against non‑array / non‑string entries

The intent (dropping the sort‑imports plugin and all importOrder* keys) matches the comment. To make this more future‑proof, guard against plugins being missing or containing non‑string entries:

-// cow-fi eslint config has been ignoring import/order rules, so we disable prettier import order rules
-config.plugins = [...config.plugins].filter((p) => !p.includes('@trivago/prettier-plugin-sort-imports'))
+// cow-fi eslint config has been ignoring import/order rules, so we disable prettier import order rules
+if (Array.isArray(config.plugins)) {
+  config.plugins = config.plugins.filter(
+    (p) => typeof p === 'string' && !p.includes('@trivago/prettier-plugin-sort-imports'),
+  )
+}

The Object.keys(config)…delete config[key] block is otherwise a clear way to strip all importOrder* options.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce4d7e3 and e806025.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (17)
  • .prettierignore (1 hunks)
  • .prettierrc (0 hunks)
  • apps/cow-fi/prettier.config.js (1 hunks)
  • apps/cowswap-frontend/.prettierrc (0 hunks)
  • apps/cowswap-frontend/prettier.config.js (1 hunks)
  • apps/cowswap-frontend/src/modules/application/containers/App/FaviconAnimationUpdater.test.ts (1 hunks)
  • apps/cowswap-frontend/src/modules/application/utils/faviconAnimation/controller.test.ts (1 hunks)
  • apps/cowswap-frontend/src/modules/sounds/utils/sound.test.ts (1 hunks)
  • apps/cowswap-frontend/src/modules/tradeQuote/services/fetchAndProcessQuote.test.ts (1 hunks)
  • apps/cowswap-frontend/vite.config.mts (1 hunks)
  • eslint.config.js (2 hunks)
  • libs/abis/src/index.ts (1 hunks)
  • libs/core/src/jotaiStore.ts (1 hunks)
  • lint-staged.config.js (1 hunks)
  • package.json (2 hunks)
  • prettier.config.js (1 hunks)
  • tools/scripts/install-sdk-preview.js (2 hunks)
💤 Files with no reviewable changes (2)
  • .prettierrc
  • apps/cowswap-frontend/.prettierrc
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-07-28T16:26:08.051Z
Learnt from: cowdan
Repo: cowprotocol/cowswap PR: 6034
File: apps/cowswap-frontend-e2e/src/e2e/fiat-amounts.test.ts:44-47
Timestamp: 2025-07-28T16:26:08.051Z
Learning: In the cowswap codebase, using trivial placeholder tests like `it('should be true', () => { expect(true).to.be.true })` in e2e test files is an intentional pattern when disabling broken tests to keep CI green while maintaining build efficiency.

Applied to files:

  • apps/cowswap-frontend/src/modules/application/utils/faviconAnimation/controller.test.ts
  • apps/cowswap-frontend/src/modules/sounds/utils/sound.test.ts
  • apps/cowswap-frontend/src/modules/application/containers/App/FaviconAnimationUpdater.test.ts
  • apps/cowswap-frontend/src/modules/tradeQuote/services/fetchAndProcessQuote.test.ts
📚 Learning: 2025-09-25T08:48:53.495Z
Learnt from: shoom3301
Repo: cowprotocol/cowswap PR: 6299
File: apps/cowswap-frontend/src/entities/bridgeProvider/useBridgeSupportedNetworks.test.tsx:58-60
Timestamp: 2025-09-25T08:48:53.495Z
Learning: In the cowswap-frontend codebase, when writing SWR tests, the team prefers maximum test isolation by using `provider: () => new Map()` in SWRConfig wrappers, even if it recreates cache on every render, to ensure tests don't share any state.

Applied to files:

  • apps/cowswap-frontend/src/modules/sounds/utils/sound.test.ts
📚 Learning: 2025-09-25T08:49:32.256Z
Learnt from: shoom3301
Repo: cowprotocol/cowswap PR: 6299
File: apps/cowswap-frontend/src/entities/bridgeProvider/useBridgeSupportedNetworks.test.tsx:62-67
Timestamp: 2025-09-25T08:49:32.256Z
Learning: In the cowswap-frontend codebase, when testing hooks that use multiple bridge providers, both providers are always properly mocked as complete jest.Mocked<BridgeProvider<BridgeQuoteResult>> objects with all required methods stubbed, ensuring no undefined returns that could break the hook logic.

Applied to files:

  • apps/cowswap-frontend/src/modules/sounds/utils/sound.test.ts
  • apps/cowswap-frontend/src/modules/tradeQuote/services/fetchAndProcessQuote.test.ts
📚 Learning: 2025-09-11T08:25:51.460Z
Learnt from: alfetopito
Repo: cowprotocol/cowswap PR: 6234
File: libs/tokens/src/index.ts:1-4
Timestamp: 2025-09-11T08:25:51.460Z
Learning: In the cowprotocol/cowswap project, there is currently no SSR (Server-Side Rendering) support, so localStorage access at module import time does not cause SSR-related issues.

Applied to files:

  • apps/cowswap-frontend/src/modules/sounds/utils/sound.test.ts
📚 Learning: 2025-08-08T13:56:18.009Z
Learnt from: shoom3301
Repo: cowprotocol/cowswap PR: 6125
File: libs/tokens/src/updaters/TokensListsUpdater/index.tsx:29-31
Timestamp: 2025-08-08T13:56:18.009Z
Learning: In libs/tokens/src/updaters/TokensListsUpdater/index.tsx, the project’s current Jotai version requires using `unstable_getOnInit` (not `getOnInit`) in atomWithStorage options; keep `{ unstable_getOnInit: true }` until Jotai is upgraded.

Applied to files:

  • libs/core/src/jotaiStore.ts
🧬 Code graph analysis (2)
apps/cowswap-frontend/prettier.config.js (1)
apps/cow-fi/prettier.config.js (1)
  • config (1-3)
apps/cow-fi/prettier.config.js (1)
apps/cowswap-frontend/prettier.config.js (1)
  • config (1-1)
⏰ 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: Socket Security: Pull Request Alerts
🔇 Additional comments (10)
apps/cowswap-frontend/vite.config.mts (1)

8-8: LGTM! Import consolidation improves code organization.

These imports were deduplicated and moved to the top of the file, which follows best practices and improves maintainability.

Also applies to: 17-17

libs/core/src/jotaiStore.ts (1)

3-4: AsyncStringStorage import aligns the type usage

Wiring up the explicit AsyncStringStorage import to match the existing storage: AsyncStringStorage annotation in atomWithIdbStorage is correct and keeps typings in sync without changing runtime behavior.

.prettierignore (1)

5-7: Ignoring generated and tooling files from Prettier looks appropriate

Adding .cursor/, the generated ABIs under /libs/abis/src/generated, and CHANGELOG.md to .prettierignore is reasonable to prevent unwanted formatting noise on non-source or generated content.

libs/abis/src/index.ts (1)

4-14: Legacy ABI imports reorganization is non-functional and consistent

The added/relocated legacy ABI imports (_ArgentWalletContractAbi, _Erc20Abi, etc.) line up with the existing exports below, so this is just an import-structure cleanup with no behavioral impact.

eslint.config.js (2)

18-19: Expanded ESLint ignores for build artifacts look good

Ignoring .nx/, **/.next/, build/, and dist/ alongside static-files/ is a sensible way to keep ESLint focused on source rather than generated output.


144-149: Turning off import/order in favor of Prettier is consistent with the new setup

Documenting that import/order is now handled via prettier.config.js and disabling the ESLint rule avoids double-enforcement and conflicting fixes. Just make sure the Prettier config (with the sort-imports plugin) runs in both lint-staged and CI for all JS/TS files so import ordering stays enforced.

apps/cowswap-frontend/src/modules/tradeQuote/services/fetchAndProcessQuote.test.ts (1)

1-1: Keep sort-imports-ignore on its own line for plugin compatibility

The @trivago/prettier-plugin-sort-imports plugin requires the comment to be exactly // sort-imports-ignore to recognize the directive. Trailing text prevents the plugin from recognizing it. Update to:

// sort-imports-ignore
// disabled for tests
tools/scripts/install-sdk-preview.js (1)

16-45: run() wrapper and token guard look correct

Moving logic into run(), short‑circuiting when hasSdkPrVersion is false, and failing fast if PACKAGE_READ_AUTH_TOKEN is missing all look sound for this script’s usage; .npmrc is now only written when needed. No changes requested.

package.json (1)

273-327: Prettier plugin + lint‑staged versioning

Adding @trivago/prettier-plugin-sort-imports and bumping lint-staged aligns with the new Prettier + lint‑staged setup; nothing looks off in this file. Please just confirm these versions match the Node/Prettier versions you run in CI and locally.

lint-staged.config.js (1)

2-14: lint‑staged pipeline looks correct (Prettier then ESLint on JS/TS only)

The glob, quoting, and conditional ESLint invocation all look good; this will format all targeted files with Prettier and only lint JS/TS when present, with concurrency enabled. Please just double‑check that your installed ESLint version supports --concurrency auto in all environments (CI and local).

Comment on lines +12 to +51
importOrder: [
// react / jotai first
'^(react|jotai)(/.*)?$',

// scope packages like @cowprotocol, @uniswap, @safe-global, etc.
'^@(cowprotocol|uniswap|safe-global|ethersproject|web3-react)(/.*)?$',

// third parties (analogous to group: external)
'<THIRD_PARTY_MODULES>',

// legacy/**
'^legacy/.*$',

// built-in Node modules (analogous to group: builtin)
'<BUILTIN_MODULES>',

// modules/**
'^modules/.*$',

// internal project folders: api, abis, common, constants, etc.
'^(api|abis|common|constants|lib|pages|types|utils)/.*$',

// sibling imports (without index)
'^\\./(?!index$).+$',

// parent imports
'^\\.\\.(/.*)?$',

// index imports
'^\\.(/)?(index)?$',

// type imports
'<THIRD_PARTY_TS_TYPES>',
'<TS_TYPES>^[./]',
],
importOrderSeparation: true,
importOrderSortSpecifiers: false,
importOrderCaseInsensitive: true,
importOrderSideEffects: false,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

find . -name "package.json" -type f | head -5

Repository: cowprotocol/cowswap

Length of output: 182


🏁 Script executed:

cat package.json | grep -A 5 -B 5 "prettier-plugin-sort-imports\|prettier"

Repository: cowprotocol/cowswap

Length of output: 182


🌐 Web query:

@trivago/prettier-plugin-sort-imports supported tokens documentation

💡 Result:

The plugin supports these special tokens (used inside importOrder):

  • <THIRD_PARTY_MODULES> — place third‑party imports. [1]
  • <BUILTIN_MODULES> — place Node.js builtin (and node:‑prefixed) modules. [1]
  • — explicit group separator when importOrderSeparation is enabled. [1]

(importOrder otherwise accepts an array of regex strings for grouping/sorting). See the plugin README for details. [1][2]

Sources:
[1] trivago/prettier-plugin-sort-imports README (GitHub).
[2] @trivago/prettier-plugin-sort-imports package page (npm).


🌐 Web query:

@trivago/prettier-plugin-sort-imports THIRD_PARTY_TS_TYPES TS_TYPES tokens

💡 Result:

Short answer: @trivago/prettier-plugin-sort-imports does not define tokens named <THIRD_PARTY_TS_TYPES> or <TS_TYPES>. The plugin supports special tokens such as <THIRD_PARTY_MODULES> and <BUILTIN_MODULES> (and other plugins may support a token to group type-only imports). See the plugin README for <THIRD_PARTY_MODULES>/<BUILTIN_MODULES> and an alternative plugin that documents a token. [1][2]

Sources:
[1] @trivago/prettier-plugin-sort-imports README — special words <THIRD_PARTY_MODULES> and <BUILTIN_MODULES>.
[2] IanVS/prettier-plugin-sort-imports README — documents a grouping token used by that plugin.


Type‑import placeholders in importOrder are ineffective with the current plugin

@trivago/prettier-plugin-sort-imports documents only three special importOrder tokens: <THIRD_PARTY_MODULES>, <BUILTIN_MODULES>, and <SEPARATOR>. The entries <THIRD_PARTY_TS_TYPES> and <TS_TYPES>^[./] are not recognized tokens, so they will be treated as literal regex patterns and never match anything, leaving no dedicated type-import grouping despite the comment.

If type-import grouping is desired, consider either removing these entries or migrating to the IanVS prettier-plugin-sort-imports package, which supports a <TYPES> token for that purpose.

🤖 Prompt for AI Agents
In prettier.config.js around lines 12 to 51, the entries
'<THIRD_PARTY_TS_TYPES>' and '<TS_TYPES>^[./]' in the importOrder are not
recognized by @trivago/prettier-plugin-sort-imports and thus act as literal
regexes; remove these two invalid tokens or replace them by migrating to a
plugin that supports a types token (e.g., switch to IanVS's
prettier-plugin-sort-imports and use its '<TYPES>' token), and ensure
importOrder only contains valid special tokens like '<THIRD_PARTY_MODULES>',
'<BUILTIN_MODULES>' or '<SEPARATOR>' so type-import grouping behaves as
intended.

@elena-zh elena-zh requested a review from a team December 3, 2025 10:49
Copy link
Contributor

@kernelwhisperer kernelwhisperer left a comment

Choose a reason for hiding this comment

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

As discussed in #6594 (comment) please rebase your changes on the new develop branch

@crutch12
Copy link
Contributor Author

Closed in favor of #6716

@crutch12 crutch12 closed this Dec 17, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants