textlint-rule-ja-hiragana-fukushi
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -5,7 +5,7 @@ "use strict"; | ||
var fs = require('fs'); | ||
var fs = require("fs"); | ||
var kuromojin = require("kuromojin"); | ||
var createMatcher = require("morpheme-match-all"); | ||
var yaml = require('js-yaml'); | ||
var data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", 'utf8')); | ||
var yaml = require("js-yaml"); | ||
var data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", "utf8")); | ||
@@ -20,4 +20,4 @@ var dictionaries = []; | ||
dictionaries.push({ | ||
message: data.message + ": \"" + form + "\" > \"" + item.fix_form + "\"", | ||
fix: item.fix_form, | ||
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"", | ||
fix: item.expected, | ||
tokens: item.tokens | ||
@@ -42,8 +42,3 @@ }); | ||
var results = matchAll(actualTokens); | ||
/* | ||
console.log("/-----------------------"); | ||
console.log(actualTokens); | ||
console.log(results); | ||
console.log("-----------------------/"); | ||
*/ | ||
if (results.length == 0) { | ||
@@ -65,5 +60,2 @@ return; | ||
}); | ||
//console.log(node); | ||
//console.log("-----------------------"); | ||
//console.log(result); | ||
report(node, ruleError); | ||
@@ -73,3 +65,3 @@ }); | ||
}); | ||
}; | ||
} | ||
@@ -76,0 +68,0 @@ function getIndexFromTokens(tokenIndex, actualTokens) { |
{ | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"keywords": [ | ||
@@ -18,2 +18,3 @@ "textlintrule" | ||
"devDependencies": { | ||
"eslint": "^3.17.1", | ||
"textlint-scripts": "^1.2.2" | ||
@@ -20,0 +21,0 @@ }, |
"use strict"; | ||
const fs = require('fs'); | ||
const fs = require("fs"); | ||
const kuromojin = require("kuromojin"); | ||
const createMatcher = require("morpheme-match-all"); | ||
const yaml = require('js-yaml'); | ||
const data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", 'utf8')); | ||
const yaml = require("js-yaml"); | ||
const data = yaml.safeLoad(fs.readFileSync(__dirname + "/../dict/fukushi.yml", "utf8")); | ||
let dictionaries = []; | ||
const dictionaries = []; | ||
@@ -17,4 +17,4 @@ data.dict.forEach(function (item) { | ||
dictionaries.push({ | ||
message: data.message + ": \"" + form + "\" > \"" + item.fix_form + "\"", | ||
fix: item.fix_form, | ||
message: data.message + ": \"" + form + "\" => \"" + item.expected + "\"", | ||
fix: item.expected, | ||
tokens: item.tokens | ||
@@ -27,39 +27,31 @@ }); | ||
function reporter(context, options = {}) { | ||
const {Syntax, RuleError, report, getSource, fixer} = context; | ||
return { | ||
[Syntax.Str](node){ // "Str" node | ||
const text = getSource(node); // Get text | ||
return kuromojin(text).then((actualTokens) => { | ||
const results = matchAll(actualTokens); | ||
/* | ||
console.log("/-----------------------"); | ||
console.log(actualTokens); | ||
console.log(results); | ||
console.log("-----------------------/"); | ||
*/ | ||
if (results.length == 0) { | ||
return; | ||
} | ||
const {Syntax, RuleError, report, getSource, fixer} = context; | ||
return { | ||
[Syntax.Str](node){ // "Str" node | ||
const text = getSource(node); // Get text | ||
return kuromojin(text).then((actualTokens) => { | ||
const results = matchAll(actualTokens); | ||
results.forEach(function (result) { | ||
let tokenIndex = result.index; | ||
let index = getIndexFromTokens(tokenIndex, actualTokens); | ||
let replaceFrom = ""; | ||
result.tokens.forEach(function(token){ | ||
replaceFrom += token.surface_form; | ||
}); | ||
let replaceTo = fixer.replaceTextRange([index, index + replaceFrom.length], result.dict.fix); | ||
let ruleError = new RuleError(result.dict.message, { | ||
index: index, | ||
fix: replaceTo // https://github.com/textlint/textlint/blob/master/docs/rule-fixable.md | ||
}); | ||
//console.log(node); | ||
//console.log("-----------------------"); | ||
//console.log(result); | ||
report(node, ruleError); | ||
if (results.length == 0) { | ||
return; | ||
} | ||
results.forEach(function (result) { | ||
const tokenIndex = result.index; | ||
const index = getIndexFromTokens(tokenIndex, actualTokens); | ||
let replaceFrom = ""; | ||
result.tokens.forEach(function(token){ | ||
replaceFrom += token.surface_form; | ||
}); | ||
const replaceTo = fixer.replaceTextRange([index, index + replaceFrom.length], result.dict.fix); | ||
const ruleError = new RuleError(result.dict.message, { | ||
index: index, | ||
fix: replaceTo // https://github.com/textlint/textlint/blob/master/docs/rule-fixable.md | ||
}); | ||
report(node, ruleError); | ||
}); | ||
} | ||
}); | ||
} | ||
}; | ||
}; | ||
} | ||
@@ -66,0 +58,0 @@ function getIndexFromTokens(tokenIndex, actualTokens) { |
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
41825
2
121