diff --git a/README.md b/README.md index f1fc265..d21088b 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,11 @@ textlint --rule no-mix-dearu-desumasu README.md "rules": { "no-mix-dearu-desumasu": { "preferInHeader": "", // "である" or "ですます" - "preferInBody": "", // "である" or "ですます" - "preferInList": "" // "である" or "ですます" - } + "preferInBody": "ですます",// "である" or "ですます" + "preferInList": "である", // "である" or "ですます" + // 文末以外でも、敬体(ですます調)と常体(である調)を厳しくチェックするかどうか + "strict": false + } } } ``` @@ -61,7 +63,7 @@ textlint --rule no-mix-dearu-desumasu README.md - 本文はですます - 箇条書きはである -というルールでチェックします。 +かつ `strict`モードでチェックします。 ```js { @@ -69,12 +71,32 @@ textlint --rule no-mix-dearu-desumasu README.md "no-mix-dearu-desumasu": { "preferInHeader": "", // "である" or "ですます" "preferInBody": "ですます",// "である" or "ですます" - "preferInList": "である" // "である" or "ですます" + "preferInList": "である", // "である" or "ですます" + // 文末以外でも、敬体(ですます調)と常体(である調)を厳しくチェックするかどうか + "strict": true } } } ``` +- `strict` + - default: `false` + - 文末以外でも、敬体(ですます調)と常体(である調)を厳しくチェックするかどうか + +例えば、`strict:false`(デフォルト)では以下のような"である場合に"という接続的な"である"は無視されます。 +そのため、次のような "であったが" は無視されています。 + +> OK: 昨日はいい天気であったが、今日は雨です。 + +`strict:false`では次のような文末が"である"や"です"といったものだけを検出します。 +そのため、次の文章は"ですが"と"である"が混在しているのでエラーとなります。 + +> NG: 今日はいい天気である。明日も晴れです。 + +`strict:true`としていた場合では、以下の文章は"ですが"と"である"が混在しているのでエラーとなります。 + +> NG: 今日はいい天気ですが、明日は悪天候である。 + ## Example 詳しくは[example/](example/)を動かして試してみてください。 @@ -100,10 +122,9 @@ Total: ## FAQ -- Q. 箇条書きの際に「である」調が混在することもあるのでは? - - 例外) 「です・ます」調の文中の「箇条書き」の部分に「である」調を使う場合 - - http://www.p-press.jp/correct/mailmagazine/mailmagazine24.html -- A. 本文、見出し、箇条書き それぞれは別々にカウントします。 +### Q. 箇条書きの際に「である」調が混在することもあるのでは? + +A. 本文、見出し、箇条書き をそれぞれ別々にカウントします。 箇条書き(`- リスト`)同士の間で混在している場合はエラーとなりますが、 **本文**と**箇条書き**での混在は問題ありません。 @@ -114,6 +135,53 @@ Total: それぞれ、別々に扱っているため、これらの間での混在は問題ありません。 +### Q. なぜデフォルトでは文末のみの検出なのですか? + +A. 自然言語に絶対の表現がないためデフォルトを緩くするためです。 + +textlintでは多くのルールはfalse positiveにならないように、デフォルトを緩く設定しています。 +厳しく(接続的な"である"なども)検出したい場合は、{ "strict": true } オプションが利用できます。 + +### Q. 2.0(以前)と同じ挙動にするにはどうすればよいですか? + +A. オプションに`"strict": true`を追加してください。 + +2.0 + +```js +{ + "rules": { + "no-mix-dearu-desumasu": { + "preferInHeader": "", // "である" or "ですます" + "preferInBody": "ですます",// "である" or "ですます" + "preferInList": "である" // "である" or "ですます" + } + } +} +``` + +3.0 + +```js +{ + "rules": { + "no-mix-dearu-desumasu": { + "preferInHeader": "", // "である" or "ですます" + "preferInBody": "ですます",// "である" or "ですます" + "preferInList": "である", // "である" or "ですます" + // 文末以外でも、敬体(ですます調)と常体(である調)を厳しくチェックするかどうか + "strict": true + } + } +} +``` + +関連Issue + +- [接続的な "である" を無視するオプション · Issue #5 · azu/analyze-desumasu-dearu](https://github.com/azu/analyze-desumasu-dearu/issues/5) +- [Proposal: デフォルトでは文末の"です/である"のみ検出するように · Issue #13 · azu/textlint-rule-no-mix-dearu-desumasu](https://github.com/azu/textlint-rule-no-mix-dearu-desumasu/issues/13) + + ## Further Reading - [JTF日本語標準スタイルガイド](https://www.jtf.jp/jp/style_guide/styleguide_top.html "JTF日本語標準スタイルガイド") diff --git a/package.json b/package.json index 231a9a6..0cd474f 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "textlint-tester": "^1.2.0" }, "dependencies": { - "analyze-desumasu-dearu": "^3.0.4", + "analyze-desumasu-dearu": "^3.1.0", "textlint-rule-helper": "^1.1.3" } } diff --git a/src/MixedChecker.js b/src/MixedChecker.js index 24ce5bf..4b52bec 100644 --- a/src/MixedChecker.js +++ b/src/MixedChecker.js @@ -10,7 +10,7 @@ export default class MixedChecker { this.context = context; /** * 明示的な優先するタイプの指定 - * @type {{preferDearu: boolean, preferDesumasu: boolean}} + * @type {{preferDearu: boolean, preferDesumasu: boolean, isStrict: boolean}} */ this.options = options; this.dearuCount = 0; @@ -22,7 +22,10 @@ export default class MixedChecker { check(node, text) { this._queue = this._queue.then(() => { - return analyze(text).then(results => { + const analyzeOptions = { + ignoreConjunction: !this.options.isStrict + }; + return analyze(text, analyzeOptions).then(results => { const retDearu = results.filter(isDearu); const retDesumasu = results.filter(isDesumasu); const dearuCount = this.dearuCount + retDearu.length; diff --git a/src/no-mix-dearu-desumasu.js b/src/no-mix-dearu-desumasu.js index 35a3171..d3a6f3e 100644 --- a/src/no-mix-dearu-desumasu.js +++ b/src/no-mix-dearu-desumasu.js @@ -4,32 +4,37 @@ import {RuleHelper} from "textlint-rule-helper"; import BodyMixedChecker from "./BodyMixedChecker"; import HeaderMixedChecker from "./HeaderMixedChecker"; import ListMixedChecker from "./ListMixedChecker"; -// Default: false -// デフォルトでその項目で多く出現している方を優先します。 -// 明示的にpreferの設定した場合は、そちらを優先した内容をエラーとして表示します。 export const PreferTypes = { DESUMASU: "ですます", DEARU: "である" }; +// デフォルトでその項目で多く出現している方を優先します。 +// 明示的にpreferの設定した場合は、そちらを優先した内容をエラーとして表示します。 const defaultOptions = { - preferInHeader: "", // "である" or "ですます" - preferInBody: "", // "である" or "ですます" - preferInList: "" // "である" or "ですます" + "preferInHeader": "", // "である" or "ですます" + "preferInBody": "", // "である" or "ですます" + "preferInList": "", // "である" or "ですます" + // 文末以外でも、敬体(ですます調)と常体(である調)を厳しくチェックするかどうか + "strict": false }; module.exports = function noMixedDearuDesumasu(context, options = defaultOptions) { const {Syntax, getSource} = context; const helper = new RuleHelper(context); + const isStrict = options.strict !== undefined ? options.strict : defaultOptions.strict; const bodyChecker = new BodyMixedChecker(context, { preferDesumasu: options.preferInBody === PreferTypes.DESUMASU, - preferDearu: options.preferInBody === PreferTypes.DEARU + preferDearu: options.preferInBody === PreferTypes.DEARU, + isStrict }); const headerChecker = new HeaderMixedChecker(context, { preferDesumasu: options.preferInHeader === PreferTypes.DESUMASU, - preferDearu: options.preferInHeader === PreferTypes.DEARU + preferDearu: options.preferInHeader === PreferTypes.DEARU, + isStrict }); const listChecker = new ListMixedChecker(context, { preferDesumasu: options.preferInList === PreferTypes.DESUMASU, - preferDearu: options.preferInList === PreferTypes.DEARU + preferDearu: options.preferInList === PreferTypes.DEARU, + isStrict }); return { // 見出し diff --git a/test/no-mix-dearu-desumasu-test.js b/test/no-mix-dearu-desumasu-test.js index 5aa846d..4143f51 100644 --- a/test/no-mix-dearu-desumasu-test.js +++ b/test/no-mix-dearu-desumasu-test.js @@ -11,6 +11,13 @@ tester.run("no-mix-dearu-desumasu", rule, { preferInBody: "である" } }, + { + // ですがはstrict:false(=デフォルト)では無視される + text: "昨日はいい天気ですが、今日は悪天候である。", + options: { + preferInBody: "である" + } + }, `今日はいい天気ですね。 そうですね。`, @@ -31,7 +38,15 @@ tester.run("no-mix-dearu-desumasu", rule, { # 今日はいい天気ですね 今日はいい天気である。 -` +`, + { + // であるがは"接続"的なものなので無視される + text: `AはBである +CはDです。`, + options: { + strict: false + } + } ], @@ -109,7 +124,7 @@ Total: } ] }, -// 箇条書き間での混在 + // 箇条書き間での混在 { text: ` - 今日はいい天気ですね @@ -174,6 +189,70 @@ Total: column: 8 } ] + }, + // strict + { + text: "昨日はいい天気であったが、今日は雨です。", + options: { + strict: true + }, + errors: [[ + { + message: `本文: "である"調 と "ですます"調 が混在 +=> "である。" がである調 +Total: +である : 1 +ですます: 1 +`, + line: 1, + column: 18 + } + ] + ] + }, + { + // vvvv + text: `今日はいい天気であるが、明日はどうなるか分からない。 +しかし、今日はいい天気ですね。だが明日はどうなるかわからないのである。`, + options: { + preferInBody: "である", + strict: true + }, + errors: [ + { + message: `本文: "である"調 と "ですます"調 が混在 +=> "ですね。" がですます調 +Total: +である : 2 +ですます: 1 +`, + line: 2, + column: 12 + } + ] + }, + { + // "AはBである"は"接続"的なものなので無視 + text: `AはBである +CはDです。 +一方、AとCは同じものである。 +`, + options: { + preferInBody: "です", + strict: false + }, + errors: [ + { + message: `本文: "である"調 と "ですます"調 が混在 +=> "である。" がである調 +Total: +である : 1 +ですます: 1 +`, + line: 3, + column: 12 + } + ] } ] }); \ No newline at end of file