Skip to content

Commit 8b7012f

Browse files
koba04toshi-toma
authored andcommitted
feat: Support TypeScript (#93)
* add @typescript-eslint/eslint-plugin * add typescript into devDeps and peerDeps * add lib/typescript and presets/typescript * update typescript-eslint rules * add preset/typescript-prettier and preset/typescript-node-prettier * add presets/react-typescript-prettier * tweak presets and rules * Add tsconfig.json only for testing TypeScript rules * add tests for lib/typescript * add tests for lib/react-typescript * add tests for presets/node-typescript-prettier * add tests for presets/react-typescript-prettier * add tests for presets/react-typescript * add tests for presets/typescript-prettier * disable `no-useless-constructor` in lib/typescript * add tests for presets/typescript * fix file name * add typescript preset for README.md * chore updat README * set timeout option for mocha
1 parent 217cdff commit 8b7012f

24 files changed

+433
-71
lines changed

README.md

Lines changed: 19 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -73,70 +73,21 @@ module.exports = {
7373

7474
## Support rule set
7575

76-
### `@cybozu`
77-
78-
This rule set is a basic rules for Cybozu, which supports ES2017 and parse your sources as Modules.
79-
80-
```js
81-
module.exports = {
82-
extends: "@cybozu"
83-
};
84-
```
85-
86-
### `@cybozu/eslint-config/node`
87-
88-
This rule set is for projects running on a Node environment.
89-
90-
```js
91-
module.exports = {
92-
extends: "@cybozu/eslint-config/presets/node"
93-
};
94-
```
95-
96-
### [Experimental] `@cybozu/eslint-config/presets/react`
97-
98-
This rule set is for projects using React, which has JSX support and rules related React provided by `eslint-plugin-react` and `eslint-plugin-jsx-ally`.
99-
This rule set includes `@cybozu`.
100-
101-
```js
102-
module.exports = {
103-
extends: "@cybozu/eslint-config/presets/react"
104-
};
105-
```
106-
107-
If you use React and Flow we recommend to use `@cybozu/eslint-config/react-flowtype` instead.
108-
109-
### [Experimental] `@cybozu/eslint-config/presets/flowtype`
110-
111-
This rule set is for projects using Flow, which has Flow support, which is using `eslint-plugin-flowtype`.
112-
113-
```js
114-
module.exports = {
115-
extends: "@cybozu/eslint-config/presets/flowtype"
116-
};
117-
```
118-
119-
If you use React and Flow we recommend to use `@cybozu/eslint-config/react-flowtype` instead.
120-
121-
### [Experimental] `@cybozu/eslint-config/presets/react-flowtype`
122-
123-
This rule set is for projects using React and Flow, which has Flow support in addition to `@cybozu/eslint-config/react`.
124-
125-
```js
126-
module.exports = {
127-
extends: "@cybozu/eslint-config/presets/react-flowtype"
128-
};
129-
```
130-
131-
### `@cybozu/eslint-config/presets/es5`
132-
133-
This rule set is for projects using ES5.
134-
135-
```js
136-
module.exports = {
137-
extends: "@cybozu/eslint-config/presets/es5"
138-
};
139-
```
76+
- `@cybozu`
77+
- This is included in the all following presets
78+
- `@cybozu/eslint-config/presets/node`
79+
- Including `eslint-plugin-node`
80+
- `@cybozu/eslint-config/presets/typescript`
81+
- Including `@typescript-eslint/eslint-plugin`
82+
- `@cybozu/eslint-config/presets/react`
83+
- Including `eslint-plugin-react` and `eslint-plugin-jsx-ally`
84+
- `@cybozu/eslint-config/presets/react-typescript`
85+
- Including `@cybozu/eslint-config/presets/typescript` and `@cybozu/eslint-config/presets/react`
86+
- `@cybozu/eslint-config/presets/flowtype`
87+
- Including `eslint-plugin-flowtype`
88+
- `@cybozu/eslint-config/presets/react-flowtype`
89+
- Including `@cybozu/eslint-config/presets/react` and `eslint-plugin-flowtype`
90+
- `@cybozu/eslint-config/presets/es5`
14091

14192
## Prettier Support
14293

@@ -146,7 +97,6 @@ Prettier is used widely for a code formatter for JavaScript.
14697
It's an opinionated tool but with Prettier, we don't have to discuss code styles in code review.
14798
(No more bikeshed)
14899

149-
`@cybozu/eslint-config` has presets to support Prettier as an experimental.
150100
The presets disable all rules conflicting with Prettier and treat the difference as errors.
151101
You can fix the errors by `--fix` option so you don't have to fix the errors manually.
152102

@@ -158,6 +108,9 @@ In order to this, you have to install `prettier` and choose a preset from the fo
158108

159109
- `@cybozu/eslint-config/presets/prettier`
160110
- `@cybozu/eslint-config/presets/node-prettier`
111+
- `@cybozu/eslint-config/presets/node-typescript-prettier`
112+
- `@cybozu/eslint-config/presets/typescript-prettier`
113+
- `@cybozu/eslint-config/presets/react-typescript-prettier`
161114
- `@cybozu/eslint-config/presets/react-prettier`
162115
- `@cybozu/eslint-config/presets/react-flowtype-prettier`
163116
- `@cybozu/eslint-config/presets/es5-prettier`
@@ -175,3 +128,4 @@ module.exports = {
175128
```
176129

177130
We also provide `@cybozu/eslint-config/presets/kintone-customize-es5-prettier` to use it with `prettier`.
131+

lib/node-typescript.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
"node/no-unsupported-features/es-syntax": "off"
4+
}
5+
};

lib/prettier-typescript.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ["prettier/@typescript-eslint"]
3+
};

lib/react-typescript.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
"react/jsx-filename-extension": ["error", { extensions: [".tsx"] }]
4+
}
5+
};

lib/react.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
"react/void-dom-elements-no-children": "error",
4545

4646
"react/jsx-filename-extension": "error",
47+
4748
// react/jsx-key
4849
// react/jsx-no-duplicate-props
4950
// react/jsx-no-target-blank

lib/typescript.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
plugins: ["@typescript-eslint"],
4+
extends: ["plugin:@typescript-eslint/recommended"],
5+
parserOptions: {
6+
project: "./tsconfig.json"
7+
},
8+
rules: {
9+
"@typescript-eslint/array-type": ["error", "array-simple"],
10+
"@typescript-eslint/no-for-in-array": "error",
11+
12+
"no-useless-constructor": "off",
13+
"@typescript-eslint/no-useless-constructor": "warn",
14+
"@typescript-eslint/type-annotation-spacing": "warn",
15+
"@typescript-eslint/unified-signatures": "warn",
16+
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
17+
"@typescript-eslint/indent": ["warn", 2, { SwitchCase: 1 }],
18+
19+
"@typescript-eslint/camelcase": "off",
20+
"@typescript-eslint/explicit-function-return-type": "off",
21+
"@typescript-eslint/explicit-member-accessibility": "off",
22+
"@typescript-eslint/interface-name-prefix": "off",
23+
"@typescript-eslint/no-explicit-any": "off",
24+
"@typescript-eslint/no-inferrable-types": "off",
25+
// FIXME use NonNullable<T> instead
26+
"@typescript-eslint/no-non-null-assertion": "off",
27+
"@typescript-eslint/no-object-literal-type-assertion": "off",
28+
"@typescript-eslint/no-triple-slash-reference": "off",
29+
"@typescript-eslint/no-unused-vars": "off",
30+
"@typescript-eslint/no-use-before-define": "off",
31+
"@typescript-eslint/no-var-requires": "off",
32+
"@typescript-eslint/prefer-interface": "off",
33+
"@typescript-eslint/prefer-namespace-keyword": "off"
34+
}
35+
};

package-lock.json

Lines changed: 95 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,28 @@
1919
"lint": "eslint **/*.js",
2020
"release": "npm-run-all -p lint test && standard-version",
2121
"release:dryrun": "standard-version --dry-run",
22-
"test": "mocha"
22+
"test": "mocha --timeout 5000"
2323
},
2424
"keywords": [
2525
"eslint"
2626
],
2727
"author": "cybozu",
2828
"license": "MIT",
2929
"devDependencies": {
30+
"@types/react": "^16.8.10",
3031
"eslint": "^5.15.3",
3132
"mocha": "^6.0.2",
3233
"npm-run-all": "^4.1.5",
3334
"prettier": "^1.16.4",
34-
"standard-version": "^5.0.2"
35+
"standard-version": "^5.0.2",
36+
"typescript": "^3.3.4000"
3537
},
3638
"peerDependencies": {
37-
"eslint": "^5.3.0"
39+
"eslint": "^5.3.0",
40+
"typescript": "^3.3.3333"
3841
},
3942
"dependencies": {
43+
"@typescript-eslint/eslint-plugin": "^1.5.0",
4044
"babel-eslint": "^9.0.0",
4145
"eslint-config-prettier": "^4.1.0",
4246
"eslint-plugin-flowtype": "^3.4.2",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: [
3+
"../lib/base.js",
4+
"../lib/node.js",
5+
"../lib/typescript.js",
6+
"../lib/node-typescript.js",
7+
"../lib/prettier.js",
8+
"../lib/prettier-typescript.js"
9+
]
10+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
extends: [
3+
"../lib/base.js",
4+
"../lib/react.js",
5+
"../lib/react-typescript.js",
6+
"../lib/typescript.js",
7+
"../lib/prettier.js",
8+
"../lib/prettier-react.js",
9+
"../lib/prettier-typescript.js"
10+
]
11+
};

0 commit comments

Comments
 (0)