Logo : Fix Knip Unused Exports

Fix Knip Unused Exports

Organisation
Factory-AI
fix-knip-unused-exports

Fix knip "Unused exports" violations. Handles all violation categories: test-only exports (extract to new file), dead barrel re-exports (remove from index.ts), and internally-only-used exports (un-export). Use when `npm run knip` reports unused exports.

Présentation

ÉditeurFactory-AI
Dépôtfactory-plugins
Nom de la compétencefix-knip-unused-exports
Étoiles
111
Forks
15
Fichiers inclus
Instructions uniquement
Liens
  • Instructions en Markdown

    Un fichier SKILL.md que le modèle charge à la demande : il ne consomme donc des tokens que lorsqu’une demande correspond réellement à la compétence.

  • Compatible avec tous les LLM

    Les compétences IA sont rédigées en Markdown et non sous forme de code propre à un fournisseur. Elles fonctionnent donc avec GPT, Claude, Gemini, Grok ou un modèle local.

  • Tout dans les instructions

    Tout ce dont le modèle a besoin se trouve dans les instructions : aucun fichier supplémentaire à synchroniser.

  • Open source

    Publiée par Factory-AI sur GitHub. Consultez les sources avant de l’installer.

Installation

Installez la compétence IA Fix Knip Unused Exports dans TypingMind pour l’utiliser avec n’importe quel LLM, ou ajoutez-la à un autre agent capable de lire SKILL.md.

1

Installer dans TypingMind

TypingMind installe une compétence directement depuis son dossier GitHub : l’application lit SKILL.md, regroupe les fichiers de ressources et enregistre le tout localement.

  1. Ouvrez l’application et accédez à Plugins → Compétences.
  2. Choisissez « Installer depuis GitHub ».
  3. Copiez l’URL ci-dessous, qui pointe vers le dossier de la compétence, puis collez-la et confirmez.
    https://github.com/Factory-AI/factory-plugins/tree/master/plugins/typescript/skills/fix-knip-unused-exports
  4. Activez la compétence dans chaque discussion où vous souhaitez pouvoir l’utiliser.
Plugins → Compétences → Ajouter une compétence → Via une URL GitHub, puis collez l’URL du dossier et appuyez sur Continuer.
2

Installer dans un autre agent

Tout agent capable de lire le format Agent Skills peut utiliser cette compétence : copiez le dossier dans le répertoire des compétences de cet agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Factory-AI/factory-plugins.git /tmp/factory-plugins
mkdir -p .claude/skills
cp -r /tmp/factory-plugins/plugins/typescript/skills/fix-knip-unused-exports .claude/skills/fix-knip-unused-exports
Redémarrez Claude Code après la copie pour que la nouvelle compétence soit prise en compte.

Utilisez cette compétence dans TypingMind

Activez Fix Knip Unused Exports dans n’importe quelle discussion TypingMind et le modèle s’occupe du reste. Le nom et la description de la compétence figurent dans le prompt système. Dès qu’une demande correspond, le modèle charge lui-même l’intégralité des instructions : vous n’avez jamais à l’invoquer manuellement, et elle ne consomme aucun token tant qu’elle n’est pas utilisée.

Le modèle charge automatiquement Fix Knip Unused Exports dès qu’une demande correspond à cette compétence.

Compatible avec tous les modèles IA

Les compétences IA sont de simples instructions Markdown, et non du code propre à un fournisseur. Ainsi, la compétence Fix Knip Unused Exports n’est pas liée au modèle pour lequel elle a été conçue. Installez-la une seule fois dans TypingMind et utilisez-la avec GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ou un modèle local que vous exécutez vous-même, le tout avec vos propres clés API.

  • Chargée uniquement en cas de besoin

    Le prompt système ne contient que le nom et la description. Les instructions sont récupérées à la première demande correspondante : une compétence inutilisée ne coûte donc rien.

  • Changez de modèle en cours de discussion

    La compétence étant constituée d’instructions et non de code, elle reste fonctionnelle lorsque vous changez de modèle : le nouveau modèle lit le même fichier SKILL.md.

Instructions de la compétence

Voici le contenu de SKILL.md que le modèle charge. Lisez-le avant l’installation : une compétence contient des instructions que votre modèle suivra.

Fix Knip Unused Exports

Fix knip "Unused exports" violations. There are several categories of violation, each with a different fix strategy.

When to Use

  • npm run knip reports "Unused exports"

When NOT to Use

  • The export is consumed by non-test production code in another file -- something else is wrong

Workflow

1. Identify Violations

bash
npm run knip

Output looks like:

Unused exports (3)
::error file=packages/foo/src/bar.ts,line=42,title=Unused exports::myFunction

2. Classify Each Violation

For each flagged export, grep the entire repository (not just the package):

bash
rg "myFunction"

Determine which category it falls into:

CategoryCallersFix
Test-only exportUsed in same file + test files onlyExtract to new file
Dead barrel re-exportRe-exported from index.ts, but production code imports via relative paths or other subpaths insteadRemove the re-export from the barrel
Internally-only-used exportUsed only within the same file, not by tests or other filesRemove the export keyword
Dead codeNo callers anywhereDelete the export
Production consumer existsUsed by non-test code in another fileNot a knip issue -- investigate further

Important: When grepping, exclude test files to identify production consumers:

bash
rg "myFunction" --glob '!**/*.test.*'

Fix: Test-Only Exports (Extract to New File)

When a function is exported solely for test access but is also used internally in the same file.

Plan the Extraction

Before writing code, answer these questions:

a) What moves to the new file?

  • The flagged export function/class/const
  • All private helper functions it depends on
  • All private constants/types it depends on

b) Are any helpers shared with functions staying behind?

  • If yes, the helper must be exported from the new file, and the original file imports it
  • This means the new file will have 2+ exports (which is fine for any filename-match-export lint rule)

c) Will the new file have exactly one exported function?

  • If your project enforces a filename-match-export lint rule, the file MUST be named after that export: myFunction.ts
  • If the file has 2+ function exports, the name is flexible

d) Does a test file with a matching name exist?

  • If bar.ts stays and bar.test.ts exists, the test must still import something from ./bar (if your project enforces a test-imports-source rule)
  • If bar.ts is deleted (everything moved out), that rule typically only applies when the matching source file exists

e) Any circular dependency risk?

  • Draw the import graph: new file -> original file -> new file is circular
  • Fix: move the shared dependency to the new file or a third file

f) Does it export a constant?

  • If your project enforces a constants-file-organization lint rule, exported constants must live in a file named constants.ts
  • If the extracted function depends on a constant that other functions in the original file also use, do NOT export the constant from the new file. Instead, call the function (e.g., replace BUDGET[effort] with getBudget(effort)) to avoid needing a separate constants.ts

Execute the Extraction

Create the new file in the same directory:

typescript
// myFunction.ts (new file)
import { SomeType } from '../types';

function privateHelper(): void { /* ... */ }

export function myFunction(): SomeType {
  return privateHelper();
}

Update the original file to import from the new file:

typescript
// bar.ts (original file, updated)
import { myFunction } from './myFunction';

function otherFunction() {
  const result = myFunction(); // Now imports from new file
}

Update test files to import from the new file:

typescript
// bar.test.ts (updated)
import { myFunction } from './myFunction';
// If bar.ts still exists, you may need to also import something from './bar'
// to satisfy any test-imports-source rule

Watch for Chained Violations

After extracting, run npm run knip again. If function A was extracted to a new file alongside function B that A calls, but B is also only consumed by tests externally, knip will flag B too. You need to extract B to its own file so that A's file creates a genuine production import of B.

Example: suppose throwMappedError was first extracted alongside mapResponseFailure into error-mappers.ts. If throwMappedError is only called internally within that file (by mapResponseFailure), it will still be flagged. Fix: extract it to throwMappedError.ts, making the import from error-mappers.ts a genuine production consumer.

Fix: Dead Barrel Re-Exports (Remove from index.ts)

When a barrel index.ts re-exports something, but no production code imports it through the barrel. This happens when:

  • Production code within the same package uses relative imports (e.g., import { x } from './source') instead of the barrel
  • Production code in other packages imports directly from a subpath (e.g., @scope/pkg/feature/handlers) instead of the barrel
  • The re-export was added speculatively but never consumed

How to Identify

Grep excluding test files. If the only hits are:

  • The barrel index.ts itself
  • Source files using relative imports within the same package
  • Test files

Then the barrel re-export is unused. Simply remove it from index.ts.

Cross-Package Test Imports

If a test in another package imports the symbol through the barrel (e.g., import { x } from '@scope/pkg/feature'), you need to provide an alternative import path after removing the barrel re-export:

  1. Add a subpath export in the source package's package.json:

    json
    {
      "exports": {
        "./feature": "./src/feature/index.ts",
        "./feature/doSomething": "./src/feature/doSomething.ts"
      }
    }
  2. Update the test to import from the new subpath:

    typescript
    import { doSomething } from '@scope/pkg/feature/doSomething';

This pattern follows typical subpath-export conventions used in monorepos.

Fix: Internally-Only-Used Exports (Un-export)

When an export is only used within the same file and not imported by anything else (not even tests), just remove the export keyword:

typescript
// Before
export const MySchema = z.object({ ... });

// After
const MySchema = z.object({ ... });

This is common for Zod schemas that are only used as building blocks for other schemas in the same file.

Verify

Run ALL of these checks on the affected packages:

bash
# Knip passes (the whole point)
npm run knip

# Types still compile
npm run typecheck

# Tests still pass
npm run test

# Lint passes (catches filename-match-export, test-imports-source, constants-file-organization, etc.)
npm run lint

If cross-package imports exist, also verify the consuming package.

Interacting Lint Rules

Many TypeScript monorepos layer additional custom lint rules on top of knip. Adapt the fixes below to whichever of these your project uses.

filename-match-export (or similar)

If a file has exactly ONE exported function (not a React component), the filename must match the function name.

  • export function loadConfig in loadConfig.ts -- passes
  • export function loadConfig in helpers.ts -- fails
  • Two exports in helpers.ts -- rule does not apply (multiple exports)

test-imports-source (or similar)

If foo.test.ts and foo.ts both exist, the test must import from ./foo.

  • Imports like import { x } from './foo' satisfy the rule
  • Typically also accepts importing from '.' or './index' if index.ts re-exports from foo.ts
  • If foo.ts is deleted, the rule does not apply

constants-file-organization (or similar)

Exported constants must be defined in a file named constants.ts.

  • If you extract a function that depends on a shared constant, do NOT export the constant from the function's file
  • Instead, replace direct constant access with function calls (e.g., BUDGET[effort] becomes getBudget(effort))
  • Or move the constant to a constants.ts file

How Knip Traces Exports

  • Knip ignores test files (**/*.test.*, **/*.spec.*)
  • ignoreIssues in knip.json suppresses warnings ON the listed file, but does NOT make the source export "used"
  • Barrel re-exports (export { x } from './source') from an index.ts with ignoreIssues do NOT count as usage of the source export
  • Only genuine imports from non-test, non-ignored project files count as usage
  • includeEntryExports: true (if set) means exports from entry point files are checked too, so entry-point-style files (migrations, scripts) may need explicit ignoreIssues

Package Subpath Exports

When removing barrel re-exports that cross-package tests relied on, add subpath exports to package.json:

json
{
  "exports": {
    "./feature": "./src/feature/index.ts",
    "./feature/doSomething": "./src/feature/doSomething.ts"
  }
}

What Not to Do

  • Do not add files to ignoreIssues in knip.json unless they are genuine entry point scripts (migrations, CLIs)
  • Do not merge all functions into one file to reduce exports -- same-file usage of an export does not count as usage from knip's perspective
  • Do not remove the export keyword if tests need it -- the tests would break
  • Do not create circular imports between the new and original files
  • Do not export constants from non-constants.ts files if your project enforces a constants-file-organization lint rule

Foire aux questions

À quoi sert la compétence IA Fix Knip Unused Exports ?

Fix knip "Unused exports" violations. Handles all violation categories: test-only exports (extract to new file), dead barrel re-exports (remove from index.ts), and internally-only-used exports (un-export). Use when `npm run knip` reports unused exports.

Pourquoi utiliser Fix Knip Unused Exports sur TypingMind ?

Parce que vous l’installez une seule fois pour l’utiliser avec n’importe quel modèle. Fix Knip Unused Exports se compose de simples instructions en Markdown plutôt que de code propre à un fournisseur. La même compétence fonctionne donc avec GPT-5, Claude, Gemini, Grok ou un modèle local, et vous pouvez changer de modèle en cours de discussion sans perturber son fonctionnement. TypingMind utilise vos propres clés API : vous payez donc directement les fournisseurs plutôt qu’un abonnement par siège, et vos compétences et discussions restent dans votre propre espace de stockage.

Comment installer Fix Knip Unused Exports dans TypingMind ?

Dans TypingMind, ouvrez Plugins → Compétences → Installer depuis GitHub et collez https://github.com/Factory-AI/factory-plugins/tree/master/plugins/typescript/skills/fix-knip-unused-exports. TypingMind lit le fichier SKILL.md et l’installe sous forme de compétence que vous pouvez activer pour chaque discussion.

Quels modèles d’IA peuvent utiliser Fix Knip Unused Exports ?

N’importe quel modèle que vous connectez dans TypingMind. Les compétences IA sont de simples instructions en Markdown, et non du code propre à un fournisseur. GPT, Claude, Gemini, Grok et les modèles locaux peuvent donc tous charger cette compétence lorsqu’une demande lui correspond.

Combien de modèles d’IA puis-je utiliser avec Fix Knip Unused Exports ?

Autant que vous le souhaitez. Vous pouvez utiliser Fix Knip Unused Exports avec tout modèle qui prend en charge les compétences : GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama et bien d’autres, le tout dans TypingMind avec vos propres clés API.

La compétence IA Fix Knip Unused Exports est-elle gratuite ?

Cette compétence est publiée sur GitHub par Factory-AI. Consultez le dépôt pour connaître les conditions de licence. Vous ne payez que votre propre fournisseur d’IA pour les tokens utilisés.

Que sont les compétences IA ?

Une compétence IA est un ensemble d’instructions réutilisables qui apprend à un modèle d’IA à accomplir une tâche précise. Elle suit le format ouvert Agent Skills : un fichier SKILL.md contenant un nom et une description, ainsi que les éventuels scripts, gabarits ou fichiers de référence dont le modèle peut avoir besoin. Le modèle ne lit les instructions que lorsque votre demande correspond à la compétence. Une compétence installée ne coûte donc rien tant qu’elle n’est pas utilisée.

En quoi les compétences IA diffèrent-elles des plugins ou des serveurs MCP ?

Un plugin ou un serveur MCP fournit au modèle de nouveaux outils à appeler : du code qui s’exécute quelque part et renvoie un résultat. Une compétence IA lui apporte plutôt des connaissances et une méthode : comment aborder une tâche, quelles étapes suivre et à quoi ressemble un bon résultat. Les compétences sont de simples instructions en Markdown. Elles ne nécessitent donc ni serveur, ni clé API, ni environnement d’exécution, et fonctionnent avec n’importe quel modèle.

Tout voir

Créez votre propre espace de travail IA dès maintenant

Abonnez-vous à notre newsletter pour être informé des nouvelles fonctionnalités et des prochains cadeaux à gagner 👇