From accb1c950c7c258a7efcf9cbeaab92273020614f Mon Sep 17 00:00:00 2001 From: yarastqt Date: Sat, 7 Mar 2020 19:49:53 +0300 Subject: [PATCH] chore: use eslint instead tslint --- .eslintignore | 6 ++ .eslintrc.js | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++ .lintstagedrc | 1 + package.json | 9 ++- tslint.json | 116 -------------------------- 5 files changed, 232 insertions(+), 119 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.js delete mode 100644 tslint.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..05478b62 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +!.eslintrc.js + +build +node_modules + +*.d.ts diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..b878444b --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,219 @@ +module.exports = { + parser: '@typescript-eslint/parser', + plugins: ['@typescript-eslint', 'react-hooks', 'react'], + env: { + browser: true, + es6: true, + node: true, + }, + globals: { + __DEV__: true, + }, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + ecmaFeatures: { jsx: true }, + useJSXTextNode: true, + }, + settings: { + react: { + pragma: 'React', + version: '16.0', + }, + }, + rules: { + // see https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/style.js#L122 + indent: [ + 2, + 2, + { + SwitchCase: 1, + VariableDeclarator: 1, + outerIIFEBody: 1, + FunctionDeclaration: { + parameters: 1, + body: 1, + }, + FunctionExpression: { + parameters: 1, + body: 1, + }, + CallExpression: { + arguments: 1, + }, + ArrayExpression: 1, + ObjectExpression: 1, + ImportDeclaration: 1, + flatTernaryExpressions: false, + ignoreComments: false, + }, + ], + + semi: [2, 'never'], + 'semi-spacing': [2, { before: false, after: true }], + 'wrap-iife': [2, 'inside'], + 'no-use-before-define': [2, { functions: true, classes: true, variables: true }], + 'no-caller': 2, + 'no-cond-assign': [2, 'except-parens'], + 'no-constant-condition': 2, + 'no-debugger': 2, + 'no-dupe-args': 2, + 'no-dupe-keys': 2, + 'no-duplicate-case': 2, + 'no-empty': [2, { allowEmptyCatch: true }], + 'no-extra-boolean-cast': 2, + 'no-extra-semi': 2, + 'no-func-assign': 2, + 'no-new': 2, + 'no-sparse-arrays': 2, + 'no-undef': 2, + 'no-unexpected-multiline': 2, + 'no-unreachable': 2, + 'no-unused-vars': [ + 2, + { + args: 'after-used', + argsIgnorePattern: '^_', + ignoreRestSiblings: true, + vars: 'all', + varsIgnorePattern: '^_', + }, + ], + + strict: 2, + 'max-params': [2, 5], + 'max-depth': [1, 4], + 'no-eq-null': 0, + 'no-unused-expressions': 0, + 'dot-notation': 2, + 'use-isnan': 2, + + // Best practices + 'block-scoped-var': 2, + complexity: [0, 11], + curly: [2, 'multi-line'], + eqeqeq: [2, 'always', { null: 'ignore' }], + 'no-else-return': 2, + 'no-extra-bind': 2, + 'no-implicit-coercion': 2, + 'no-return-assign': 0, + 'no-sequences': 2, + yoda: 2, + + // Variables + 'no-restricted-globals': [2, 'fdescribe', 'fit'], + 'no-var': 1, + + // Codestyle + 'arrow-parens': [2, 'always'], + 'array-bracket-spacing': [2, 'never'], + 'brace-style': [2, '1tbs', { allowSingleLine: true }], + camelcase: [2, { properties: 'never' }], + 'comma-dangle': ['warn', 'always-multiline'], + 'comma-spacing': [2, { before: false, after: true }], + 'eol-last': 2, + 'func-call-spacing': [2, 'never'], + 'block-spacing': 2, + 'keyword-spacing': [2, { before: true, after: true }], + 'max-len': [ + 2, + { + code: 100, + ignoreUrls: true, + ignoreComments: false, + ignoreRegExpLiterals: true, + ignoreStrings: true, + ignoreTemplateLiterals: true, + ignorePattern: 'require', + }, + ], + 'no-lonely-if': 2, + 'no-mixed-spaces-and-tabs': 2, + 'no-multi-spaces': 2, + 'no-multiple-empty-lines': [2, { max: 1, maxBOF: 0, maxEOF: 0 }], + 'no-trailing-spaces': 2, + 'no-unneeded-ternary': 2, + 'no-nested-ternary': 2, + 'object-curly-spacing': [2, 'always'], + 'one-var-declaration-per-line': [2, 'initializations'], + 'one-var': [2, { let: 'never', const: 'never' }], + 'operator-linebreak': [2, 'before'], + 'padded-blocks': [2, 'never'], + 'quote-props': [2, 'as-needed', { numbers: true }], + quotes: [2, 'single', { avoidEscape: true }], + 'space-before-blocks': [2, 'always'], + 'space-before-function-paren': [ + 2, + { + asyncArrow: 'always', + anonymous: 'never', + named: 'never', + }, + ], + 'space-in-parens': 2, + 'no-console': [2, { allow: ['assert', 'error', 'warn'] }], + 'key-spacing': [2, { beforeColon: false, afterColon: true, mode: 'strict' }], + 'space-infix-ops': 2, + + // REACT + // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules + 'jsx-quotes': [2, 'prefer-double'], + 'react/jsx-boolean-value': 2, + 'react/display-name': 0, + 'react/jsx-closing-tag-location': 2, + 'react/jsx-equals-spacing': 2, + 'react/jsx-first-prop-new-line': [2, 'multiline'], + 'react/jsx-handler-names': 0, + 'react/jsx-indent': [2, 2], + 'react/jsx-indent-props': [2, 2], + 'react/jsx-key': 2, + 'react/jsx-no-bind': 1, + 'react/jsx-no-duplicate-props': 2, + 'react/jsx-no-literals': 0, + 'react/jsx-no-undef': 2, + 'react/jsx-sort-props': 0, + 'react/jsx-tag-spacing': [2, { beforeClosing: 'never', beforeSelfClosing: 'always' }], + 'react/jsx-uses-react': 2, + 'react/jsx-uses-vars': 2, + 'react/no-find-dom-node': 2, + 'react/no-multi-comp': 0, + 'react/no-set-state': 0, + 'react/react-in-jsx-scope': 2, + 'react/require-optimization': 0, + 'react/self-closing-comp': 2, + 'react/style-prop-object': 2, + 'react/void-dom-elements-no-children': 2, + + // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules + '@typescript-eslint/consistent-type-assertions': 2, + '@typescript-eslint/no-empty-interface': 2, + '@typescript-eslint/no-unused-vars': [ + 2, + { + args: 'after-used', + argsIgnorePattern: '^_', + ignoreRestSiblings: true, + vars: 'all', + varsIgnorePattern: '^_', + }, + ], + + // https://reactjs.org/docs/hooks-rules.html + 'react-hooks/rules-of-hooks': 2, // Checks rules of Hooks + 'react-hooks/exhaustive-deps': 1, // Checks effect dependencies + }, + overrides: [ + { + files: ['*.test.{ts,tsx}'], + env: { + jest: true, + }, + }, + { + files: ['*.js'], + rules: { + strict: 0, + }, + }, + ], +} diff --git a/.lintstagedrc b/.lintstagedrc index b82b2dea..009d7eb8 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,6 +1,7 @@ { "*.{js,ts,tsx}": [ "prettier --write", + "eslint --fix", "git add" ], "*.md": [ diff --git a/package.json b/package.json index 4f41c710..d837d0ac 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "scripts": { "bootstrap": "lerna bootstrap --no-ci", "build": "lerna run build --concurrency=1", - "lint": "lerna run lint", + "lint": "eslint --ext .js,.ts,.tsx .", "postinstall": "npm run bootstrap", "publish:next": "lerna publish --canary --preid dev --npm-tag next --no-git-tag-version", "unit:coverage": "npm run unit -- --coverage", @@ -15,9 +15,14 @@ "@types/enzyme": "3.1.15", "@types/jest": "25.1.3", "@types/react": "16.8.8", + "@typescript-eslint/eslint-plugin": "2.22.0", + "@typescript-eslint/parser": "2.22.0", "chalk": "2.4.1", "enzyme": "3.7.0", "enzyme-adapter-react-16": "1.7.0", + "eslint": "6.8.0", + "eslint-plugin-react": "7.19.0", + "eslint-plugin-react-hooks": "2.5.0", "gzip-size": "5.1.0", "husky": "3.0.5", "jest": "25.1.0", @@ -34,8 +39,6 @@ "rollup-plugin-terser": "4.0.4", "rollup-plugin-typescript2": "0.21.0", "ts-jest": "25.2.1", - "tslint": "5.11.0", - "tslint-react": "3.6.0", "typescript": "3.2.1" } } diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 18448254..00000000 --- a/tslint.json +++ /dev/null @@ -1,116 +0,0 @@ -{ - "defaultSeverity": "error", - "extends": ["tslint:recommended", "tslint-react"], - "rules": { - "trailing-comma": false, - "align": false, - "whitespace": false, - "semicolon": false, - "class-name": false, - "no-require-imports": false, - "no-var-requires": false, - "quotemark": false, - "object-curly-spacing": false, - "variable-name": [ - true, - "check-format", - "allow-leading-underscore", - "allow-trailing-underscore", - "allow-pascal-case" - ], - "curly": [true, "ignore-same-line"], - "object-literal-sort-keys": false, - "object-literal-key-quotes": false, - "adjacent-overload-signatures": true, - "ban-comma-operator": true, - "member-access": [true, "no-public"], - "member-ordering": [ - true, - { - "order": "fields-first" - } - ], - "no-import-side-effect": [ - true, - { - "ignore-module": "(\\.scss|\\.css|ignore-styles|@yandex-lego/i-ua)$" - } - ], - "no-internal-module": true, - "no-non-null-assertion": true, - "no-parameter-reassignment": true, - // "no-any": true, - "no-empty-interface": true, - "interface-over-type-literal": false, - "no-reference": true, - "typedef": [true, "parameter", "property-declaration"], - "typedef-whitespace": [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - }, - { - "call-signature": "onespace", - "index-signature": "onespace", - "parameter": "onespace", - "property-declaration": "onespace", - "variable-declaration": "onespace" - } - ], - "no-redundant-jsdoc": true, - "jsdoc-format": true, - "completed-docs": [ - true, - { - "classes": { - "visibilities": ["exported"] - }, - "functions": { - "visibilities": ["exported"] - }, - "interfaces": { - "visibilities": ["exported"] - }, - "methods": { - "privacies": ["protected"] - }, - "namespaces": true - } - ], - "await-promise": true, - "prefer-for-of": true, - "no-duplicate-super": true, - "no-duplicate-switch-case": true, - "no-eval": true, - "no-floating-promises": true, - "no-invalid-this": true, - "no-misused-new": true, - "strict-type-predicates": true, - "deprecation": true, - "max-classes-per-file": [true, 3], - "max-file-line-count": [true, 500], - "max-line-length": [true, 140], - "array-type": [true, "array-simple"], - "arrow-return-shorthand": true, - "callable-types": true, - "import-spacing": true, - "newline-before-return": true, - "no-reference-import": true, - "no-string-literal": false, - "no-unnecessary-callback-wrapper": true, - "no-unnecessary-initializer": true, - "no-unnecessary-qualifier": true, - "no-unused-expression": false, - "ordered-imports": false, - "type-literal-delimiter": false, - "only-arrow-functions": false, - "no-namespace": false, - "jsx-no-multiline-js": false, - "jsx-alignment": false, - "jsx-boolean-value": false - } -}