Skip to content

Commit

Permalink
Add noBinary option in .alexrc files
Browse files Browse the repository at this point in the history
Closes GH-127.
  • Loading branch information
wooorm committed Sep 13, 2016
1 parent ed0e568 commit 17a0447
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var engine = require('unified-engine');
var unified = require('unified');
var markdown = require('remark-parse');
var english = require('retext-english');
var equality = require('retext-equality');
var profanities = require('retext-profanities');
var remark2retext = require('remark-retext');
var report = require('vfile-reporter');
var pack = require('./package');
Expand Down Expand Up @@ -76,15 +74,24 @@ if (cli.input.length) {
globs = cli.input;
}

var plain = unified().use(english).use(equality).use(profanities);
var processor = plain;
var processor = unified();

if (!cli.flags.text) {
processor = unified().use(markdown).use(remark2retext, plain);
if (cli.flags.text) {
processor.use(english);
} else {
processor
.use(markdown)
.use(remark2retext, english.Parser);
}

var filter = require.resolve('./filter.js');
var plugins = [filter];
var equality = require.resolve('retext-equality');

var plugins = [
equality,
require.resolve('retext-profanities'),
filter
];

/* istanbul ignore if - hard to check. */
if (cli.flags.diff) {
Expand Down Expand Up @@ -125,7 +132,13 @@ function transform(raw) {

current = current.plugins && current.plugins[filter] && current.plugins[filter].allow;

plugins[filter] = {allow: [].concat(allow, current || [])};
if (allow.length) {
plugins[filter] = {allow: [].concat(allow, current || [])};
}

if ('noBinary' in raw) {
plugins[equality] = {noBinary: raw.noBinary};
}

return {plugins: plugins};
};
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ example.md
All `allow` fields in all `package.json` and `.alexrc` files are
detected and used when processing.

Next to `allow`, `noBinary` can also be passed. Setting it to true
counts `he and she`, `garbageman or garbagewoman` and similar pairs
as errors, whereas the default (`false`), treats it as OK.

### Control

Sometimes, **alex** makes mistakes:
Expand Down
27 changes: 27 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,30 @@ test('quiet on nok files', function (t) {
);
});
});

test('binary (default)', function (t) {
var rp = path.join('fixtures', 'binary', 'two.md');
var fp = path.join(__dirname, rp);

return execa.stderr('../cli.js', [fp]).then(function (result) {
t.is(result, rp + ': no issues found');
});
});

test('non-binary (optional)', function (t) {
var rp = path.join('fixtures', 'non-binary', 'two.md');
var fp = path.join(__dirname, rp);

return execa.stderr('../cli.js', [fp]).catch(function (err) {
var expected = [
rp,
' 1:1-1:3 warning `He` may be insensitive, use `They`, `It` instead he-she retext-equality',
' 1:7-1:10 warning `she` may be insensitive, use `they`, `it` instead he-she retext-equality',
'',
'⚠ 2 warnings',
''
].join('\n');

t.is(err.stderr, expected);
});
});
1 change: 1 addition & 0 deletions test/fixtures/binary/two.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
He or she should do it.
3 changes: 3 additions & 0 deletions test/fixtures/non-binary/.alexrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"noBinary": true
}
1 change: 1 addition & 0 deletions test/fixtures/non-binary/two.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
He or she should do it.

0 comments on commit 17a0447

Please sign in to comment.