Skip to content

add ja-nakaguro-or-halfwidth-space-between-katakana #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# textlint-rule-ja-nakaguro-or-halfwidth-space-between-katakana

カタカナ語間の区切り文字についてのtextlintルール

## Install

Install with [npm](https://www.npmjs.com/):

npm install textlint-rule-ja-nakaguro-or-halfwidth-space-between-katakana

## Usage

Via `.textlintrc`(Recommended)

```json
{
"rules": {
"ja-nakaguro-or-halfwidth-space-between-katakana": true
}
}
```

Via CLI

```
textlint --rule ja-nakaguro-or-halfwidth-space-between-katakana README.md
```


## Changelog

See [Releases page](https://github.com/extlint-ja/textlint-rule-spacing/releases).

## Running tests

Install devDependencies and Run `npm test`:

npm i -d && npm test

## Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, [please create an issue](https://github.com/extlint-ja/textlint-rule-spacing/issues).

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## Author

- [github/azu](https://github.com/azu)
- [twitter/azu_re](https://twitter.com/azu_re)

## License

MIT © azu
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "textlint-rule-ja-nakaguro-or-halfwidth-space-between-katakana",
"version": "1.0.0",
"description": "カタカナ語間の区切り文字についてのtextlintルール",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/textlint-ja/textlint-rule-spacing.git"
},
"author": "azu",
"email": "[email protected]",
"homepage": "https://github.com/extlint-ja/textlint-rule-spacing",
"license": "MIT",
"bugs": {
"url": "https://github.com/extlint-ja/textlint-rule-spacing/issues"
},
"scripts": {
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"prepublish": "npm run --if-present build",
"test": "mocha"
},
"keywords": [
"textlint"
],
"devDependencies": {
"babel-cli": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"textlint-tester": "^2.0.0",
"mocha": "^2.3.3"
},
"dependencies": {
"match-index": "^1.0.1",
"textlint-rule-helper": "^2.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// LICENSE : MIT
"use strict";
/*
カタカナ語間のスペースの有無
中黒または半角スペースを用いてカタカナ語を区切ります。
*/
import {RuleHelper} from "textlint-rule-helper";
import {matchCaptureGroupAll} from "match-index";
export default function (context) {
const {Syntax, RuleError, report, getSource} = context;
const helper = new RuleHelper();
return {
[Syntax.Str](node){
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
return;
}
const text = getSource(node);
// カタカナ(カタカナ以外)カタカナ のパターンを取り出す
matchCaptureGroupAll(text, /[ァ-ヶー]([^[ァ-ヶー])[ァ-ヶー]/).forEach(match => {
// カタカナの間を全角スペースでは区切らない
const {text} = match;
if (text === " ") {
report(node, new RuleError("カタカナ語間は中黒(・)または半角スペースを用いてカタカナ語を区切ります", {
index: match.index
}));
}
});

}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// LICENSE : MIT
"use strict";
import TextLintTester from "textlint-tester";
import rule from "../src/index";
var tester = new TextLintTester();
tester.run("カタカナ語間のスペースの有無", rule, {
valid: [
"カタカナ・カタカナ",
"カタカナ カタカナ",
"カタカナ、カタカナ",// 例外としてしょうがない気がする
"あいう えお",
"インターフェース ブラウザ"
],
invalid: [
{
text: "カタカナ カタカナ",
errors: [
{
message: "カタカナ語間は中黒(・)または半角スペースを用いてカタカナ語を区切ります",
column: 5
}
]
}
]
});