npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unified-diff

v5.0.0

Published

unified plugin to ignore unrelated messages

Downloads

77,133

Readme

unified-diff

Build Coverage Downloads Sponsors Backers Chat

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

Contents

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. In Node.js (version 16+), install with npm:

npm install unified-diff

In Deno with esm.sh:

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

In browsers with esm.sh:

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

Use

Say our document example.md contains:

This is an an example.

👉 Note: an an is a typo.

…and our module example.js looks as follows:

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:

# …
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 --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).

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 --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.

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).

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 in unifiedjs/.github for ways to get started. See support.md for ways to get help.

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

License

MIT © Titus Wormer