textlint-rule-ginger
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -25,6 +25,6 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
var ignoreNodeManager = new _textlintRuleHelper.IgnoreNodeManager(); | ||
var gingerbreadAsync = (0, _es6Promisify2.default)(_gingerbread2.default, { multiArgs: true }); | ||
const ignoreNodeManager = new _textlintRuleHelper.IgnoreNodeManager(); | ||
const gingerbreadAsync = (0, _es6Promisify2.default)(_gingerbread2.default, { multiArgs: true }); | ||
@@ -38,8 +38,6 @@ /** | ||
*/ | ||
function filterNode(_ref) { | ||
var node = _ref.node; | ||
var context = _ref.context; | ||
var Syntax = context.Syntax; | ||
function filterNode({ node, context }) { | ||
const Syntax = context.Syntax; | ||
var helper = new _textlintRuleHelper.RuleHelper(context); | ||
const helper = new _textlintRuleHelper.RuleHelper(context); | ||
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) { | ||
@@ -52,64 +50,63 @@ return null; | ||
var source = new _textlintUtilToString2.default(node); | ||
var text = source.toString(); | ||
const source = new _textlintUtilToString2.default(node); | ||
const text = source.toString(); | ||
return { source: source, text: text }; | ||
return { source, text }; | ||
} | ||
function reporter(context) { | ||
var Syntax = context.Syntax; | ||
var report = context.report; | ||
var RuleError = context.RuleError; | ||
var fixer = context.fixer; | ||
const Syntax = context.Syntax, | ||
report = context.report, | ||
RuleError = context.RuleError, | ||
fixer = context.fixer; | ||
return _defineProperty({}, Syntax.Paragraph, function (node) { | ||
return function () { | ||
var _ref2, source, text, _ref3, _ref4, original, gingered, corrections; | ||
return { | ||
[Syntax.Paragraph](node) { | ||
return _asyncToGenerator(function* () { | ||
var _ref2 = filterNode({ node, context }) || {}; | ||
return Promise.resolve().then(function () { | ||
_ref2 = filterNode({ node: node, context: context }) || {}; | ||
source = _ref2.source; | ||
text = _ref2.text; | ||
const source = _ref2.source, | ||
text = _ref2.text; | ||
if (!(!source || !text)) { | ||
return Promise.resolve().then(function () { | ||
return gingerbreadAsync(text); | ||
}).then(function (_resp) { | ||
_ref3 = _resp; | ||
if (!source || !text) { | ||
return; | ||
} | ||
var _ref3 = yield gingerbreadAsync(text), | ||
_ref4 = _slicedToArray(_ref3, 3); | ||
original = _ref4[0]; | ||
gingered = _ref4[1]; | ||
corrections = _ref4[2]; | ||
// when no errors. | ||
const original = _ref4[0], | ||
gingered = _ref4[1], | ||
corrections = _ref4[2]; | ||
if (!(original === gingered)) { | ||
// when no errors. | ||
corrections.forEach(function (correction) { | ||
var index = correction.start; | ||
var originalPosition = source.originalPositionFromIndex(index); | ||
var originalRange = [originalPosition.column, originalPosition.column + correction.length]; | ||
if (original === gingered) { | ||
return; | ||
} | ||
// if range is ignored, not report | ||
if (ignoreNodeManager.isIgnoredRange(originalRange)) { | ||
return; | ||
} | ||
corrections.forEach(function (correction) { | ||
const index = correction.start; | ||
const originalPosition = source.originalPositionFromIndex(index); | ||
const originalRange = [originalPosition.column, originalPosition.column + correction.length]; | ||
var fix = fixer.replaceTextRange(originalRange, correction.correct); | ||
var message = correction.text + ' -> ' + correction.correct; | ||
// if range is ignored, skip reporting | ||
if (ignoreNodeManager.isIgnoredRange(originalRange)) { | ||
return; | ||
} | ||
report(node, new RuleError(message, { | ||
line: originalPosition.line - 1, | ||
column: originalPosition.column, | ||
fix: fix | ||
})); | ||
}); | ||
} | ||
}); | ||
} | ||
}).then(function () {}); | ||
}(); | ||
}); | ||
const fix = fixer.replaceTextRange(originalRange, correction.correct); | ||
const message = `${correction.text} -> ${correction.correct}`; | ||
report(node, new RuleError(message, { | ||
line: originalPosition.line - 1, | ||
column: originalPosition.column, | ||
fix | ||
})); | ||
}); | ||
})(); | ||
} | ||
}; | ||
} | ||
@@ -116,0 +113,0 @@ |
{ | ||
"name": "textlint-rule-ginger", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "textlint rule to check your English grammar with Ginger Proofreading", | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"main": "lib/ginger.js", | ||
@@ -29,6 +32,6 @@ "scripts": { | ||
"dependencies": { | ||
"es6-promisify": "^4.1.0", | ||
"es6-promisify": "^5.0.0", | ||
"gingerbread": "^0.5.0", | ||
"textlint-rule-helper": "^2.0.0", | ||
"textlint-util-to-string": "^1.2.1" | ||
"textlint-util-to-string": "^2.0.2" | ||
}, | ||
@@ -38,15 +41,11 @@ "devDependencies": { | ||
"babel-core": "^6.9.1", | ||
"babel-eslint": "^6.0.4", | ||
"babel-plugin-async-to-promises": "^1.0.5", | ||
"babel-plugin-espower": "^2.2.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"eslint": "^2.12.0", | ||
"eslint-config-airbnb": "^9.0.1", | ||
"eslint-plugin-import": "^1.8.1", | ||
"mocha": "^2.5.3", | ||
"npm-run-all": "^2.1.2", | ||
"power-assert": "^1.4.1", | ||
"textlint": "^6.11.1", | ||
"textlint-tester": "^1.2.0" | ||
"babel-preset-env": "^1.1.8", | ||
"eslint": "^3.14.1", | ||
"eslint-config-airbnb-base": "^11.0.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"mocha": "^3.2.0", | ||
"npm-run-all": "^4.0.1", | ||
"textlint": "^7.2.1", | ||
"textlint-tester": "^2.1.0" | ||
} | ||
} |
@@ -5,2 +5,3 @@ import { RuleHelper, IgnoreNodeManager } from 'textlint-rule-helper'; | ||
import StringSource from 'textlint-util-to-string'; | ||
const ignoreNodeManager = new IgnoreNodeManager(); | ||
@@ -73,3 +74,3 @@ const gingerbreadAsync = promisify(gingerbread, { multiArgs: true }); | ||
// if range is ignored, not report | ||
// if range is ignored, skip reporting | ||
if (ignoreNodeManager.isIgnoredRange(originalRange)) { | ||
@@ -76,0 +77,0 @@ return; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
14177
10
5
1
38
165
+ Addedes6-promise@4.2.8(transitive)
+ Addedes6-promisify@5.0.0(transitive)
+ Addedtextlint-util-to-string@2.1.1(transitive)
- Removedes6-promise@3.3.1(transitive)
- Removedes6-promisify@4.1.0(transitive)
- Removedtextlint-util-to-string@1.2.1(transitive)
Updatedes6-promisify@^5.0.0