# esfixup

> ES Code Transformer, Upgrader, Fixer

Latest version **1.0.0** (published 2022-08-19) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install esfixup
pnpm add esfixup
yarn add esfixup
bun add esfixup
```

Provides the command `esfixup`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-08-19 |
| First published | 2022-08-19 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 24 |
| Unpacked size | 376.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Groupon |
| Maintainers | groupon |

## Links

- npm: https://www.npmjs.com/package/esfixup
- Repository: https://github.com/groupon/esfixup
- Issues: https://github.com/groupon/esfixup/issues
- npm.io page: https://npm.io/package/esfixup

## Dependencies (24)

- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [debug](https://npm.io/package/debug.md) ^4.3.1
- [eslint](https://npm.io/package/eslint.md) ^7.29.0
- [globby](https://npm.io/package/globby.md) ^11.0.2
- [pkg-up](https://npm.io/package/pkg-up.md) ^3.1.0
- [semver](https://npm.io/package/semver.md) ^7.3.4
- [prettier](https://npm.io/package/prettier.md) ^2.3.1
- [commander](https://npm.io/package/commander.md) ^4.1.1
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.13.8
- [@babel/types](https://npm.io/package/@babel/types.md) ^7.6.3
- [decaffeinate](https://npm.io/package/decaffeinate.md) ^8.1.1
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.12.17
- [lodash.sortby](https://npm.io/package/lodash.sortby.md) ^4.7.0
- [@babel/template](https://npm.io/package/@babel/template.md) ^7.12.13
- [lodash.camelcase](https://npm.io/package/lodash.camelcase.md) ^4.3.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.13.9
- [is-builtin-module](https://npm.io/package/is-builtin-module.md) ^3.0.0
- [eslint-plugin-node](https://npm.io/package/eslint-plugin-node.md) ^11.1.0
- [eslint-plugin-mocha](https://npm.io/package/eslint-plugin-mocha.md) ^9.0.0
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) ^2.23.4
- [eslint-config-groupon](https://npm.io/package/eslint-config-groupon.md) ^11.0.4
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^4.0.0
- [@babel/plugin-syntax-typescript](https://npm.io/package/@babel/plugin-syntax-typescript.md) ^7.16.0
- [@babel/plugin-transform-react-jsx](https://npm.io/package/@babel/plugin-transform-react-jsx.md) ^7.12.17

## Recent versions

- 1.0.0 (latest) — 2022-08-19

## README

[![nlm-github](https://img.shields.io/badge/github-groupon%2Fesfixup%2Fissues-F4D03F?logo=github&logoColor=white)](https://github.com/groupon/esfixup/issues)
![nlm-node](https://img.shields.io/badge/node-%3E%3D14-blue?logo=node.js&logoColor=white)
![nlm-version](https://img.shields.io/badge/version-1.0.0-blue?logo=version&logoColor=white)
# `esfixup`

> CLI to transform/port/upgrade/improve your existing JavaScript (or convert
Coffee to JS)

## Usage

```bash
npx esfixup --help
npx esfixup --transforms=decaf *.coffee lib
npx esfixup --transforms=js,testium-wd modules
```

## Options

### `--no-lint-fix`

Don't run `eslint --fix` (using your lint settings) on any JS files when
complete.  (Default JS output is pretty ugly, you probably don't want this).

### `--node-version`

Explicitly specify a compatible version of JS that should be generated - by
default this is inferred from the `engines.node` section of your `package.json`

### `--transforms` or `-t`

Comma-separated list of which transforms you want to apply; order given in
option is ignored; transforms know which order they should be applied in.

Available transforms include:

#### `assert`
Converts uses of [assertive] to modern builtin NodeJS [assert].

File type: `*.js`

[assertive]: https://github.com/groupon/assertive
[assert]: https://nodejs.org/dist/latest/docs/api/assert.html

Assertive was great in its day, but mostly NodeJS `assert` has caught up, and
is much more standard.

Example:

```js
const { equal } = require('assertive');
equal('expected', 'actual');
```

```
$ npx esfixup --transforms=assert foo.js
[assert] ✏️  foo.js
```

```js
const assert = require('assert');
assert.strictEqual('actual', 'expected');
```

#### `decaf`
Decaffeinate single files or entire folders - tries to convert to idiomatic
JavaScript where possible, which means it may not always be a 100% faithful
conversion.

File type: `*.coffee`

Example:

```coffee
# foo.coffee
x = 20
y = 10
y = 30
```

```
$ npx esfixup --transforms=decaf foo.coffee
[decaf] ✏️  foo.coffee → foo.js
```

```js
// foo.js
'use strict';

const x = 20;
let y = 10;
y = 30;
```

#### `js`
Upgrades JS/ES Syntax to maximum features available for your NodeJS version

File type: `*.js`

Included features:

* `Object.assign({}, a, b)` replaced with object-spread: `{ ...a, ...b }`
* Uses of `bluebird.coroutine` and `co.wrap` replaced with async/await
* Uses object & array destructuring in function and assignments where possible
* Replaces `.indexOf(x) !== -1` with `.includes()`
* Removes unnecessary `const { URL } = require('url');`
* Removes unused `catch` clause parameter
* Replaces `[].concat.apply()` construct with `.flat()`
* Replaces `a && a.b && a.b.c` sort of stuff with optional chaining: `a?.b?.c`
* Removes `__guard__` constructs introduced by `--transforms=decaf`

#### `nodash`
Replace some uses of lodash with ES6+ code

File type: `*.js`

Notes:
- After applying, rigorously test your code
- Some transforms are very complex. If possible, try to avoid lodash usage in
  the first place.
- Transforms currently happen in place.  Refactor your code afterwards to not
  replicate code.

This will replace some uses of:

* assign
* compact
* concat
* difference
* drop
* fill
* head
* first
* initial
* intersection
* join
* keys
* last
* take
* takeRight
* toPairs
* without
* uniq
* union
* unzip
* values
* zip
* zipObject

#### `phy`
Converts boring `h()` or jsx calls to [phy] `h()` calls

[phy]: https://github.com/groupon/phy

File type: `*.jsx`, `*.js`

Example:

```jsx
// foo.jsx
const { h } = require('preact');

function SomeComp() {
  return <div class="a"><b>stuff</b></div>;
}
function OtherComp() {
  return h('div', { className: 'a' }, [h('b', {}, ['stuff'])]);
}
```

```
$ npx esfixup --transforms=phy foo.jsx
[phy] ✏️  foo.jsx → foo.js
```

```js
// foo.js
const h = require('phy');

function SomeComp() {
  return h('.a', h('b', 'stuff'));
}

function OtherComp() {
  return h('.a', [h('b', ['stuff'])]);
}
```

#### `testium-wd`
Converts testium-driver-sync tests to testium-driver-wd

File type: `*.js`

```js
const injectBrowser = require('testium/mocha');

describe('x', () => {
  before(injectBrowser({ driver: 'sync' }));
  it('y', function () {
    this.browser.navigateTo('/');
    return this.browser.waitForElementVisible('#a');
  });
  it('checks', () => {
    browser.assert.httpStatus(204);
  });
  it('z', () => {
    browser.navigateTo('/z');
    assert.equal(200, browser.getStatusCode());
    browser.assert.elementIsVisible('#a');
    assert.expect(true);
    browser.setCookie({ domain: 'd' });
  });
});
```

```
$ npx esfixup --transforms=testium-wd some.test.js
[testium-wd] ✏️  some.test.js
```

```js
const { browser } = require("testium-mocha");

describe('x', () => {
  before(browser.beforeHook({ driver: 'wd' }));
  it('y', () =>
    browser
      .loadPage('/', { expectedStatusCode: 204 })
      .waitForElementDisplayed('#a')
  );

  it('z', async () => {
    await browser
      .loadPage('/z')
      .assertElementIsDisplayed('#a');
    assert.expect(true);
    await browser.setCookie({ domain: 'd' });
  });
});
```

#### `ts`

File type: `*.js`

Transforms JavaScript with optional TS-compatible JSDoc comments into idiomatic
TypeScript.  Sadly most other transforms currently only operate on JavaScript,
so this transform will run last.

Example:

```js
// foo.js
/**
 * @param {string} a
 * @param {import('./foo').Foo} [b]
 * @return {number}
 */
function fn(a, b) {
  return a + (b ? b.toNum() : 42);
}
```

```
$ npx esfixup --transforms=ts foo.js
[ts] ✏️  foo.js → foo.ts
```

```ts
// foo.ts
import { Foo } from './foo';

function fn(a: string, b?: Foo): number {
  return a + (b ? b.toNum() : 42);
}
```

## Development

For work on this library, see [DEVELOPMENT.md](DEVELOPMENT.md)

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