Skip to content

Commit

Permalink
Add support for passing phrases not to work about in ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 27, 2017
1 parent 0fbd859 commit 3915072
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use strict';

var difference = require('lodash.difference');
var search = require('nlcst-search');
var toString = require('nlcst-to-string');
var position = require('unist-util-position');
var findBefore = require('unist-util-find-before');
var list = require('./list');
var patterns = require('./list');

module.exports = passive;

var verbs = ['am', 'are', 'were', 'being', 'is', 'been', 'was', 'be'];

function passive() {
function passive(options) {
var ignore = (options || {}).ignore || [];
var list = difference(patterns, ignore);

return transformer;

/* Search `tree` for violations. */
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"index.js"
],
"dependencies": {
"lodash.difference": "^4.5.0",
"nlcst-search": "^1.0.0",
"nlcst-to-string": "^2.0.0",
"unist-util-find-before": "^2.0.0",
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ example.txt

## API

### `retext().use(passive)`
### `retext().use(passive[, options])`

Check for passive voice. No options.

###### `options.ignore`

`Array.<string>` — phrases _not_ to warn about.

## Related

* [`retext-equality`](https://github.com/wooorm/retext-equality)
Expand Down
36 changes: 25 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,35 @@ var passive = require('./');
test('passive', function (t) {
t.plan(2);

var doc = [
'He was withheld while we were being fed.',
'Fed.',
'The fed.'
].join('\n');

retext()
.use(passive)
.process([
'He was withheld while we were being fed.',
'Fed.',
'The fed.'
].join('\n'), function (err, file) {
t.ifError(err, 'should not fail');

.process(doc, function (err, file) {
t.deepEqual(
file.messages.map(String),
[err, file.messages.map(String)],
[
'1:8-1:16: Don’t use the passive voice',
'1:37-1:40: Don’t use the passive voice'
]
null,
[
'1:8-1:16: Don’t use the passive voice',
'1:37-1:40: Don’t use the passive voice'
]
],
'should work'
);
});

retext()
.use(passive, {ignore: ['fed']})
.process(doc, function (err, file) {
t.deepEqual(
[err, file.messages.map(String)],
[null, ['1:8-1:16: Don’t use the passive voice']],
'should `ignore`'
);
});
});

0 comments on commit 3915072

Please sign in to comment.