textlint-rule-helper
Advanced tools
Comparing version 1.1.5 to 1.2.0
@@ -7,2 +7,3 @@ // LICENSE : MIT | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -12,7 +13,7 @@ value: true | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var RuleHelper = (function () { | ||
var RuleHelper = function () { | ||
/** | ||
@@ -37,2 +38,3 @@ * Initialize RuleHelper with RuleContext object. | ||
_createClass(RuleHelper, [{ | ||
@@ -56,2 +58,3 @@ key: "getParents", | ||
*/ | ||
}, { | ||
@@ -73,5 +76,5 @@ key: "isChildNode", | ||
return RuleHelper; | ||
})(); | ||
}(); | ||
exports.RuleHelper = RuleHelper; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy90ZXh0bGludC1ydWxlLWhlbHBlci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0EsWUFBWSxDQUFDOzs7Ozs7Ozs7Ozs7O0lBS0EsVUFBVTs7Ozs7O0FBS1IsYUFMRixVQUF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XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBSZXR1cm4gdHJ1ZSBpZiBgbm9kZWAgaXMgd3JhcHBlZCBhbnkgb25lIG9mIG5vZGUge0BsaW5rIHR5cGVzfS5cbiAgICAgKiBAcGFyYW0ge1R4dE5vZGV9IG5vZGUgaXMgdGFyZ2V0IG5vZGVcbiAgICAgKiBAcGFyYW0ge3N0cmluZ1tdfSB0eXBlcyBhcmUgd3JhcHBlZCB0YXJnZXQgbm9kZVxuICAgICAqIEByZXR1cm5zIHtib29sZWFufVxuICAgICAqL1xuICAgIGlzQ2hpbGROb2RlKG5vZGUsIHR5cGVzKSB7XG4gICAgICAgIHZhciBwYXJlbnRzID0gdGhpcy5nZXRQYXJlbnRzKG5vZGUpO1xuICAgICAgICB2YXIgcGFyZW50c1R5cGVzID0gcGFyZW50cy5tYXAoZnVuY3Rpb24gKHBhcmVudCkge1xuICAgICAgICAgICAgcmV0dXJuIHBhcmVudC50eXBlO1xuICAgICAgICB9KTtcbiAgICAgICAgcmV0dXJuIHR5cGVzLnNvbWUoZnVuY3Rpb24gKHR5cGUpIHtcbiAgICAgICAgICAgIHJldHVybiBwYXJlbnRzVHlwZXMuc29tZShmdW5jdGlvbiAocGFyZW50VHlwZSkge1xuICAgICAgICAgICAgICAgIHJldHVybiBwYXJlbnRUeXBlID09PSB0eXBlO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgIH1cbn0iXX0= | ||
exports.default = RuleHelper; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy90ZXh0bGludC1ydWxlLWhlbHBlci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0E7Ozs7Ozs7Ozs7Ozs7O0lBS3FCLFU7Ozs7OztBQUtqQix3QkFBWSxXQUFaLEVBQXlCO0FBQUE7O0FBQ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HR5cGVzIGFyZSB3cmFwcGVkIHRhcmdldCBub2RlXG4gICAgICogQHJldHVybnMge2Jvb2xlYW59XG4gICAgICovXG4gICAgaXNDaGlsZE5vZGUobm9kZSwgdHlwZXMpIHtcbiAgICAgICAgdmFyIHBhcmVudHMgPSB0aGlzLmdldFBhcmVudHMobm9kZSk7XG4gICAgICAgIHZhciBwYXJlbnRzVHlwZXMgPSBwYXJlbnRzLm1hcChmdW5jdGlvbiAocGFyZW50KSB7XG4gICAgICAgICAgICByZXR1cm4gcGFyZW50LnR5cGU7XG4gICAgICAgIH0pO1xuICAgICAgICByZXR1cm4gdHlwZXMuc29tZShmdW5jdGlvbiAodHlwZSkge1xuICAgICAgICAgICAgcmV0dXJuIHBhcmVudHNUeXBlcy5zb21lKGZ1bmN0aW9uIChwYXJlbnRUeXBlKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHBhcmVudFR5cGUgPT09IHR5cGU7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgfVxufSJdfQ== |
{ | ||
"name": "textlint-rule-helper", | ||
"description": "Helper for textlint rule.", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/textlint/textlint-rule-helper/", | ||
@@ -10,3 +10,3 @@ "repository": { | ||
}, | ||
"main": "lib/textlint-rule-helper.js", | ||
"main": "lib/index.js", | ||
"files": [ | ||
@@ -17,6 +17,6 @@ "lib", | ||
"scripts": { | ||
"build": "babel src --out-dir lib --source-maps inline", | ||
"build": "NODE_ENV=production babel src --out-dir lib --source-maps inline", | ||
"watch": "babel src --out-dir lib --watch --source-maps inline", | ||
"docs": "jsdoc2md -t template/README.template.md lib/textlint-rule-helper.js > README.md", | ||
"test": "npm run build && mocha test/*.js" | ||
"test": "mocha test/*.js", | ||
"prepublish": "npm run build" | ||
}, | ||
@@ -32,12 +32,15 @@ "directories": { | ||
"devDependencies": { | ||
"babel": "^5.2.17", | ||
"espower-babel": "^3.0.0", | ||
"jsdoc-to-markdown": "^1.1.1", | ||
"babel-cli": "^6.10.1", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-power-assert": "^1.0.0", | ||
"babel-register": "^6.9.0", | ||
"markdown-to-ast": "^3.0.5", | ||
"mocha": "^2.1.0", | ||
"power-assert": "^0.11.0", | ||
"source-map-support": "^0.2.8", | ||
"textlint": "^5.0.2", | ||
"power-assert": "^1.4.1", | ||
"textlint": "^6.11.1", | ||
"txt-ast-traverse": "^1.2.0" | ||
}, | ||
"dependencies": { | ||
"unist-util-visit": "^1.1.0" | ||
} | ||
} |
@@ -13,18 +13,8 @@ # textlint-rule-helper | ||
### class RuleHelper | ||
<a name="RuleHelper"></a> | ||
####class: RuleHelper | ||
**Members** | ||
Helper for traversing TxtAST. | ||
* [class: RuleHelper](#RuleHelper) | ||
* [new RuleHelper()](#new_RuleHelper) | ||
* [ruleHelper.getParents(node)](#RuleHelper#getParents) | ||
* [ruleHelper.isChildNode(node, types)](#RuleHelper#isChildNode) | ||
#### ruleHelper.getParents(node) : TxtNode[] | ||
<a name="new_RuleHelper"></a> | ||
#####new RuleHelper() | ||
RuleHelper is helper class for textlint. | ||
<a name="RuleHelper#getParents"></a> | ||
#####ruleHelper.getParents(node) | ||
Get parents of node. | ||
@@ -36,7 +26,6 @@ The parent nodes are returned in order from the closest parent to the outer ones. | ||
- node `TxtNode` - the node is start point. | ||
- node `TxtNode` - the node is start point. | ||
**Returns**: `Array.<TxtNode>` | ||
<a name="RuleHelper#isChildNode"></a> | ||
#####ruleHelper.isChildNode(node, types) | ||
####ruleHelper.isChildNode(node, types): boolean | ||
Return true if `node` is wrapped any one of node `types`. | ||
@@ -46,32 +35,39 @@ | ||
- node `TxtNode` - is target node | ||
- types `Array.<string>` - are wrapped target node | ||
- node `TxtNode` - is target node | ||
- types `Array.<string>` - are wrapped target node | ||
**Returns**: `boolean` | ||
### class IgnoreNodeManger | ||
<a name="RuleHelper#getParents"></a> | ||
####ruleHelper.getParents(node) | ||
Get parents of node. | ||
The parent nodes are returned in order from the closest parent to the outer ones. | ||
`node` is not contained in the results. | ||
You can manager ignoring range in texts. | ||
**Params** | ||
#### ignore(node): void | ||
- node `TxtNode` - the node is start point. | ||
Add the range of `node` to ignoring range list. | ||
**Returns**: `Array.<TxtNode>` | ||
#### ignoreRange(range): void | ||
<a name="RuleHelper#isChildNode"></a> | ||
####ruleHelper.isChildNode(node, types) | ||
Return true if `node` is wrapped any one of node `types`. | ||
Add the `range` to ignoring range list | ||
#### ignoreChildrenByTypes(targetNode, ignoredNodeTypes): void | ||
if the children node has the type that is included in `ignoredNodeTypes`, | ||
Add range of children node of `node` to ignoring range list, | ||
**Params** | ||
- node `TxtNode` - is target node | ||
- types `Array.<string>` - are wrapped target node | ||
- targetNode `TxtNode` - target node | ||
- `Array.<string>` - are node types for ignoring | ||
**Returns**: `boolean` | ||
#### isIgnoredIndex(index): boolean | ||
If the `index` is included in ignoring range list, return true. | ||
#### isIgnoredRange(range): boolean | ||
If the `range` is included in ignoring range list, return true. | ||
#### isIgnored(node): boolean | ||
If the `range` of `node` is included in ignoring range list, return true. | ||
## Example | ||
@@ -83,5 +79,14 @@ | ||
var RuleHelper = require("textlint-rule-helper").RuleHelper; | ||
var IgnoreNodeManger = require("textlint-rule-helper").IgnoreNodeManger; | ||
module.exports = function (context) { | ||
var helper = new RuleHelper(context); | ||
var ignoreNodeManager = new IgnoreNodeManger() | ||
var exports = {} | ||
var reportingErrors = []; | ||
exports[context.Syntax.Paragraph] = function(node){ | ||
// Add `Code` node to ignoring list | ||
ignoreNodeManager.ignoreChildrenByTypes(node, [context.Syntax.Code]) | ||
// do something | ||
reportingErrors.push(node, ruleError); | ||
}; | ||
exports[context.Syntax.Str] = function(node){ | ||
@@ -94,4 +99,12 @@ // parent nodes is any one Link or Image. | ||
var parents = helper.getParents(node); | ||
} | ||
[Syntax.Document + ":exit"](){ | ||
reportingErrors.forEach(function(node, ruleError){ | ||
// if the error is ignored, don't report | ||
if(ignoreNodeManager.isIgnored(node)){ | ||
return; | ||
} | ||
// report actual | ||
}); | ||
} | ||
return exports; | ||
@@ -98,0 +111,0 @@ } |
@@ -7,3 +7,3 @@ // LICENSE : MIT | ||
*/ | ||
export class RuleHelper { | ||
export default class RuleHelper { | ||
/** | ||
@@ -10,0 +10,0 @@ * Initialize RuleHelper with RuleContext object. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
23672
10
306
132
1
1
+ Addedunist-util-visit@^1.1.0
+ Addedunist-util-is@3.0.0(transitive)
+ Addedunist-util-visit@1.4.1(transitive)
+ Addedunist-util-visit-parents@2.1.2(transitive)