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

feat: add TypeScript support #106

Merged
merged 7 commits into from Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 9 additions & 8 deletions README.md
Expand Up @@ -19,7 +19,7 @@ Just **focus** on coding.

- [Setup your project](#setup-your-project)
- [Base requirements](#base-requirements)
- [Vanilla](#vanilla)
- [Vanilla or TypeScript](#vanilla-or-typescript)
- [Jest](#jest)
- [React](#react)
- [Flow](#flow)
Expand All @@ -41,13 +41,14 @@ Just **focus** on coding.

```sh
yarn add \
eslint babel-eslint prettier \
eslint @typescript-eslint/parser prettier \
eslint-config-algolia eslint-config-prettier \
eslint-plugin-import eslint-plugin-prettier \
@typescript-eslint/eslint-plugin typescript \
--dev
```

### Vanilla
### Vanilla or TypeScript

**.eslintrc.js**
```js
Expand All @@ -61,7 +62,7 @@ module.exports = {
{
"scripts": {
"test": "npm run lint",
"lint": "eslint .",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "npm run lint -- --fix"
}
}
Expand All @@ -88,7 +89,7 @@ module.exports = {
{
"scripts": {
"test": "npm run lint",
"lint": "eslint .",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "npm run lint -- --fix"
}
}
Expand All @@ -113,7 +114,7 @@ module.exports = {
{
"scripts": {
"test": "npm run lint",
"lint": "eslint .",
"lint": "eslint --ext .js,.ts,.tsx .",
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
"lint:fix": "npm run lint -- --fix"
}
}
Expand Down Expand Up @@ -152,7 +153,7 @@ module.exports = {
{
"scripts": {
"test": "npm run lint",
"lint": "eslint .",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "npm run lint -- --fix"
}
}
Expand Down Expand Up @@ -202,7 +203,7 @@ module.exports = {
{
"scripts": {
"test": "npm run lint",
"lint": "eslint .",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "npm run lint -- --fix"
}
}
Expand Down
3 changes: 2 additions & 1 deletion base.js
Expand Up @@ -5,7 +5,7 @@ module.exports = {
es6: true,
node: true,
},
parser: 'babel-eslint', // allows both flowtype and static class properties
parser: '@typescript-eslint/parser',
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
Expand All @@ -17,6 +17,7 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:import/errors',
'./rules/typescript.js',
'./rules/base.js',
'prettier',
],
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -35,6 +35,8 @@
},
"homepage": "https://github.com/algolia/eslint-config-algolia",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.6.0",
"conventional-changelog-cli": "2.0.12",
"doctoc": "1.4.0",
"eslint": "5.16.0",
Expand All @@ -43,6 +45,7 @@
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jest": "21.27.2",
"eslint-plugin-prettier": "2.7.0",
"json": "9.0.6"
"json": "9.0.6",
"typescript": "3.4.3"
}
}
10 changes: 5 additions & 5 deletions rules/base.js
Expand Up @@ -120,8 +120,8 @@ module.exports = {
'no-shadow-restricted-names': ['error'],
'no-undef': ['error'],
'no-undefined': ['off'],
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
'no-use-before-define': ['error', { functions: false }],
'no-unused-vars': ['off'], // Superset by @typescript-eslint/no-unused-vars
'no-use-before-define': ['off'], // Superset by @typescript-eslint/no-use-before-define

// Node.js and Common.js
// http://eslint.org/docs/rules/#nodejs-and-commonjs
Expand All @@ -141,7 +141,7 @@ module.exports = {
'array-bracket-spacing': ['error'],
'block-spacing': ['error'],
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
camelcase: ['error'],
camelcase: ['off'], // Superset by @typescript-eslint/camelcase
'comma-dangle': ['error', 'always-multiline'],
'comma-spacing': ['error'],
'comma-style': ['error'],
Expand Down Expand Up @@ -181,7 +181,7 @@ module.exports = {
'newline-after-var': ['off'],
'newline-before-return': ['off'],
'newline-per-chained-call': ['off'],
'no-array-constructor': ['error'],
'no-array-constructor': ['off'], // Superset by @typescript-eslint/no-array-constructor
'no-bitwise': ['error'],
'no-continue': ['error'],
'no-inline-comments': ['off'],
Expand Down Expand Up @@ -240,7 +240,7 @@ module.exports = {
'no-restricted-imports': ['off'],
'no-this-before-super': ['error'],
'no-useless-computed-key': ['error'],
'no-useless-constructor': ['error'],
'no-useless-constructor': ['off'], // Superset by @typescript-eslint/no-useless-constructor
'no-useless-rename': ['error'],
'no-var': ['error'],
'object-shorthand': ['error'],
Expand Down
61 changes: 61 additions & 0 deletions rules/typescript.js
@@ -0,0 +1,61 @@
// eslint-disable-next-line import/no-commonjs
module.exports = {
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/adjacent-overload-signatures': ['error'],
'@typescript-eslint/array-type': ['error', 'array-simple'],
'@typescript-eslint/ban-types': ['error'],
'@typescript-eslint/ban-ts-ignore': ['off'],
'@typescript-eslint/camelcase': ['error'],
'@typescript-eslint/class-name-casing': ['error'],
'@typescript-eslint/explicit-function-return-type': ['off'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@yannickcr yannickcr Apr 15, 2019

Choose a reason for hiding this comment

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

No objection on this but it will add a little more work to type our code. There will be 7 errors to fix in InstantSearch.js but it should not be too difficult.

'@typescript-eslint/explicit-member-accessibility': ['error'],
'@typescript-eslint/generic-type-naming': ['off'],
Copy link
Contributor

@samouss samouss Apr 15, 2019

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@yannickcr yannickcr Apr 15, 2019

Choose a reason for hiding this comment

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

No objection on this. There will be 10 errors to fix in InstantSearch.js, I'll need a little help to fix them but nothing insurmountable.

'@typescript-eslint/indent': ['off'],
'@typescript-eslint/interface-name-prefix': ['error', 'never'],
'@typescript-eslint/member-delimiter-style': ['off'],
'@typescript-eslint/member-naming': ['off'],
'@typescript-eslint/member-ordering': [
'error',
{
default: ['static-field'],
},
],
'@typescript-eslint/no-angle-bracket-type-assertion': ['error'],
'@typescript-eslint/no-array-constructor': ['error'],
'@typescript-eslint/no-empty-interface': ['error'],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-extraneous-class': ['off'],
'@typescript-eslint/no-for-in-array': ['off'],
'@typescript-eslint/no-inferrable-types': ['off'],
'@typescript-eslint/no-misused-new': ['error'],
'@typescript-eslint/no-namespace': ['error'],
'@typescript-eslint/no-non-null-assertion': ['off'],
'@typescript-eslint/no-object-literal-type-assertion': ['off'],
'@typescript-eslint/no-parameter-properties': ['off'],
'@typescript-eslint/no-require-imports': ['off'],
'@typescript-eslint/no-this-alias': ['off'],
'@typescript-eslint/no-triple-slash-reference': ['error'],
'@typescript-eslint/no-type-alias': ['off'],
'@typescript-eslint/no-unnecessary-qualifier': ['off'],
'@typescript-eslint/no-unnecessary-type-assertion': ['off'],
'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
'@typescript-eslint/no-useless-constructor': ['error'],
'@typescript-eslint/no-var-requires': ['error'],
'@typescript-eslint/prefer-for-of': ['off'],
'@typescript-eslint/prefer-function-type': ['error'],
'@typescript-eslint/prefer-interface': ['off'],
'@typescript-eslint/prefer-namespace-keyword': ['error'],
'@typescript-eslint/promise-function-async': ['off'],
'@typescript-eslint/restrict-plus-operands': ['off'],
'@typescript-eslint/type-annotation-spacing': ['error'],
'@typescript-eslint/unbound-method': ['off'],
'@typescript-eslint/unified-signatures': ['error'],
},
};
6 changes: 4 additions & 2 deletions sample-project/package.json
Expand Up @@ -17,14 +17,16 @@
"react-addons-shallow-compare": "15.6.2"
},
"devDependencies": {
"babel-eslint": "10.0.1",
"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.6.0",
"eslint": "5.16.0",
"eslint-config-algolia": "file:../",
"eslint-config-prettier": "3.6.0",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jest": "21.27.2",
"eslint-plugin-prettier": "2.7.0",
"eslint-plugin-react": "7.7.0",
"prettier": "1.16.4"
"prettier": "1.16.4",
"typescript": "3.4.3"
}
}