Skip to content

Commit

Permalink
Remove warnings for literal words
Browse files Browse the repository at this point in the history
Why:

*   Sometimes, words are meant literally and without their original
    definition. For example, `Dont use “he”.`

How:

*   Add `nlcst-is-literal` as a dependency, which checks whether
    a word is surrounded by quotes, parens, brackets, commans, colons
    and whatnot.
  • Loading branch information
wooorm committed Aug 24, 2015
1 parent e2b29fd commit 7154046
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 12 deletions.
3 changes: 2 additions & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"wooorm/nlcst-to-string": "^1.0.0",
"ljharb/object-keys": "^1.0.7",
"blakeembrey/pluralize": "^1.1.4",
"wooorm/unist-util-visit": "^1.0.0"
"wooorm/unist-util-visit": "^1.0.0",
"wooorm/nlcst-is-literal": "^1.0.0"
},
"repository": "wooorm/retext-equality",
"scripts": [
Expand Down
15 changes: 12 additions & 3 deletions lib/equality.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
var keys = require('object-keys');
var visit = require('unist-util-visit');
var nlcstToString = require('nlcst-to-string');
var isLiteral = require('nlcst-is-literal');
var patterns = require('./patterns.json');

/*
Expand Down Expand Up @@ -506,11 +507,19 @@ function factory(file) {
*/

visit(node, 'WordNode', function (child, position, parent) {
var patterns = byWord[toString(child).toLowerCase()];
var length = patterns ? patterns.length : 0;
var index = -1;
var patterns;
var length;
var index;
var result;

if (isLiteral(parent, position)) {
return;
}

patterns = byWord[toString(child).toLowerCase()];
length = patterns ? patterns.length : 0;
index = -1;

while (++index < length) {
result = test(file, byId[patterns[index]], position, parent);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"retext"
],
"dependencies": {
"nlcst-is-literal": "^1.0.0",
"nlcst-to-string": "^1.0.0",
"object-keys": "^1.0.7",
"pluralize": "^1.1.4",
Expand Down
Loading

0 comments on commit 7154046

Please sign in to comment.