textlint-filter-rule-whitelist
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -8,2 +8,4 @@ // LICENSE : MIT | ||
var escapeStringRegexp = require('escape-string-regexp'); | ||
var toRegExp = require("str-to-regexp").toRegExp; | ||
var COMPLEX_REGEX_END = /^.+\/(\w*)$/; | ||
var defaultOptions = { | ||
@@ -15,2 +17,3 @@ // white list | ||
// "/\\d+/" | ||
// "/^===/m" | ||
allow: [] | ||
@@ -29,5 +32,4 @@ }; | ||
} | ||
if (allowWord[0] === "/" && allowWord[allowWord.length - 1] === "/") { | ||
var regExpString = allowWord.slice(1, allowWord.length - 1); | ||
return new RegExp(regExpString, "g"); | ||
if (allowWord[0] === "/" && COMPLEX_REGEX_END.test(allowWord)) { | ||
return toRegExp(allowWord); | ||
} | ||
@@ -34,0 +36,0 @@ var escapeString = escapeStringRegexp(allowWord); |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"main": "lib/textlint-filter-rule-whitelist.js", | ||
@@ -50,4 +50,5 @@ "directories": { | ||
"escape-string-regexp": "^1.0.5", | ||
"execall": "^1.0.0" | ||
"execall": "^1.0.0", | ||
"str-to-regexp": "^1.1.3" | ||
} | ||
} |
# textlint-filter-rule-whitelist | ||
textlint filter rule that filter any word by white list. | ||
textlint [filter rule](https://github.com/textlint/textlint/blob/master/docs/filter-rule.md "Filter rule") that filter any word by white list. | ||
@@ -21,3 +21,4 @@ ## Install | ||
"ignored-word", | ||
"/\\d+/" | ||
"/\\d+/", | ||
"/^===/m" | ||
] | ||
@@ -37,3 +38,3 @@ } | ||
textlint-filter-rule-whitelist allow to use RegExp like string. | ||
The string is stated with `/` and ended with `/`. | ||
The string is stated with `/` and ended with `/` or `/flag`. | ||
@@ -44,2 +45,6 @@ ```js | ||
**Note**: | ||
Multiline pattern should be use `m` flag like `/regexp/m`. | ||
## Changelog | ||
@@ -46,0 +51,0 @@ |
@@ -5,2 +5,4 @@ // LICENSE : MIT | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
const toRegExp = require("str-to-regexp").toRegExp; | ||
const COMPLEX_REGEX_END = /^.+\/(\w*)$/; | ||
const defaultOptions = { | ||
@@ -12,6 +14,7 @@ // white list | ||
// "/\\d+/" | ||
// "/^===/m" | ||
allow: [] | ||
}; | ||
module.exports = function(context, options) { | ||
const {Syntax, shouldIgnore, getSource} = context; | ||
const { Syntax, shouldIgnore, getSource } = context; | ||
const allowWords = options.allow || defaultOptions.allow; | ||
@@ -22,5 +25,4 @@ const regExpWhiteList = allowWords.map(allowWord => { | ||
} | ||
if (allowWord[0] === "/" && allowWord[allowWord.length - 1] === "/") { | ||
const regExpString = allowWord.slice(1, allowWord.length - 1); | ||
return new RegExp(regExpString, "g"); | ||
if (allowWord[0] === "/" && COMPLEX_REGEX_END.test(allowWord)) { | ||
return toRegExp(allowWord); | ||
} | ||
@@ -31,3 +33,3 @@ const escapeString = escapeStringRegexp(allowWord); | ||
return { | ||
[Syntax.Document](node){ | ||
[Syntax.Document](node) { | ||
const text = getSource(node); | ||
@@ -34,0 +36,0 @@ regExpWhiteList.forEach(whiteRegExp => { |
Sorry, the diff of this file is not supported yet
13775
124
77
3
+ Addedstr-to-regexp@^1.1.3