# unified-diff

> unified plugin to ignore unrelated messages

Latest version **5.0.0** (published 2023-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install unified-diff
pnpm add unified-diff
yarn add unified-diff
bun add unified-diff
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2023-08-24 |
| First published | 2016-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 16.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Titus Wormer |
| Maintainers | wooorm |
| Keywords | diff, difference, plugin, pr, rehype, remark, retext, travis, unified, unified-plugin |

## Links

- npm: https://www.npmjs.com/package/unified-diff
- Repository: https://github.com/unifiedjs/unified-diff
- Homepage: https://github.com/unifiedjs/unified-diff#readme
- Issues: https://github.com/unifiedjs/unified-diff/issues
- Funding: https://opencollective.com/unified
- npm.io page: https://npm.io/package/unified-diff

## Dependencies (4)

- [vfile](https://npm.io/package/vfile.md) ^6.0.0
- [devlop](https://npm.io/package/devlop.md) ^1.0.0
- [git-diff-tree](https://npm.io/package/git-diff-tree.md) ^1.0.0
- [vfile-find-up](https://npm.io/package/vfile-find-up.md) ^7.0.0

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 5.0.0 (latest) — 2023-08-24
- 4.0.1 — 2021-10-20
- 4.0.0 — 2021-10-20
- 3.1.0 — 2020-12-26
- 3.0.1 — 2020-03-25
- 3.0.0 — 2019-06-26
- 2.0.0 — 2018-05-05
- 1.0.2 — 2017-07-17
- 1.0.1 — 2016-09-13
- 1.0.0 — 2016-09-07

## README

# unified-diff

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

**[unified][]** plugin to ignore unrelated messages in GitHub Actions and
Travis.

## Contents

*   [What is this?](#what-is-this)
*   [When should I use this?](#when-should-i-use-this)
*   [Install](#install)
*   [Use](#use)
*   [API](#api)
    *   [`unified().use(unifiedDiff)`](#unifieduseunifieddiff)
*   [Types](#types)
*   [Compatibility](#compatibility)
*   [Contribute](#contribute)
*   [License](#license)

## What is this?

This package is a [unified][] plugin to ignore unrelated lint messages in a CI.

**unified** is a project that transforms content with abstract syntax trees
(ASTs).
**vfile** is the virtual file interface used in unified which manages messages.
This is a unified plugin that filters messages on the vfile.

## When should I use this?

You can use this plugin when you are dealing with a large, existing project.

Using tools that check whether things follow a style guide is typically very
useful.
However, it can be hard to start using something in a large existing project.
This plugin helps, because it ignores messages that occur in lines that are not
touched by a PR in a CI.
When this plugin is used outside of a supported CIs, it doesn’t do anything.

## Install

This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

```sh
npm install unified-diff
```

In Deno with [`esm.sh`][esmsh]:

```js
import unifiedDiff from 'https://esm.sh/unified-diff@5'
```

In browsers with [`esm.sh`][esmsh]:

```html
<script type="module">
  import unifiedDiff from 'https://esm.sh/unified-diff@5?bundle'
</script>
```

## Use

Say our document `example.md` contains:

```markdown
This is an an example.
```

> 👉 **Note**: `an an` is a typo.

…and our module `example.js` looks as follows:

```js
import process from 'node:process'
import remarkParse from 'remark-parse'
import remarkRetext from 'remark-retext'
import remarkStringify from 'remark-stringify'
import retextEnglish from 'retext-english'
import retextIndefiniteArticle from 'retext-indefinite-article'
import retextRepeatedWords from 'retext-repeated-words'
import {read} from 'to-vfile'
import {unified} from 'unified'
import unifiedDiff from 'unified-diff'
import {reporter} from 'vfile-reporter'

const file = await unified()
  .use(remarkParse)
  .use(
    remarkRetext,
    unified()
      .use(retextEnglish)
      .use(retextRepeatedWords)
      .use(retextIndefiniteArticle)
  )
  .use(remarkStringify)
  .use(unifiedDiff)
  .process(await read('example.md'))

console.error(reporter(file))
process.exitCode = file.messages.length > 0 ? 1 : 0
```

…and our Travis configuration `.travis.yml` contains:

```yml
# …
script:
- npm test
- node example.js
# …
```

> 👉 **Note**: an equivalent GH Actions workflow file is also supported.

Then, say someone creates a PR which adds the following diff:

```diff
diff --git a/example.md b/example.md
index 360b225..5a96b86 100644
--- a/example.md
+++ b/example.md
@@ -1 +1,3 @@
 This is an an example.
+
+Some more more text. A error.
```

> 👉 **Note**: `more more` and `A` before `error` are typos.

When run in CI, we’ll see the following printed on **stderr**(4).

```txt
example.md
   3:6-3:15  warning  Expected `more` once, not twice   retext-repeated-words      retext-repeated-words
  3:22-3:23  warning  Use `An` before `error`, not `A`  retext-indefinite-article  retext-indefinite-article

⚠ 2 warnings
```

> 👉 **Note**: `an an` on L1 is not included because it’s unrelated to this PR.

The build exits with `1` as there are messages, thus failing CI.
The user sees this and amends the PR to the following:

```diff
diff --git a/example.md b/example.md
index 360b225..5a96b86 100644
--- a/example.md
+++ b/example.md
@@ -1 +1,3 @@
 This is an an example.
+
+Some more text. An error.
```

This time our lint task exits successfully, even though L1 would normally emit
an error, but it’s unrelated to the PR.

## API

This package exports no identifiers.
The default export is [`unifiedDiff`][api-unified-diff].

### `unified().use(unifiedDiff)`

Ignore unrelated messages in GitHub Actions and Travis.

There are no options.
If there’s a `TRAVIS_COMMIT_RANGE`, `GITHUB_BASE_REF` and `GITHUB_HEAD_REF`, or
`GITHUB_SHA` environment variable, then this plugin runs, otherwise it does
nothing.

###### To do

*   [ ] Add support for other CIs (ping if you want to work on this)
*   [ ] Add non-CI support (I’m not sure how though)

PRs welcome!

###### Returns

Transform ([`Transformer`][transformer]).

## Types

This package is fully typed with [TypeScript][].
It exports no additional types.

## Compatibility

Projects maintained by the unified collective are compatible with maintained
versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `unified-diff@^5`,
compatible with Node.js 16.

## Contribute

See [`contributing.md`][contributing] in [`unifiedjs/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.

This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

## License

[MIT][license] © [Titus Wormer][author]

<!-- Definitions -->

[build-badge]: https://github.com/unifiedjs/unified-diff/workflows/main/badge.svg

[build]: https://github.com/unifiedjs/unified-diff/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/unifiedjs/unified-diff.svg

[coverage]: https://codecov.io/github/unifiedjs/unified-diff

[downloads-badge]: https://img.shields.io/npm/dm/unified-diff.svg

[downloads]: https://www.npmjs.com/package/unified-diff

[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[backers-badge]: https://opencollective.com/unified/backers/badge.svg

[collective]: https://opencollective.com/unified

[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

[chat]: https://github.com/unifiedjs/unified/discussions

[npm]: https://docs.npmjs.com/cli/install

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[esmsh]: https://esm.sh

[typescript]: https://www.typescriptlang.org

[health]: https://github.com/unifiedjs/.github

[contributing]: https://github.com/unifiedjs/.github/blob/main/contributing.md

[support]: https://github.com/unifiedjs/.github/blob/main/support.md

[coc]: https://github.com/unifiedjs/.github/blob/main/code-of-conduct.md

[license]: license

[author]: https://wooorm.com

[unified]: https://github.com/unifiedjs/unified

[transformer]: https://github.com/unifiedjs/unified?tab=readme-ov-file#transformer

[api-unified-diff]: #unifieduseunifieddiff

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