# @cozy/codemods

> Codeshifts used inside Cozies

Latest version **1.35.1** (published 2026-06-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cozy/codemods
pnpm add @cozy/codemods
yarn add @cozy/codemods
bun add @cozy/codemods
```

Provides the command `cozy-codemods`.

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.35.1 |
| Published | 2026-06-25 |
| First published | 2020-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 120.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Cozy |
| Maintainers | mycozycloud |

## Links

- npm: https://www.npmjs.com/package/@cozy/codemods
- Repository: https://github.com/cozy/cozy-libs
- npm.io page: https://npm.io/package/@cozy/codemods

## Dependencies (2)

- [jscodeshift](https://npm.io/package/jscodeshift.md) ^0.11.0
- [@cozy/cli-tree](https://npm.io/package/@cozy/cli-tree.md) ^0.15.1

## Recent versions

- 1.35.1 (latest) — 2026-06-25
- 1.9.0-beta.1 (beta) — 2020-12-01
- 1.35.0 — 2026-06-17
- 1.34.1 — 2026-03-17
- 1.34.0 — 2026-03-17
- 1.33.3 — 2026-03-16
- 1.33.2 — 2026-03-05
- 1.33.1 — 2026-01-29
- 1.33.0 — 2025-12-04
- 1.32.0 — 2025-11-06
- 1.31.3 — 2025-10-30
- 1.31.2 — 2025-09-09
- 1.31.1 — 2024-11-06
- 1.31.0 — 2024-11-06
- 1.30.0 — 2024-11-06
- … 59 more at https://npm.io/package/@cozy/codemods/versions

## README

<!-- Autogenerated, change .README.template -->

## Cozy codeshifts

A collection of utils and transforms for [jscodeshift](https://github.com/facebook/jscodeshift).

Codeshifts are automatic transformations of Javascript code. They can be used
for

- code migrations following API changes
- flag removal
- general automatic code changes...

### Documentation

See [jscodeshift-docs](https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation) for more information on codeshifts.

Here are nice examples about [import manipulation](https://www.codeshiftcommunity.com/docs/import-manipulation/) and [React & JSX manipulation](https://www.codeshiftcommunity.com/docs/react).

The [API doc](https://npmdoc.github.io/node-npmdoc-jscodeshift/build/apidoc.html) can be usefull too.

### Installation

You can install @cozy/codemods globally so that you do not have to pollute your package.json
and yarn.lock in every project where you use it.

```
yarn global add @cozy/codemods
```

### General usage

```
$ cozy-codemods --help
$ cozy-codemods list # List available transforms
$ cozy-codemods showExample apply-flag # Show an example of what a transform does
$ cozy-codemods run apply-flag -- --flag=my-flag # Run a transform, pass jscodeshift args after --
```

### Available transforms

#### Apply flag

Transforms `flag()` calls into `true` then remove dead code and dead imports

Before

```
import Old from 'old'
import New from 'new'
flag("hello") ? <Old /> : <New />
```

After

```
import New from 'new'
<New />
```

#### Remove boolean variables

Simpler version of Apply flag only for boolean variables.

Before

```
import Old from 'old'
import New from 'new'
true ? <Old /> : <New />
```

After

```
<New />
```

### Utils

- Replace a HOC with a hook with [`hoc-replacer.js`](./src/hoc-replacer.js)
- Remove unused imports with [`remove-unused-imports.js`](./src/remove-unused-imports.js)

## API

## Functions

<dl>
<dt><a href="#removeUnusedImports">removeUnusedImports(root, j)</a></dt>
<dd><p>Removes unused imports by counting usage.
JSX identifiers are counted as React usage.</p>
</dd>
<dt><a href="#isBlockLike">isBlockLike(path)</a> ⇒ <code>Boolean</code></dt>
<dd><p>Returns true if path is Program or a Block</p>
</dd>
<dt><a href="#flatReplace">flatReplace(path, newNode)</a></dt>
<dd><p>Replaces <code>path.node</code> with <code>newNode</code> without keeping blocks, flattening
<code>newNode</code> into <code>path</code>. Useful when removing <code>if</code>/<code>else</code>.</p>
</dd>
<dt><a href="#simplifyConditions">simplifyConditions(root, j)</a></dt>
<dd><p>Statically evaluates boolean conditions</p>
</dd>
</dl>

<a name="removeUnusedImports"></a>

## removeUnusedImports(root, j)

Removes unused imports by counting usage.
JSX identifiers are counted as React usage.

**Kind**: global function

| Param | Type                  |
| ----- | --------------------- |
| root  | <code>PathNode</code> |
| j     | <code>Object</code>   |

<a name="isBlockLike"></a>

## isBlockLike(path) ⇒ <code>Boolean</code>

Returns true if path is Program or a Block

**Kind**: global function

| Param | Type                  |
| ----- | --------------------- |
| path  | <code>PathNode</code> |

<a name="flatReplace"></a>

## flatReplace(path, newNode)

Replaces `path.node` with `newNode` without keeping blocks, flattening
`newNode` into `path`. Useful when removing `if`/`else`.

**Kind**: global function

| Param   | Type                  |
| ------- | --------------------- |
| path    | <code>PathNode</code> |
| newNode | <code>Node</code>     |

<a name="simplifyConditions"></a>

## simplifyConditions(root, j)

Statically evaluates boolean conditions

**Kind**: global function

| Param | Type                  |
| ----- | --------------------- |
| root  | <code>NodePath</code> |
| j     | <code>Object</code>   |

**Example**

```js
`if (true) { foo } else { bar }` -> `foo`

`true ? foo : bar` -> `foo`

`!true ? foo : bar` -> `bar`
```

---
_Source: https://npm.io/package/@cozy/codemods · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
