Skip to content
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

Migrate babel to textlint-scripts #3

Merged
merged 3 commits into from Jan 2, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 0 additions & 13 deletions .babelrc

This file was deleted.

35 changes: 24 additions & 11 deletions package.json
Expand Up @@ -21,29 +21,42 @@
"test": "test"
},
"scripts": {
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"build": "textlint-scripts build",
"watch": "textlint-scripts build --watch",
"prepublish": "npm run --if-present build",
"test": "mocha"
"test": "textlint-scripts test",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
},
"keywords": [
"textlint",
"textlintrule"
],
"description": "ら抜き言葉を検出するtextlint rule",
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.20",
"babel-preset-es2015": "^6.9.0",
"babel-preset-jsdoc-to-assert": "^2.0.1",
"babel-preset-power-assert": "^1.0.0",
"babel-register": "^6.9.0",
"mocha": "^2.3.3",
"husky": "^1.3.1",
"lint-staged": "^8.1.0",
"power-assert": "^1.4.1",
"textlint-tester": "^1.2.0"
"prettier": "^1.15.3",
"textlint-scripts": "^2.1.0"
},
"dependencies": {
"kuromojin": "^1.2.1",
"textlint-rule-helper": "^1.1.4"
},
"prettier": {
"singleQuote": false,
"printWidth": 120,
"tabWidth": 4
},
"husky": {
"hooks": {
"precommit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css}": [
"prettier --write",
"git add"
]
}
}
45 changes: 25 additions & 20 deletions src/no-dropping-the-ra.js
@@ -1,41 +1,43 @@
// LICENSE : MIT
"use strict";
import {RuleHelper} from "textlint-rule-helper";
import { RuleHelper } from "textlint-rule-helper";
import kuromojin from "kuromojin";

function isTargetVerb(token) {
return token.pos == '動詞' &&
token.pos_detail_1 == '自立' &&
token.conjugated_type == '一段' &&
token.conjugated_form == '未然形';
return (
token.pos == "動詞" &&
token.pos_detail_1 == "自立" &&
token.conjugated_type == "一段" &&
token.conjugated_form == "未然形"
);
}

function isRaWord(token) {
return token.pos == '動詞' &&
token.pos_detail_1 == '接尾' &&
token.basic_form == 'れる'
return token.pos == "動詞" && token.pos_detail_1 == "接尾" && token.basic_form == "れる";
}

function isKoreru(token) {
return token.pos == '動詞' &&
token.basic_form == '来れる'
return token.pos == "動詞" && token.basic_form == "来れる";
}

module.exports = function(context) {
const helper = new RuleHelper(context);
const {Syntax, report, getSource, RuleError} = context;
const { Syntax, report, getSource, RuleError } = context;
return {
[Syntax.Str](node){
[Syntax.Str](node) {
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
return;
}
const text = getSource(node);
return kuromojin(text).then(tokens => {
tokens.forEach((token) => {
tokens.forEach(token => {
if (isKoreru(token)) {
report(node, new RuleError("ら抜き言葉を使用しています。", {
index: (token.word_position)
}));
report(
node,
new RuleError("ら抜き言葉を使用しています。", {
index: token.word_position
})
);
}
});
// tokenのペアがない場合は無視する
Expand All @@ -44,13 +46,16 @@ module.exports = function(context) {
}
tokens.reduce((prev, current) => {
if (isTargetVerb(prev) && isRaWord(current)) {
report(node, new RuleError("ら抜き言葉を使用しています。", {
index: (current.word_position - 1)
}));
report(
node,
new RuleError("ら抜き言葉を使用しています。", {
index: current.word_position - 1
})
);
}
return current;
});
});
}
}
};
};
2 changes: 1 addition & 1 deletion test/mocha.opts
@@ -1 +1 @@
--compilers js:babel-register
--require textlint-scripts/register