-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
retext-passive.js | ||
retext-passive.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,52 @@ | ||
'use strict'; | ||
'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 patterns = require('./list'); | ||
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 patterns = require('./list') | ||
|
||
module.exports = passive; | ||
module.exports = passive | ||
|
||
var verbs = ['am', 'are', 'were', 'being', 'is', 'been', 'was', 'be']; | ||
var verbs = ['am', 'are', 'were', 'being', 'is', 'been', 'was', 'be'] | ||
|
||
function passive(options) { | ||
var ignore = (options || {}).ignore || []; | ||
var list = difference(patterns, ignore); | ||
var ignore = (options || {}).ignore || [] | ||
var list = difference(patterns, ignore) | ||
|
||
return transformer; | ||
return transformer | ||
|
||
/* Search `tree` for violations. */ | ||
function transformer(tree, file) { | ||
search(tree, list, searcher); | ||
search(tree, list, searcher) | ||
|
||
function searcher(match, index, parent, phrase) { | ||
var before = findBefore(parent, index, 'WordNode'); | ||
var message; | ||
var before = findBefore(parent, index, 'WordNode') | ||
var message | ||
|
||
if (!before) { | ||
return; | ||
return | ||
} | ||
|
||
before = toString(before).toLowerCase(); | ||
before = toString(before).toLowerCase() | ||
|
||
if (verbs.indexOf(before) === -1) { | ||
return; | ||
return | ||
} | ||
|
||
message = file.warn('Don’t use the passive voice', { | ||
start: position.start(match[0]), | ||
end: position.end(match[match.length - 1]) | ||
}, phrase.replace(/\s+/g, '-').toLowerCase()); | ||
|
||
message.source = 'retext-passive'; | ||
message.actual = toString(match); | ||
message.expected = null; | ||
message = file.warn( | ||
'Don’t use the passive voice', | ||
{ | ||
start: position.start(match[0]), | ||
end: position.end(match[match.length - 1]) | ||
}, | ||
phrase.replace(/\s+/g, '-').toLowerCase() | ||
) | ||
|
||
message.source = 'retext-passive' | ||
message.actual = toString(match) | ||
message.expected = null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters