Skip to content

Commit

Permalink
refactor(rule): Convert to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jul 7, 2019
1 parent feb4f47 commit 126a270
Show file tree
Hide file tree
Showing 8 changed files with 779 additions and 204 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
"textlintrule"
],
"devDependencies": {
"textlint-scripts": "^2.1.0"
"@textlint/types": "^1.1.5",
"@types/node": "^12.0.12",
"textlint-scripts": "^3.0.0-beta.1",
"ts-node": "^8.3.0",
"typescript": "^3.5.2"
},
"dependencies": {
"kuromojin": "^1.3.1",
"morpheme-match-textlint": "^2.0.0",
"kuromojin": "^2.0.0",
"morpheme-match-textlint": "^2.0.3",
"textlint-rule-prh": "^5.2.1"
}
}
2 changes: 1 addition & 1 deletion src/dictionary.js → src/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [
export default [
{
// http://azu.github.io/morpheme-match/?text=今朝起きた事件に法律(を適応)する
message: `"適用"の誤用である可能性があります。適応 => 適用`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"use strict";
import {createTextlintMatcher} from "morpheme-match-textlint"

const tokenize = require("kuromojin").tokenize;
const fs = require("fs");
const path = require("path");
const prh = require("textlint-rule-prh");
const dictionaryList = require("./dictionary");
import path from "path";
import fs from "fs";

import {tokenize} from "kuromojin";
import {TextlintRuleReporter} from "@textlint/types";
import dictionaryList from "./dictionary";

const reporter = (context) => {
const prh = require("textlint-rule-prh");
const reporter: TextlintRuleReporter = (context) => {
const {Syntax, RuleError, report, fixer, getSource} = context;
const matcherList = createTextlintMatcher({
tokenize: tokenize,
Expand All @@ -17,7 +19,7 @@ const reporter = (context) => {
const prhLinter = prh.linter;
const prhStr = prhLinter(context, {
ruleContents: [
fs.readFileSync(path.join(__dirname, "..", "dict", "prh.yml"))
fs.readFileSync(path.join(__dirname, "..", "dict", "prh.yml"),"utf-8")
]
});
return {
Expand Down
1 change: 0 additions & 1 deletion test/mocha.opts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const TextLintTester = require("textlint-tester");
const tester = new TextLintTester();
// rule
import rule from "../src/textlint-rule-ja-no-abusage";
const rule = require("../src/textlint-rule-ja-no-abusage");
// ruleName, rule, { valid, invalid }
tester.run("textlint-rule-no-confusing-adjust-and-apply", rule, {
valid: [
Expand Down
4 changes: 2 additions & 2 deletions test/no-variable-test.js → test/no-variable-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// LICENSE : MIT
"use strict";
const TextLintTester = require("textlint-tester");
import TextLintTester from "textlint-tester";
const tester = new TextLintTester();
// rule
import rule from "../src/textlint-rule-ja-no-abusage";
const rule = require("../src/textlint-rule-ja-no-abusage");
// ruleName, rule, { valid, invalid }
tester.run("可変", rule, {
valid: [
Expand Down
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
/* Basic Options */
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"noEmit": true,
"target": "es2015",
/* Strict Type-Checking Options */
"strict": true,
/* Additional Checks */
/* Report errors on unused locals. */
"noUnusedLocals": true,
/* Report errors on unused parameters. */
"noUnusedParameters": true,
/* Report error when not all code paths in function return a value. */
"noImplicitReturns": true,
/* Report errors for fallthrough cases in switch statement. */
"noFallthroughCasesInSwitch": true
}
}
Loading

0 comments on commit 126a270

Please sign in to comment.