Skip to content

Commit

Permalink
feat(eslint-plugin-tinkoff): add eslint-plugin-tinkoff source code to…
Browse files Browse the repository at this point in the history
… packages (#43)

* feat(eslint-plugin-tinkoff): add eslint-plugin-tinkoff source code to packages

* feat(eslint-plugin-tinkoff): move eslint-plugin-tinkoff from packages, review fixes

Co-authored-by: o.drapeza <o.drapeza@tinkoff.ru>
  • Loading branch information
SuperOleg39 and o.drapeza committed Jun 15, 2020
1 parent 8196571 commit 2fe98e9
Show file tree
Hide file tree
Showing 44 changed files with 7,034 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .eslintignore
Expand Up @@ -3,3 +3,5 @@ packages/linters/tslint/rules
packages/linters/tslint/src
node_modules
dist

__temp_packages__/
2 changes: 1 addition & 1 deletion .lintstagedrc.js
@@ -1,5 +1,5 @@
module.exports = {
'packages/**/*.{ts,js}': ['eslint --fix'],
'packages/**/**/*.{ts,js}': ['eslint --fix'],
'**/README.md': [
files => files.map(file => `markdown-toc -i ${file}`), // single file per command
'prettier --write',
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
@@ -1,3 +1,5 @@
*.lint
*.fix
package-lock.json

__temp_packages__/
15 changes: 15 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/.eslintignore
@@ -0,0 +1,15 @@
test/__fixtures__/*
test/__snapshots__/*

# from .gitignore
node_modules/

# IDE
.DS_Store
.vscode
.idea

# Compiled sources
lib

.tmp
17 changes: 17 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/.eslintrc
@@ -0,0 +1,17 @@
{
"root": true,
"extends": [
"plugin:tinkoff/lib"
],
"overrides": [
{
"files": [
"*.test.ts",
"*.spec.ts"
],
"rules": {
"max-nested-callbacks": ["error", 10]
}
}
]
}
21 changes: 21 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/.gitignore
@@ -0,0 +1,21 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Dependency directories
node_modules/

# IDE
.DS_Store
.vscode
.idea

# Compiled sources
lib

.tmp

debug-path
9 changes: 9 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/.prettierrc
@@ -0,0 +1,9 @@
{
"parser": "typescript",
"singleQuote": true,
"trailingComma": "es5",
"proseWrap": "never",
"arrowParens": "always",
"tabWidth": 2,
"printWidth": 100
}
87 changes: 87 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/README.md
@@ -0,0 +1,87 @@
# eslint-config-tinkoff

ESlint plugin includes Tinkoff rules and plugins, for JS and TS codebase.

## Usage

Install from npm

```bash
npm i --save-dev eslint-plugin-tinkoff
```

Plugin automatically install `eslint@7` and `prettier@2` packages.

Then, need to include necessary configurations sets to `.eslintrc`.
Wee need to choose base configuration, and any necessary additional configs.

### Base configurations

#### For application
```bash
{
"extends": ["plugin:tinkoff/app"]
}
```

#### For library
```bash
{
"extends": ["plugin:tinkoff/lib"]
}
```

### Additional configurations

#### For React application
```bash
{
"extends": ["plugin:tinkoff/app", "plugin:tinkoff/react"]
}
```

#### For Angular application
```bash
{
"extends": ["plugin:tinkoff/app", "plugin:tinkoff/angular"]
}
```

#### If we use Jest
```bash
{
"extends": ["plugin:tinkoff/app", "plugin:tinkoff/jest"]
}
```

## Configurations overview

Main configurations sets contains common rules

* `tinkoff/app` - common rules and specific rules for applications
* `tinkoff/lib` - common rules and specific rules for libraries

Additional configurations sets. This configs **not** contain common eslint rules, and must be included with main configurations

* `tinkoff/react` - rules for lint React code
* `tinkoff/angular` - rules for lint Angular code
* `tinkoff/jest` - rules for lint Jest test suits

## Internal used plugins

`tinkoff/app` and `tinkoff/lib` include:

* `eslint-config-airbnb` - common and popular configuration
* `eslint-plugin-eslint-comments` - validate `eslint` comments
* `eslint-plugin-import` - validate proper imports
* `eslint-plugin-promise` - enforce best practices for promises
* `eslint-plugin-jest` - validate jest tests
* `@typescript-eslint/eslint-plugin` - lint TypeScript files, adopt many eslint rules to TS code, and provide specific TS rules
* `eslint-plugin-prettier` - disable code formatting using eslint tools and transfers all the logic to a prettier, and report differences as eslint issues

`tinkoff/react` include:

* `eslint-plugin-react` - common react lint rules
* `eslint-plugin-react-hooks` - lint rules for react hooks

<!-- ## Internal rules -->
6 changes: 6 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/jest.config.js
@@ -0,0 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
cacheDirectory: '<rootDir>/.tmp/jest',
timers: 'fake',
};
70 changes: 70 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/package.json
@@ -0,0 +1,70 @@
{
"name": "eslint-plugin-tinkoff",
"version": "0.5.0",
"description": "Tinkoff ESLint configs to rule them all",
"keywords": [
"eslint",
"eslintconfig",
"eslint-config"
],
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest --clearCache && jest",
"test:watch": "jest --clearCache && jest --watch",
"lint": "eslint --ext .jsx,.js,.ts,.tsx --ignore-path .eslintignore .",
"lint:fix": "npm run lint -- --fix",
"prepublish": "npm run build",
"prebuild": "rimraf lib"
},
"main": "./lib/index",
"bugs": {
"url": "https://github.com/TinkoffCreditSystems/linters/issues"
},
"files": [
"lib",
"src"
],
"homepage": "https://github.com/TinkoffCreditSystems/linters",
"repository": {
"type": "git",
"url": "https://github.com/TinkoffCreditSystems/linters.git"
},
"dependencies": {
"@tinkoff/utils": "^2.1.2",
"@typescript-eslint/eslint-plugin": "^3.0.0-alpha.27",
"@typescript-eslint/parser": "^3.0.0-alpha.27",
"babel-eslint": "^10.1.0",
"eslint": "^7.0.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-import-resolver-webpack": "^0.12.1",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.11.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^4.0.1",
"eslint-plugin-sort-class-members": "^1.7.0",
"prettier": "^2.0.5"
},
"devDependencies": {
"@types/eslint": "^6.8.0",
"@types/jest": "^25.2.3",
"@types/node": "^14.0.1",
"eslint-plugin-self-dir": "^1.3.1",
"eslint-plugin-tinkoff": "file:.",
"jest": "^26.0.1",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"ts-jest": "^26.0.0",
"typescript": "^3.9.2"
},
"engines": {
"node": "^10.12.0 || >=12.0.0"
}
}
14 changes: 14 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/src/config/angular.ts
@@ -0,0 +1,14 @@
export const angularConfig = {
overrides: [
{
files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
rules: {
'import/no-webpack-loader-syntax': 'off',
'sort-class-members/sort-class-members': 'off',
'no-param-reassign': 'off',
'@typescript-eslint/no-useless-constructor': 'off',
'@typescript-eslint/no-extraneous-class': 'off', // incorrect working with constructor parameters
},
},
],
};
7 changes: 7 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/src/config/app.ts
@@ -0,0 +1,7 @@
export const appConfig = {
extends: ['plugin:tinkoff/main'],

plugins: [],

rules: {},
};
3 changes: 3 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/src/config/jest.ts
@@ -0,0 +1,3 @@
export const jestConfig = {
extends: ['plugin:jest/recommended'],
};
10 changes: 10 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/src/config/lib.ts
@@ -0,0 +1,10 @@
export const libConfig = {
extends: ['plugin:tinkoff/main'],

plugins: [],

rules: {
'import/no-dynamic-require': 'off',
'@typescript-eslint/no-var-requires': 'off',
},
};
19 changes: 19 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/src/config/main.ts
@@ -0,0 +1,19 @@
export const mainConfig = {
extends: [
'eslint-config-airbnb-base',
'plugin:eslint-comments/recommended',
'plugin:tinkoff/base',
'plugin:tinkoff/import',
'plugin:tinkoff/promise',
'plugin:tinkoff/testFiles',
'plugin:tinkoff/typescript',
'plugin:tinkoff/prettier',
],

env: {
browser: true,
node: true,
},

plugins: ['import', 'sort-class-members'],
};
73 changes: 73 additions & 0 deletions __temp_packages__/eslint-plugin-tinkoff/src/config/plugins/base.ts
@@ -0,0 +1,73 @@
export const baseConfig = {
parser: 'babel-eslint',

plugins: ['babel'],

settings: {
'import/parser': 'babel-eslint',
},

parserOptions: {
ecmaFeatures: {
legacyDecorators: true,
},
},

rules: {
...require('../rules/sort-class-members'),
'no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
},
],
'no-use-before-define': [
'error',
{
functions: false,
classes: false,
variables: true,
},
],
'func-name-matching': 'warn',
'global-require': 'warn',
'class-methods-use-this': 'warn',
'no-continue': 'off',
'no-restricted-syntax': 'warn',
'default-case': 'warn',
'no-plusplus': ['warn', { allowForLoopAfterthoughts: true }],
'consistent-return': 'warn',
'vars-on-top': 'warn',
'no-var': 'warn',
camelcase: [
'warn',
{
allow: ['^UNSAFE_'],
ignoreDestructuring: false,
properties: 'never',
},
],
'func-style': [
'error',
'declaration',
{
allowArrowFunctions: true,
},
],
'max-depth': ['warn', 4],
'max-params': ['warn', 3],
'max-classes-per-file': ['error', 4],
complexity: ['error', 25],
'max-statements': ['error', 25],
'no-empty': ['error', { allowEmptyCatch: true }],
'no-underscore-dangle': 'off',
'no-return-assign': ['error', 'except-parens'],
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
'spaced-comment': ['error', 'always', { exceptions: ['*'] }],
'max-nested-callbacks': ['error', 4],
'no-bitwise': 'warn',
'no-useless-escape': 'warn',
'no-await-in-loop': 'off',
},
};

0 comments on commit 2fe98e9

Please sign in to comment.