Skip to content

Commit ff643e2

Browse files
committed
initial commit
0 parents  commit ff643e2

File tree

10 files changed

+3960
-0
lines changed

10 files changed

+3960
-0
lines changed

.gitignore

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore
2+
3+
# Logs
4+
logs
5+
*.log
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# node-waf configuration
22+
.lock-wscript
23+
24+
# Compiled binary addons (http://nodejs.org/api/addons.html)
25+
build/Release
26+
27+
# Dependency directory
28+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
29+
node_modules
30+
31+
# Debug log from npm
32+
npm-debug.log
33+
34+
35+
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore
36+
37+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
38+
39+
*.iml
40+
41+
## Directory-based project format:
42+
.idea/
43+
# if you remove the above rule, at least ignore the following:
44+
45+
# User-specific stuff:
46+
# .idea/workspace.xml
47+
# .idea/tasks.xml
48+
# .idea/dictionaries
49+
50+
# Sensitive or high-churn files:
51+
# .idea/dataSources.ids
52+
# .idea/dataSources.xml
53+
# .idea/sqlDataSources.xml
54+
# .idea/dynamic.xml
55+
# .idea/uiDesigner.xml
56+
57+
# Gradle:
58+
# .idea/gradle.xml
59+
# .idea/libraries
60+
61+
# Mongo Explorer plugin:
62+
# .idea/mongoSettings.xml
63+
64+
## File-based project format:
65+
*.ipr
66+
*.iws
67+
68+
## Plugin-specific files:
69+
70+
# IntelliJ
71+
out/
72+
73+
# mpeltonen/sbt-idea plugin
74+
.idea_modules/
75+
76+
# JIRA plugin
77+
atlassian-ide-plugin.xml
78+
79+
# Crashlytics plugin (for Android Studio and IntelliJ)
80+
com_crashlytics_export_strings.xml
81+
crashlytics.properties
82+
crashlytics-build.properties
83+
84+
85+
/lib

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sudo: false
2+
language: node_js
3+
node_js: "stable"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018 azu
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# @textlint-rule/textlint-rule-no-unmatched-pair
2+
3+
textlint rule that check unmatched pairs like `` and `]`
4+
5+
## Support pair characters
6+
7+
- double quote: `"` and `"`
8+
- angled bracket[]: `[` and `]`
9+
- round bracket(): `` and ``
10+
- curly brace{}: `{` and `}`
11+
- かぎ括弧「」: `` and ``
12+
- 二重かぎ括弧『』: `` and ``
13+
- 全角丸括弧(): `(` and `)`
14+
- 波括弧{}: `` and ``
15+
- 角括弧[]: `` and ``
16+
- 重角括弧〚〛: `` and ``
17+
- 隅付き括弧【】: `` and ``
18+
19+
## Examples
20+
21+
**OK**:
22+
23+
```
24+
これは(秘密)です。
25+
John said "Hello World!".
26+
```
27+
28+
**NG**:
29+
30+
```
31+
これは(秘密)です。
32+
John said "Hello World!'.
33+
```
34+
35+
36+
## Install
37+
38+
Install with [npm](https://www.npmjs.com/):
39+
40+
npm install @textlint-rule/textlint-rule-no-unmatched-pair
41+
42+
## Usage
43+
44+
Via `.textlintrc`(Recommended)
45+
46+
```json
47+
{
48+
"rules": {
49+
"@textlint-rule/no-unmatched-pair": true
50+
}
51+
}
52+
```
53+
54+
Via CLI
55+
56+
```
57+
textlint --rule @textlint-rule/no-unmatched-pair README.md
58+
```
59+
60+
61+
## Changelog
62+
63+
See [Releases page](https://github.com/textlint-rule/textlint-rule-no-unmatched-pair/releases).
64+
65+
## Running tests
66+
67+
Install devDependencies and Run `npm test`:
68+
69+
npm i -d && npm test
70+
71+
## Contributing
72+
73+
Pull requests and stars are always welcome.
74+
75+
For bugs and feature requests, [please create an issue](https://github.com/textlint-rule/textlint-rule-no-unmatched-pair/issues).
76+
77+
1. Fork it!
78+
2. Create your feature branch: `git checkout -b my-new-feature`
79+
3. Commit your changes: `git commit -am 'Add some feature'`
80+
4. Push to the branch: `git push origin my-new-feature`
81+
5. Submit a pull request :D
82+
83+
## Author
84+
85+
- [github/azu](https://github.com/azu)
86+
- [twitter/azu_re](https://twitter.com/azu_re)
87+
88+
## License
89+
90+
MIT © azu

package.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "@textlint-rule/textlint-rule-no-unmatched-pair",
3+
"version": "1.0.0",
4+
"description": "textlint rule that check unmatched pairs like \"\" and \")\"",
5+
"keywords": [
6+
"textlintrule"
7+
],
8+
"homepage": "https://github.com/textlint-rule/textlint-rule-no-unmatched-pair",
9+
"bugs": {
10+
"url": "https://github.com/textlint-rule/textlint-rule-no-unmatched-pair/issues"
11+
},
12+
"license": "MIT",
13+
"author": "azu",
14+
"files": [
15+
"bin/",
16+
"lib/",
17+
"src/"
18+
],
19+
"main": "lib/textlint-rule-no-unmatched-pair.js",
20+
"directories": {
21+
"lib": "lib",
22+
"test": "test"
23+
},
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/textlint-rule/textlint-rule-no-unmatched-pair.git"
27+
},
28+
"scripts": {
29+
"build": "textlint-scripts build",
30+
"prepublish": "npm run --if-present build",
31+
"test": "textlint-scripts test",
32+
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
33+
"watch": "textlint-scripts build --watch"
34+
},
35+
"prettier": {
36+
"printWidth": 120,
37+
"singleQuote": false,
38+
"tabWidth": 4
39+
},
40+
"devDependencies": {
41+
"husky": "^1.1.1",
42+
"lint-staged": "^7.3.0",
43+
"prettier": "^1.8.1",
44+
"textlint-scripts": "^2.1.0"
45+
},
46+
"publishConfig": {
47+
"access": "public"
48+
},
49+
"husky": {
50+
"hooks": {
51+
"precommit": "lint-staged"
52+
}
53+
},
54+
"lint-staged": {
55+
"*.{js,jsx,ts,tsx,css}": [
56+
"prettier --write",
57+
"git add"
58+
]
59+
},
60+
"dependencies": {
61+
"sentence-splitter": "^3.0.11"
62+
}
63+
}

src/parser/PairMaker.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* Mark pair character
3+
* PairMarker aim to mark pair string as a single sentence.
4+
*
5+
* For example, Following sentence has two period(。). but it should treat a single sentence
6+
*
7+
* > I hear "I'm back to home." from radio.
8+
*
9+
* https://ja.wikipedia.org/wiki/%E6%8B%AC%E5%BC%A7
10+
*/
11+
/**
12+
* @typedef {{key:string,start:string,end:string}[]} PairMark
13+
*/
14+
const PAIR_MARKS = [
15+
{
16+
key: "double quote",
17+
start: `"`,
18+
end: `"`
19+
},
20+
{
21+
key: "angled bracket[]",
22+
start: `[`,
23+
end: `]`
24+
},
25+
{
26+
key: "round bracket()",
27+
start: `(`,
28+
end: `)`
29+
},
30+
{
31+
key: "curly brace{}",
32+
start: `{`,
33+
end: `}`
34+
},
35+
{
36+
key: "かぎ括弧「」",
37+
start: `「`,
38+
end: `」`
39+
},
40+
{
41+
key: "二重かぎ括弧『』",
42+
start: `『`,
43+
end: `』`
44+
},
45+
{
46+
key: "全角丸括弧()",
47+
start: `(`,
48+
end: `)`
49+
},
50+
{
51+
key: "波括弧{}",
52+
start: `{`,
53+
end: `}`
54+
},
55+
{
56+
key: "角括弧[]",
57+
start: `[`,
58+
end: `]`
59+
},
60+
{
61+
key: "重角括弧〚〛",
62+
start: `〚`,
63+
end: `〛`
64+
},
65+
{
66+
key: "隅付き括弧【】",
67+
start: `【`,
68+
end: `】`
69+
}
70+
];
71+
72+
// For readme
73+
// console.log(PAIR_MARKS.map(pair => `- ${pair.key}: \`${pair.start}\` and \`${pair.end}\``).join("\n"));
74+
export class PairMaker {
75+
mark(sourceCode) {
76+
const string = sourceCode.read();
77+
if (!string) {
78+
return;
79+
}
80+
// if current is in a context, should not start other context.
81+
// PairMaker does not support nest context by design.
82+
if (sourceCode.isInContext()) {
83+
// check that string is end mark?
84+
const pair = PAIR_MARKS.find(pair => pair.end === string);
85+
if (pair) {
86+
sourceCode.leaveContext(pair);
87+
}
88+
} else {
89+
const pair = PAIR_MARKS.find(pair => pair.start === string);
90+
if (pair) {
91+
sourceCode.enterContext(pair);
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)