Skip to content

Commit 6e01ed2

Browse files
committed
docs: Update README
1 parent 585876c commit 6e01ed2

5 files changed

+629
-35
lines changed

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ Via `.textlintrc`.
2222

2323
### Options
2424

25-
Defaults: **Not** allow to use `!?!?`.
25+
Defaults: Disallows to use `!?!?`.
2626

27-
- `allow`: ["Yahoo!"],
28-
- allow words
29-
- `allowHalfWidthExclamation`: false,
27+
- `allow`: `string[]`,
28+
- allow word list that suppor [RegExp-like String](https://github.com/textlint/textlint-filter-rule-allowlist#regexp-like-string)
29+
- `allowHalfWidthExclamation`: `boolean`
3030
- allow to use !
31-
- `allowFullWidthExclamation`: false,
31+
- Default: `false`
32+
- `allowFullWidthExclamation`: `boolean`
3233
- allow to use !
33-
- `allowHalfWidthQuestion`: false,
34+
- Default: `false`
35+
- `allowHalfWidthQuestion`: `boolean`
3436
- allow to use ?
35-
- `allowFullWidthQuestion`: false
37+
- Default: `false`
38+
- `allowFullWidthQuestion`: `boolean`
3639
- allow to use ?
40+
- Default: `false`
3741

3842
```
3943
{

package.json

+21-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,34 @@
2525
"test": "textlint-scripts test",
2626
"build": "textlint-scripts build",
2727
"watch": "textlint-scripts build --watch",
28-
"prepublish": "npm run --if-present build"
28+
"prepublish": "npm run --if-present build",
29+
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
2930
},
3031
"devDependencies": {
32+
"husky": "^4.3.0",
33+
"lint-staged": "^10.3.0",
34+
"prettier": "^2.1.1",
3135
"textlint-scripts": "^3.0.0"
3236
},
3337
"dependencies": {
3438
"@textlint/regexp-string-matcher": "^1.1.0",
3539
"match-index": "^1.0.3",
3640
"textlint-rule-helper": "^2.1.1"
41+
},
42+
"prettier": {
43+
"singleQuote": false,
44+
"printWidth": 120,
45+
"tabWidth": 4,
46+
"trailingComma": "none"
47+
},
48+
"husky": {
49+
"hooks": {
50+
"pre-commit": "lint-staged"
51+
}
52+
},
53+
"lint-staged": {
54+
"*.{js,jsx,ts,tsx,css}": [
55+
"prettier --write"
56+
]
3757
}
3858
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// LICENSE : MIT
22
"use strict";
3-
import {RuleHelper} from "textlint-rule-helper";
4-
import {matchPatterns} from "@textlint/regexp-string-matcher";
5-
import {matchCaptureGroupAll} from "match-index"
3+
import { RuleHelper } from "textlint-rule-helper";
4+
import { matchPatterns } from "@textlint/regexp-string-matcher";
5+
import { matchCaptureGroupAll } from "match-index";
66

77
/**
88
* if actual is in the `matchPatternResults`, return true
@@ -11,24 +11,23 @@ import {matchCaptureGroupAll} from "match-index"
1111
* @returns {boolean}
1212
*/
1313
const isIgnoredRange = (matchPatternResults, actual) => {
14-
return matchPatternResults.some(result => {
14+
return matchPatternResults.some((result) => {
1515
return result.startIndex <= actual.index && actual.index <= result.endIndex;
1616
});
1717
};
1818

19+
const DEFAULT_ALLOW_LIST = ["Yahoo!"];
1920
const defaultOptions = {
2021
// allow words
21-
"allow": [
22-
"Yahoo!"
23-
],
22+
allow: [],
2423
// allow to use !
25-
"allowHalfWidthExclamation": false,
24+
allowHalfWidthExclamation: false,
2625
// allow to use !
27-
"allowFullWidthExclamation": false,
26+
allowFullWidthExclamation: false,
2827
// allow to use ?
29-
"allowHalfWidthQuestion": false,
28+
allowHalfWidthQuestion: false,
3029
// allow to use ?
31-
"allowFullWidthQuestion": false
30+
allowFullWidthQuestion: false
3231
};
3332
const Mark = {
3433
HalfWidthExclamation: /(!)/,
@@ -38,16 +37,16 @@ const Mark = {
3837
};
3938

4039
module.exports = function (context, options = defaultOptions) {
41-
const {Syntax, RuleError, report, getSource} = context;
40+
const { Syntax, RuleError, report, getSource } = context;
4241
const helper = new RuleHelper(context);
43-
const allow = options.allow || defaultOptions.allow;
42+
const allow = (options.allow || defaultOptions.allow).concat(DEFAULT_ALLOW_LIST);
4443
const allowHalfWidthExclamation = options.allowHalfWidthExclamation || defaultOptions.allowHalfWidthExclamation;
4544
const allowFullWidthExclamation = options.allowFullWidthExclamation || defaultOptions.allowFullWidthExclamation;
4645
const allowHalfWidthQuestion = options.allowHalfWidthQuestion || defaultOptions.allowHalfWidthQuestion;
4746
const allowFullWidthQuestion = options.allowFullWidthQuestion || defaultOptions.allowFullWidthQuestion;
4847

4948
return {
50-
[Syntax.Str](node){
49+
[Syntax.Str](node) {
5150
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
5251
return;
5352
}
@@ -60,16 +59,19 @@ module.exports = function (context, options = defaultOptions) {
6059
const reportIfIncludeMark = (text, markRegExp) => {
6160
const ignoreMatch = matchPatterns(text, allow);
6261
matchCaptureGroupAll(text, markRegExp).forEach((actual) => {
63-
const {text, index} = actual;
62+
const { text, index } = actual;
6463

6564
// 無視する単語を含んでいるなら無視
6665
if (isIgnoredRange(ignoreMatch, actual)) {
6766
return;
6867
}
6968

70-
report(node, new RuleError(`Disallow to use "${text}".`, {
71-
index
72-
}));
69+
report(
70+
node,
71+
new RuleError(`Disallow to use "${text}".`, {
72+
index
73+
})
74+
);
7375
});
7476
};
7577
// Check
@@ -86,5 +88,5 @@ module.exports = function (context, options = defaultOptions) {
8688
reportIfIncludeMark(text, Mark.FullWidthQuestion);
8789
}
8890
}
89-
}
90-
};
91+
};
92+
};

test/textlint-rule-no-exclamation-question-mark-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ tester.run("no-exclamation-question-mark", rule, {
8989
]
9090
}
9191
]
92-
});
92+
});

0 commit comments

Comments
 (0)