textlint-rule-ja-space-between-half-and-full-width
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -5,11 +5,8 @@ // LICENSE : MIT | ||
var _textlintRuleHelper = require("textlint-rule-helper"); | ||
var _matchIndex = require("match-index"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
var assert = require("assert"); | ||
@@ -20,3 +17,2 @@ /* | ||
var PunctuationRegExp = /[。、]/; | ||
@@ -33,6 +29,4 @@ var ZenRegExpStr = '[、。]|[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[ぁ-んァ-ヶ]'; | ||
}; | ||
function reporter(context) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
@@ -47,3 +41,2 @@ * 入力された `space` オプションを内部処理用に成形する | ||
assert(opt === "always" || opt === "never", "\"space\" options should be \"always\", \"never\" or an array."); | ||
if (opt === "always") { | ||
@@ -76,6 +69,4 @@ if (exceptPunctuation === false) { | ||
} | ||
return defaultSpaceOptions; | ||
}; | ||
var { | ||
@@ -97,3 +88,2 @@ Syntax, | ||
*/ | ||
var createFilter = (text, padding) => { | ||
@@ -107,20 +97,15 @@ /** | ||
var targetChar = text[match.index + padding]; | ||
if (!targetChar) { | ||
return false; | ||
} | ||
if (!spaceOption.punctuation && PunctuationRegExp.test(targetChar)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
}; // Never: アルファベットと全角の間はスペースを入れない | ||
}; | ||
// Never: アルファベットと全角の間はスペースを入れない | ||
var noSpaceBetween = (node, text) => { | ||
var betweenHanAndZen = (0, _matchIndex.matchCaptureGroupAll)(text, new RegExp("[A-Za-z0-9]([ \u3000])(?:".concat(ZenRegExpStr, ")"))); | ||
var betweenZenAndHan = (0, _matchIndex.matchCaptureGroupAll)(text, new RegExp("(?:".concat(ZenRegExpStr, ")([ \u3000])[A-Za-z0-9]"))); | ||
var reportMatch = match => { | ||
@@ -135,8 +120,7 @@ var { | ||
}; | ||
betweenHanAndZen.filter(createFilter(text, 1)).forEach(reportMatch); | ||
betweenZenAndHan.filter(createFilter(text, -1)).forEach(reportMatch); | ||
}; // Always: アルファベットと全角の間はスペースを入れる | ||
}; | ||
// Always: アルファベットと全角の間はスペースを入れる | ||
var needSpaceBetween = (node, text, options) => { | ||
@@ -154,3 +138,2 @@ /** | ||
var expStr; | ||
if (btwHanAndZen) { | ||
@@ -161,6 +144,4 @@ expStr = "([".concat(alphabets).concat(numbers, "])(?:").concat(ZenRegExpStr, ")"); | ||
} | ||
return new RegExp(expStr); | ||
}; | ||
var betweenHanAndZenRegExp = generateRegExp(options); | ||
@@ -171,3 +152,2 @@ var betweenZenAndHanRegExp = generateRegExp(options, false); | ||
var betweenZenAndHan = (0, _matchIndex.matchCaptureGroupAll)(text, betweenZenAndHanRegExp); | ||
var reportMatch = match => { | ||
@@ -182,7 +162,5 @@ var { | ||
}; | ||
betweenHanAndZen.filter(createFilter(text, 1)).forEach(reportMatch); | ||
betweenZenAndHan.filter(createFilter(text, 0)).forEach(reportMatch); | ||
}; | ||
return { | ||
@@ -193,7 +171,4 @@ [Syntax.Str](node) { | ||
} | ||
var text = getSource(node); | ||
var noSpace = key => key === 'punctuation' ? true : !spaceOption[key]; | ||
if (Object.keys(spaceOption).every(noSpace)) { | ||
@@ -205,6 +180,4 @@ noSpaceBetween(node, text); | ||
} | ||
}; | ||
} | ||
module.exports = { | ||
@@ -211,0 +184,0 @@ linter: reporter, |
{ | ||
"name": "textlint-rule-ja-space-between-half-and-full-width", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "半角文字と全角文字のスペースについてのtextlintルール", | ||
@@ -32,9 +32,9 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"textlint-scripts": "^12.0.1" | ||
"textlint-scripts": "^13.3.3" | ||
}, | ||
"dependencies": { | ||
"match-index": "^1.0.1", | ||
"textlint-rule-helper": "^2.2.0" | ||
"textlint-rule-helper": "^2.2.4" | ||
}, | ||
"gitHead": "cb4c4f8364fe66861acde88a5216329dfa5562f2" | ||
"gitHead": "fdcee300489a613f44215d6a096d240c2336c46a" | ||
} |
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
33334
320
Updatedtextlint-rule-helper@^2.2.4