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

refactor(rule): Convert to TypeScript #11

Merged
merged 1 commit into from
Aug 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For inlining

]
});
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