Skip to content

Commit

Permalink
Breaking Change: デフォルトでは文末の"です/である"のみ検出するように (#14)
Browse files Browse the repository at this point in the history
`strict`オプションを導入し、デフォルトを`{ "strict": false }`としています。
そのため、デフォルトでは文末の表記のみを対象にチェックするように変更されています。

textlintでは多くのルールはfalse positiveにならないように、デフォルトを緩く設定しています。
厳しく(接続的な"である"なども)検出したい場合は、`{ "strict": true }` オプションが利用できます。

例えば、`strict:false`(デフォルト)では以下のような"である場合に"という接続的な"である"は無視されます。
そのため、次のような "であったが" は無視されています。

> OK: 昨日はいい天気であったが、今日は雨です。

`strict:false`では次のような文末が"である"や"です"といったものだけを検出します。
そのため、次の文章は"ですが"と"である"が混在しているのでエラーとなります。

> NG: 今日はいい天気である。明日も晴れです。

`strict:true`としていた場合では、以下の文章は"ですが"と"である"が混在しているのでエラーとなります。

> NG: 今日はいい天気ですが、明日は悪天候である。

-----


Q. なぜデフォルトでは文末のみの検出なのですか?
A. 自然言語に絶対の表現がないためデフォルトを緩くするためです。

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](textlint-ja/analyze-desumasu-dearu#5)
- [Proposal: デフォルトでは文末の"です/である"のみ検出するように · Issue #13 · azu/textlint-rule-no-mix-dearu-desumasu](#13)



close #13
  • Loading branch information
azu committed May 10, 2016
1 parent d23fa65 commit 2979e21
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 23 deletions.
86 changes: 77 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
```
Expand All @@ -61,20 +63,40 @@ textlint --rule no-mix-dearu-desumasu README.md
- 本文はですます
- 箇条書きはである

というルールでチェックします
かつ `strict`モードでチェックします

```js
{
"rules": {
"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/)を動かして試してみてください。
Expand All @@ -100,10 +122,9 @@ Total:

## FAQ

- Q. 箇条書きの際に「である」調が混在することもあるのでは?
- 例外) 「です・ます」調の文中の「箇条書き」の部分に「である」調を使う場合
- http://www.p-press.jp/correct/mailmagazine/mailmagazine24.html
- A. 本文、見出し、箇条書き それぞれは別々にカウントします。
### Q. 箇条書きの際に「である」調が混在することもあるのでは?

A. 本文、見出し、箇条書き をそれぞれ別々にカウントします。

箇条書き(`- リスト`)同士の間で混在している場合はエラーとなりますが、
**本文****箇条書き**での混在は問題ありません。
Expand All @@ -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日本語標準スタイルガイド")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 5 additions & 2 deletions src/MixedChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
23 changes: 14 additions & 9 deletions src/no-mix-dearu-desumasu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// 見出し
Expand Down
83 changes: 81 additions & 2 deletions test/no-mix-dearu-desumasu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ tester.run("no-mix-dearu-desumasu", rule, {
preferInBody: "である"
}
},
{
// ですがはstrict:false(=デフォルト)では無視される
text: "昨日はいい天気ですが、今日は悪天候である。",
options: {
preferInBody: "である"
}
},
`今日はいい天気ですね。
そうですね。`,
Expand All @@ -31,7 +38,15 @@ tester.run("no-mix-dearu-desumasu", rule, {
# 今日はいい天気ですね
今日はいい天気である。
`
`,
{
// であるがは"接続"的なものなので無視される
text: `AはBである
CはDです。`,
options: {
strict: false
}
}


],
Expand Down Expand Up @@ -109,7 +124,7 @@ Total:
}
]
},
// 箇条書き間での混在
// 箇条書き間での混在
{
text: `
- 今日はいい天気ですね
Expand Down Expand Up @@ -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
}
]
}
]
});

0 comments on commit 2979e21

Please sign in to comment.