diff --git a/packages/textlint-rule-google-word-list/src/textlint-rule-google-word-list.js b/packages/textlint-rule-google-word-list/src/textlint-rule-google-word-list.js index 0e313d8..53ad4ed 100644 --- a/packages/textlint-rule-google-word-list/src/textlint-rule-google-word-list.js +++ b/packages/textlint-rule-google-word-list/src/textlint-rule-google-word-list.js @@ -2,7 +2,9 @@ "use strict"; import { paragraphReporter, getPosFromSingleWord } from "@textlint-rule/textlint-report-helper-for-google-preset"; -const report = context => { +const report = (context, options = {}) => { + const allowWords = Array.isArray(options.allowWords) ? options.allowWords : []; + // Politeness and use of "please" // https://developers.google.com/style/tone#politeness-and-use-of-please const dictionaries = [ @@ -269,14 +271,16 @@ const report = context => { message: "Don't use to refer to expander arrows,\nunless you're specifically referring to the Zippy\nwidget in Closure." } - ].map(preDict => { - return { - pattern: typeof preDict.word === "string" ? new RegExp("\\b" + preDict.word + "\\b") : preDict.word, - test: preDict.test ? preDict.test : undefined, - replace: preDict.replace ? preDict.replace : undefined, - message: () => preDict.message - }; - }); + ] + .map(preDict => { + return { + pattern: typeof preDict.word === "string" ? new RegExp("\\b" + preDict.word + "\\b") : preDict.word, + test: preDict.test ? preDict.test : undefined, + replace: preDict.replace ? preDict.replace : undefined, + message: () => preDict.message + }; + }) + .filter(({ pattern }) => !allowWords.some(word => pattern.test(word))); const { Syntax, RuleError, getSource, fixer, report } = context; return { diff --git a/packages/textlint-rule-google-word-list/test/textlint-rule-google-word-list-test.js b/packages/textlint-rule-google-word-list/test/textlint-rule-google-word-list-test.js index 2d252f6..17db72b 100644 --- a/packages/textlint-rule-google-word-list/test/textlint-rule-google-word-list-test.js +++ b/packages/textlint-rule-google-word-list/test/textlint-rule-google-word-list-test.js @@ -193,7 +193,12 @@ tester.run("textlint-rule-google-word-list", rule, { "with", "zip", // allow - "touch & hold is ok" + "touch & hold is ok", + // with option: allowList + { + text: "This is an application.", + options: { allowWords: ["application"] } + } ], invalid: [ { @@ -218,6 +223,24 @@ tester.run("textlint-rule-google-word-list", rule, { text: "administrator", output: "admin", errors: [{}] + }, + // with option: allowList + { + text: "This is an application.", + options: { allowWords: [] }, + output: "This is an app.", + errors: [{}] + }, + { + text: "This is an application.", + options: { + allowWords: [ + // 'application' + "app" + ] + }, + output: "This is an app.", + errors: [{}] } ] });