Skip to content

Commit dc87dc6

Browse files
authored
refactor(rule): Convert to TypeScript (#11)
1 parent 18485a5 commit dc87dc6

8 files changed

+779
-204
lines changed

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@
3333
"textlintrule"
3434
],
3535
"devDependencies": {
36-
"textlint-scripts": "^2.1.0"
36+
"@textlint/types": "^1.1.5",
37+
"@types/node": "^12.0.12",
38+
"textlint-scripts": "^3.0.0-beta.1",
39+
"ts-node": "^8.3.0",
40+
"typescript": "^3.5.2"
3741
},
3842
"dependencies": {
39-
"kuromojin": "^1.3.1",
40-
"morpheme-match-textlint": "^2.0.0",
43+
"kuromojin": "^2.0.0",
44+
"morpheme-match-textlint": "^2.0.3",
4145
"textlint-rule-prh": "^5.2.1"
4246
}
4347
}

src/dictionary.js renamed to src/dictionary.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = [
1+
export default [
22
{
33
// http://azu.github.io/morpheme-match/?text=今朝起きた事件に法律(を適応)する
44
message: `"適用"の誤用である可能性があります。適応 => 適用`,

src/textlint-rule-ja-no-abusage.js renamed to src/textlint-rule-ja-no-abusage.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"use strict";
33
import {createTextlintMatcher} from "morpheme-match-textlint"
44

5-
const tokenize = require("kuromojin").tokenize;
6-
const fs = require("fs");
7-
const path = require("path");
8-
const prh = require("textlint-rule-prh");
9-
const dictionaryList = require("./dictionary");
5+
import path from "path";
6+
import fs from "fs";
7+
8+
import {tokenize} from "kuromojin";
9+
import {TextlintRuleReporter} from "@textlint/types";
10+
import dictionaryList from "./dictionary";
1011

11-
const reporter = (context) => {
12+
const prh = require("textlint-rule-prh");
13+
const reporter: TextlintRuleReporter = (context) => {
1214
const {Syntax, RuleError, report, fixer, getSource} = context;
1315
const matcherList = createTextlintMatcher({
1416
tokenize: tokenize,
@@ -17,7 +19,7 @@ const reporter = (context) => {
1719
const prhLinter = prh.linter;
1820
const prhStr = prhLinter(context, {
1921
ruleContents: [
20-
fs.readFileSync(path.join(__dirname, "..", "dict", "prh.yml"))
22+
fs.readFileSync(path.join(__dirname, "..", "dict", "prh.yml"),"utf-8")
2123
]
2224
});
2325
return {

test/mocha.opts

-1
This file was deleted.

test/no-confusing-adjust-and-apply-test.js renamed to test/no-confusing-adjust-and-apply-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const TextLintTester = require("textlint-tester");
44
const tester = new TextLintTester();
55
// rule
6-
import rule from "../src/textlint-rule-ja-no-abusage";
6+
const rule = require("../src/textlint-rule-ja-no-abusage");
77
// ruleName, rule, { valid, invalid }
88
tester.run("textlint-rule-no-confusing-adjust-and-apply", rule, {
99
valid: [

test/no-variable-test.js renamed to test/no-variable-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// LICENSE : MIT
22
"use strict";
3-
const TextLintTester = require("textlint-tester");
3+
import TextLintTester from "textlint-tester";
44
const tester = new TextLintTester();
55
// rule
6-
import rule from "../src/textlint-rule-ja-no-abusage";
6+
const rule = require("../src/textlint-rule-ja-no-abusage");
77
// ruleName, rule, { valid, invalid }
88
tester.run("可変", rule, {
99
valid: [

tsconfig.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"noEmit": true,
8+
"target": "es2015",
9+
/* Strict Type-Checking Options */
10+
"strict": true,
11+
/* Additional Checks */
12+
/* Report errors on unused locals. */
13+
"noUnusedLocals": true,
14+
/* Report errors on unused parameters. */
15+
"noUnusedParameters": true,
16+
/* Report error when not all code paths in function return a value. */
17+
"noImplicitReturns": true,
18+
/* Report errors for fallthrough cases in switch statement. */
19+
"noFallthroughCasesInSwitch": true
20+
}
21+
}

0 commit comments

Comments
 (0)