Skip to content

Commit 620f8ab

Browse files
authored
Merge pull request #3 from textlint-ja/migrate-babel-totextlint-scripts
Migrate babel to textlint-scripts
2 parents 21a4df5 + 2b6f771 commit 620f8ab

File tree

5 files changed

+4397
-45
lines changed

5 files changed

+4397
-45
lines changed

.babelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,42 @@
2121
"test": "test"
2222
},
2323
"scripts": {
24-
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
25-
"watch": "babel src --out-dir lib --watch --source-maps",
24+
"build": "textlint-scripts build",
25+
"watch": "textlint-scripts build --watch",
2626
"prepublish": "npm run --if-present build",
27-
"test": "mocha"
27+
"test": "textlint-scripts test",
28+
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
2829
},
2930
"keywords": [
3031
"textlint",
3132
"textlintrule"
3233
],
3334
"description": "ら抜き言葉を検出するtextlint rule",
3435
"devDependencies": {
35-
"babel-cli": "^6.10.1",
36-
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.20",
37-
"babel-preset-es2015": "^6.9.0",
38-
"babel-preset-jsdoc-to-assert": "^2.0.1",
39-
"babel-preset-power-assert": "^1.0.0",
40-
"babel-register": "^6.9.0",
41-
"mocha": "^2.3.3",
36+
"husky": "^1.3.1",
37+
"lint-staged": "^8.1.0",
4238
"power-assert": "^1.4.1",
43-
"textlint-tester": "^1.2.0"
39+
"prettier": "^1.15.3",
40+
"textlint-scripts": "^2.1.0"
4441
},
4542
"dependencies": {
4643
"kuromojin": "^1.2.1",
4744
"textlint-rule-helper": "^1.1.4"
45+
},
46+
"prettier": {
47+
"singleQuote": false,
48+
"printWidth": 120,
49+
"tabWidth": 4
50+
},
51+
"husky": {
52+
"hooks": {
53+
"precommit": "lint-staged"
54+
}
55+
},
56+
"lint-staged": {
57+
"*.{js,jsx,ts,tsx,css}": [
58+
"prettier --write",
59+
"git add"
60+
]
4861
}
4962
}

src/no-dropping-the-ra.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
// LICENSE : MIT
22
"use strict";
3-
import {RuleHelper} from "textlint-rule-helper";
3+
import { RuleHelper } from "textlint-rule-helper";
44
import kuromojin from "kuromojin";
55

66
function isTargetVerb(token) {
7-
return token.pos == '動詞' &&
8-
token.pos_detail_1 == '自立' &&
9-
token.conjugated_type == '一段' &&
10-
token.conjugated_form == '未然形';
7+
return (
8+
token.pos == "動詞" &&
9+
token.pos_detail_1 == "自立" &&
10+
token.conjugated_type == "一段" &&
11+
token.conjugated_form == "未然形"
12+
);
1113
}
1214

1315
function isRaWord(token) {
14-
return token.pos == '動詞' &&
15-
token.pos_detail_1 == '接尾' &&
16-
token.basic_form == 'れる'
16+
return token.pos == "動詞" && token.pos_detail_1 == "接尾" && token.basic_form == "れる";
1717
}
1818

1919
function isKoreru(token) {
20-
return token.pos == '動詞' &&
21-
token.basic_form == '来れる'
20+
return token.pos == "動詞" && token.basic_form == "来れる";
2221
}
2322

2423
module.exports = function(context) {
2524
const helper = new RuleHelper(context);
26-
const {Syntax, report, getSource, RuleError} = context;
25+
const { Syntax, report, getSource, RuleError } = context;
2726
return {
28-
[Syntax.Str](node){
27+
[Syntax.Str](node) {
2928
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
3029
return;
3130
}
3231
const text = getSource(node);
3332
return kuromojin(text).then(tokens => {
34-
tokens.forEach((token) => {
33+
tokens.forEach(token => {
3534
if (isKoreru(token)) {
36-
report(node, new RuleError("ら抜き言葉を使用しています。", {
37-
index: (token.word_position)
38-
}));
35+
report(
36+
node,
37+
new RuleError("ら抜き言葉を使用しています。", {
38+
index: token.word_position
39+
})
40+
);
3941
}
4042
});
4143
// tokenのペアがない場合は無視する
@@ -44,13 +46,16 @@ module.exports = function(context) {
4446
}
4547
tokens.reduce((prev, current) => {
4648
if (isTargetVerb(prev) && isRaWord(current)) {
47-
report(node, new RuleError("ら抜き言葉を使用しています。", {
48-
index: (current.word_position - 1)
49-
}));
49+
report(
50+
node,
51+
new RuleError("ら抜き言葉を使用しています。", {
52+
index: current.word_position - 1
53+
})
54+
);
5055
}
5156
return current;
5257
});
5358
});
5459
}
55-
}
60+
};
5661
};

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--compilers js:babel-register
1+
--require textlint-scripts/register

0 commit comments

Comments
 (0)