Skip to content

Knip: remove unused code, remove unused exports#5866

Merged
witoszekdev merged 32 commits intomainfrom
fix-knip-unused-exports
Sep 22, 2025
Merged

Knip: remove unused code, remove unused exports#5866
witoszekdev merged 32 commits intomainfrom
fix-knip-unused-exports

Conversation

@witoszekdev
Copy link
Member

@witoszekdev witoszekdev commented Sep 16, 2025

Continuation of #5859

This PR deletes dead-code that wasn't used anywhere and removes exports if they weren't used outside of local file.

Caution

Do not open "Files changed" tab, it will freeze your browser 🙈
Open changes using github.dev: https://github.dev/saleor/saleor-dashboard/pull/5866/files

Other changes

These changes were needed to make this cleanup possible

ESLint

Added new ESLint rules that were used during this cleanup and will be useful afterwards as well:

  • no-unused-vars - similar to our existing TypeScript config, but will ignore catch (error), and vars starting with _

  • eslint-unused-imports-plugin - to auto-delete unused imports (useful in normal development to get rid of annoying errors from TypeScript)

  • eslint-plugin-unicorn with rule unicorn/no-empty-file - to detect and remove empty files after our cleanup (due to running all rules, file content was completely removed) - we might want to use more rules from this plugin 👀

TypeScript

Removed checking unused vars and imports, since this is now done by ESLint. This might improve TypeScript performance.

Other

Added OrderGiftCardEventBalanceFragment to fix TypeScript error in src/orders/components/OrderSummaryCard/utils.ts

Steps taken

For future prosperity here were the steps taken to cleanup unused files:

  1. npm run knip:fix
  2. npm run linter
  3. npx eslint --quiet -f json | npx remove-unused-vars
  4. Repeat steps 1-3 a few times
  5. npm run check-types
  6. Fix manually some errors

Manual fixes

  • Playwright tests: they use let someVar and then initialize it in beforeEach block. If variable wasn't actually used in test, knip will delete it. But it won't delete the beforeEach initailization - this needs to be deleted manually
  • Empty files - unicorn/no-empty-file doesn't support auto-fix, do some bash magic by simply: running eslint, exporting result to json, parse it using jd, pass to rm command ಠ‿↼
  • Enums: for some reason unused enums are not deleted by remove-unused-vars - these need to be removed manually
  • Barrel files: this evil monstrosity breaks knip and/or eslint when used along with another enemy: default exports. In order to resolve issue we must remove default exports and then export {default as something} from "./some-file" line in barrel file. Ideally barrel files should be gone, but we already have 900+ files changed 😄

Copilot AI review requested due to automatic review settings September 16, 2025 14:56
@witoszekdev witoszekdev requested a review from a team as a code owner September 16, 2025 14:56
@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2025

⚠️ No Changeset found

Latest commit: f313195

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

@vercel
Copy link

vercel bot commented Sep 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
saleor-dashboard-storybook Ignored Ignored Preview Sep 18, 2025 3:37pm

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes unused exports from the codebase as identified by Knip, a tool for detecting dead code. The changes streamline the codebase by removing exports that aren't used elsewhere while keeping the functionality intact as local implementations.

Key changes include:

  • Converting exported interfaces, types, and functions to non-exported (local) versions
  • Removing entire files that only contained unused exports
  • Updating Knip configuration to be more strict about detecting unused code

Reviewed Changes

Copilot reviewed 288 out of 893 changed files in this pull request and generated 2 comments.

File Description
Multiple component files Convert exported interfaces/types to local scope when not used externally
Multiple index.ts files Remove or reduce exports that aren't consumed by other modules
.knip.json Enable stricter rules for types, files, exports, and duplicates detection
package.json Update script references to use .cjs extensions
Comments suppressed due to low confidence (1)

.knip.json:1

  • [nitpick] The Knip configuration has been changed from 'off' to 'error' for multiple rules. This is a good improvement for code quality, but ensure the CI pipeline can handle these stricter checks and consider adding documentation about the new requirements.
{

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@witoszekdev witoszekdev marked this pull request as draft September 16, 2025 14:57
@witoszekdev witoszekdev changed the base branch from main to fix-knip September 16, 2025 14:57
@witoszekdev witoszekdev added the skip changeset Use if your changes doesn't need entry in changelog label Sep 16, 2025
@github-actions github-actions bot temporarily deployed to pr-5866 September 16, 2025 15:00 Destroyed
@github-actions
Copy link
Contributor

github-actions bot commented Sep 16, 2025

Differences Found

⚠️ 10 packages or licenses were added.

Expand
License	Package
Apache-2.0	baseline-browser-mapping
BSD-2-Clause	regjsparser
MIT	builtin-modules
MIT	clean-regexp
MIT	core-js-compat
MIT	eslint-plugin-unicorn
MIT	eslint-plugin-unused-imports
MIT	find-up-simple
MIT	is-builtin-module
MIT	pluralize

Summary

Expand
License Name Package Count Packages
0BSD 1
Packages
  • tslib
CC0-1.0 1
Packages
  • type-fest
MIT/X11 1
Packages
  • nub
MPL-1.1 1
Packages
  • harmony-reflect
MPL-2.0 1
Packages
  • dompurify
Public Domain 1
Packages
  • jsonify
Python-2.0 1
Packages
  • argparse
<<missing>> 2
Packages
  • busboy
  • streamsearch
CC-BY-4.0 2
Packages
  • @saleor/macaw-ui
  • caniuse-lite
SEE LICENSE IN LICENSE 2
Packages
  • posthog-js
  • spawndamnit
WTFPL 2
Packages
  • opener
  • utf8-byte-length
BlueOak-1.0.0 3
Packages
  • jackspeak
  • package-json-from-dist
  • path-scurry
BSD-2-Clause 23
Packages
  • browser-process-hrtime
  • css-select
  • css-what
  • domelementtype
  • domhandler
  • domutils
  • dotenv
  • dotenv-expand
  • entities
  • escodegen
  • eslint-scope
  • espree
  • esprima
  • esrecurse
  • estraverse
  • esutils
  • nth-check
  • regjsparser
  • stringify-object
  • terser
  • And 3 more...
BSD-3-Clause 47
Packages
  • @saleor/app-sdk
  • @sentry/cli
  • @sentry/cli-darwin
  • @sentry/cli-linux-arm
  • @sentry/cli-linux-arm64
  • @sentry/cli-linux-i686
  • @sentry/cli-linux-x64
  • @sentry/cli-win32-arm64
  • @sentry/cli-win32-i686
  • @sentry/cli-win32-x64
  • @sinonjs/commons
  • @sinonjs/fake-timers
  • abab
  • asn1js
  • babel-plugin-istanbul
  • charenc
  • chroma-js
  • crypt
  • diff
  • esquery
  • And 27 more...
ISC 51
Packages
  • @isaacs/cliui
  • @istanbuljs/load-nyc-config
  • anymatch
  • boolbase
  • browser-stdout
  • cli-width
  • cliui
  • electron-to-chromium
  • fastq
  • flatted
  • foreground-child
  • fs.realpath
  • get-caller-file
  • get-own-enumerable-property-symbols
  • glob
  • glob-parent
  • graceful-fs
  • inflight
  • inherits
  • ini
  • And 31 more...
Apache-2.0 56
Packages
  • @ampproject/remapping
  • @editorjs/editorjs
  • @eslint/config-array
  • @eslint/config-helpers
  • @eslint/core
  • @eslint/object-schema
  • @eslint/plugin-kit
  • @humanfs/core
  • @humanfs/node
  • @humanwhocodes/module-importer
  • @humanwhocodes/retry
  • @opentelemetry/api
  • @opentelemetry/semantic-conventions
  • @playwright/test
  • @pollyjs/adapter
  • @pollyjs/core
  • @pollyjs/persister
  • @pollyjs/utils
  • @swc/core
  • @swc/core-darwin-arm64
  • And 36 more...
MIT 1278
Packages
  • @adobe/css-tools
  • @apollo/client
  • @ardatan/relay-compiler
  • @ardatan/sync-fetch
  • @babel/code-frame
  • @babel/compat-data
  • @babel/core
  • @babel/generator
  • @babel/helper-annotate-as-pure
  • @babel/helper-compilation-targets
  • @babel/helper-create-class-features-plugin
  • @babel/helper-globals
  • @babel/helper-member-expression-to-functions
  • @babel/helper-module-imports
  • @babel/helper-module-transforms
  • @babel/helper-optimise-call-expression
  • @babel/helper-plugin-utils
  • @babel/helper-replace-supers
  • @babel/helper-skip-transparent-expression-wrappers
  • @babel/helper-string-parser
  • And 1258 more...

@github-actions github-actions bot temporarily deployed to pr-5866 September 16, 2025 15:15 Destroyed
Base automatically changed from fix-knip to main September 16, 2025 15:50
Copilot AI review requested due to automatic review settings September 16, 2025 16:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 289 out of 906 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings September 16, 2025 16:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 289 out of 909 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings September 16, 2025 16:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 289 out of 916 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov
Copy link

codecov bot commented Sep 16, 2025

Codecov Report

❌ Patch coverage is 55.17241% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.64%. Comparing base (0fd3e57) to head (f313195).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rc/attributes/components/AttributeDetails/utils.ts 0.00% 2 Missing ⚠️
src/categories/views/CategoryList/filter.ts 0.00% 2 Missing ⚠️
...ialogWrapper/ChannelsAvailabilityDialogWrapper.tsx 0.00% 2 Missing ⚠️
.../apps/components/AppInstallPage/AppInstallPage.tsx 0.00% 1 Missing ⚠️
src/apps/components/AppListPage/AppListPage.tsx 0.00% 1 Missing ⚠️
.../apps/components/AppListPage/MissingAppsFooter.tsx 0.00% 1 Missing ⚠️
src/apps/components/AppPage/AppPage.tsx 0.00% 1 Missing ⚠️
...pps/components/DeactivatedText/DeactivatedText.tsx 0.00% 1 Missing ⚠️
...s/components/MarketplaceAlert/MarketplaceAlert.tsx 0.00% 1 Missing ⚠️
src/attributes/index.tsx 0.00% 1 Missing ⚠️
... and 39 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5866      +/-   ##
==========================================
+ Coverage   38.61%   38.64%   +0.02%     
==========================================
  Files        2753     2745       -8     
  Lines       43691    43254     -437     
  Branches     9863     9807      -56     
==========================================
- Hits        16873    16714     -159     
- Misses      25494    26510    +1016     
+ Partials     1324       30    -1294     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings September 16, 2025 17:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 293 out of 912 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot temporarily deployed to pr-5866 September 16, 2025 17:31 Destroyed
kzuraw
kzuraw previously approved these changes Sep 17, 2025
@witoszekdev witoszekdev changed the title Knip: remove unused exports Knip: remove unused code, remove unused exports Sep 17, 2025
@witoszekdev witoszekdev enabled auto-merge (squash) September 17, 2025 15:39
@witoszekdev witoszekdev requested a review from kzuraw September 17, 2025 15:39
@github-actions github-actions bot temporarily deployed to pr-5866 September 17, 2025 15:43 Destroyed
Copilot AI review requested due to automatic review settings September 18, 2025 15:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 299 out of 760 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/collections/components/CollectionListPage/CollectionListPage.tsx:1

  • The currencySymbol parameter is destructured but not used in the component. This should be removed from the destructuring assignment.
// @ts-strict-ignore

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot temporarily deployed to pr-5866 September 18, 2025 15:41 Destroyed
@lkostrowski lkostrowski added the run pw-e2e Run e2e (basic suite from PR automation) label Sep 22, 2025
@witoszekdev witoszekdev merged commit 543984e into main Sep 22, 2025
41 of 43 checks passed
@witoszekdev witoszekdev deleted the fix-knip-unused-exports branch September 22, 2025 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run pw-e2e Run e2e (basic suite from PR automation) skip changeset Use if your changes doesn't need entry in changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants