Giter Club home page Giter Club logo

unified-diff's Introduction

unified-diff Build Status Coverage Status

Unified plugin to ignore unrelated messages. Currently works in PRs on Travis.

When working with natural language, having tools that check cumbersome tasks can be very useful (think alex or retext plugins). However, natural language isn’t as strict as code. Integrating natural language checking in a CI often doesn’t work well due to false positives. It’s possible to add a long list of exceptions, but this soon becomes unmanageable.

This plugin solves that problem, when in Travis, by ignoring any messages on unchanged lines. When run outside Travis, this plugin doesn’t do anything.

TODO
  • Add support for other CIs (ping if you want to work on this);
  • Add non-CI support (I’m not yet sure how though).

Installation

npm:

npm install unified-diff

Usage

Say we have this readme.md. Note the an an.

This is an an example.

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

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

We have some natural language checking in lint.js:

var diff = require('unified-diff')
var vfile = require('to-vfile')
var unified = require('unified')
var markdown = require('remark-parse')
var stringify = require('remark-stringify')
var remark2retext = require('remark-retext')
var english = require('retext-english')
var repetition = require('retext-repeated-words')
var article = require('retext-indefinite-article')
var report = require('vfile-reporter')

vfile.read('readme.md', function(err, file) {
  if (err) throw err

  unified()
    .use(markdown)
    .use(
      remark2retext,
      unified()
        .use(english)
        .use(repetition)
        .use(article)
    )
    .use(stringify)
    .use(diff)
    .process(file, function(err) {
      console.error(report(err || file))
      process.exit(err || file.messages.length ? 1 : 0)
    })
})

lint.js is hooked up to run on Travis in .travis.yml like so:

# ...
script:
- npm test
- node lint.js
# ...

When run in Travis, we’ll see the following printed on stderr(4). Note that an an on L1 is not included because it’s unrelated to this PR.

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

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

diff --git a/readme.md b/readme.md
index 360b225..5a96b86 100644
--- a/readme.md
+++ b/readme.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

processor.use(diff)

Ignore messages emitted by plugins before diff for lines that did not change.

There are no options. If there’s a TRAVIS_COMMIT_RANGE environment variable this plugin runs, otherwise it’s a noop.

Contribute

See contributing.md in unifiedjs/unified for ways to get started.

This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

unified-diff's People

Contributors

wooorm avatar greenkeeperio-bot avatar

Watchers

James Cloos avatar Ben Junya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.