mirror of
https://github.com/elyby/eslint-plugin.git
synced 2025-05-31 14:11:45 +05:30
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
dfc70896ee | ||
|
ac7d5b9a51 | ||
|
2aa883804e | ||
|
25487e855d | ||
|
a6667fb421 | ||
|
4ba3f330a2 | ||
|
5d0ad26777 | ||
|
0061bfa295 | ||
|
d9b7bebd2b | ||
|
4c33698c28 | ||
|
31c531f151 |
27
.eslintrc.js
Normal file
27
.eslintrc.js
Normal file
@@ -0,0 +1,27 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'plugin:@elyby/base',
|
||||
'plugin:@elyby/typescript',
|
||||
],
|
||||
|
||||
env: {
|
||||
node: true,
|
||||
es6: true,
|
||||
},
|
||||
|
||||
settings: {
|
||||
react: {
|
||||
// Override these settings to avoid a wall of warnings
|
||||
version: 'latest',
|
||||
},
|
||||
},
|
||||
|
||||
overrides: [
|
||||
{
|
||||
files: ['src/configs/*.ts'],
|
||||
rules: {
|
||||
'quote-props': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
@@ -9,6 +9,7 @@ cache:
|
||||
|
||||
script:
|
||||
- yarn tsc
|
||||
- yarn lint
|
||||
- yarn test
|
||||
- yarn build
|
||||
|
||||
|
96
README.md
96
README.md
@@ -4,38 +4,85 @@ Set of ESLint rules used in development of Ely.by JS projects. Contains rules fo
|
||||
|
||||
## Installation
|
||||
|
||||
First of all install Ely.by ESLint plugin and `eslint` peer dependency via preferred package manager:
|
||||
First of all install Ely.by ESLint plugin and `eslint` peer dependency via NPM:
|
||||
|
||||
```sh
|
||||
# NPM users:
|
||||
npm install @elyby/eslint-plugin eslint --save-dev
|
||||
# Yarn users:
|
||||
```
|
||||
|
||||
Or via yarn:
|
||||
|
||||
```sh
|
||||
yarn add -D @elyby/eslint-plugin eslint
|
||||
```
|
||||
|
||||
Then add the following configuration to your `.eslintrc.js` file:
|
||||
## Configuration
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
extends: [
|
||||
'plugin:@elyby/config',
|
||||
],
|
||||
The configuration is divided into several parts. The `base` provides only pure js checks. To use it,
|
||||
simply add the `plugin:@elyby/base` configuration to the `extends` block:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@elyby/base"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
And that's it!
|
||||
### React
|
||||
|
||||
The configuration for React requires additional dependencies. Install them first:
|
||||
|
||||
```sh
|
||||
# NPM:
|
||||
npm install eslint-plugin-react eslint-plugin-react-hooks --save-dev
|
||||
# Yarn:
|
||||
yarn add -D eslint-plugin-react eslint-plugin-react-hooks
|
||||
```
|
||||
|
||||
Then add the `plugin:@elyby/react` configuration to the `extends` block:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@elyby/base",
|
||||
"plugin:@elyby/react"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### TypeScript
|
||||
|
||||
Configuration for TypeScript also requires additional libraries:
|
||||
|
||||
```sh
|
||||
# NPM:
|
||||
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin --save-dev
|
||||
# Yarn:
|
||||
yarn add -D @typescript-eslint/parser @typescript-eslint/eslint-plugin
|
||||
```
|
||||
|
||||
Then add the `plugin:@elyby/react` configuration to the `extends` block:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": [
|
||||
"plugin:@elyby/base",
|
||||
"plugin:@elyby/typescript"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You may still wish to override some of our rules, as well as the rest of our eslint configuration settings.
|
||||
For example, you can specify the preferred `env` for eslint:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
// ...rest of the configuration
|
||||
env: {
|
||||
browser: true,
|
||||
es6: true,
|
||||
},
|
||||
};
|
||||
```json
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Using our custom fixers
|
||||
@@ -43,13 +90,12 @@ module.exports = {
|
||||
First of all, you must install Ely.by's ESLint plugin as described in the [installation chapter](#installation).
|
||||
After that you can enable our custom rules with defining our plugin in `plugins` section:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
// ...rest of the configuration
|
||||
plugins: [
|
||||
'@elyby',
|
||||
],
|
||||
};
|
||||
```json
|
||||
{
|
||||
"plugins": [
|
||||
"@elyby"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
After that all custom rules will be available for use.
|
||||
|
21
package.json
21
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@elyby/eslint-plugin",
|
||||
"version": "0.1.0",
|
||||
"version": "0.3.0",
|
||||
"description": "Shareable ESLint config for the Ely.by's projects",
|
||||
"author": {
|
||||
"name": "erickskrauch",
|
||||
@@ -22,26 +22,29 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src -d lib --extensions .ts,.js",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^1.9.0",
|
||||
"@typescript-eslint/parser": "^1.9.0",
|
||||
"eslint-plugin-react": "^7.13.0"
|
||||
"test": "jest",
|
||||
"lint": "eslint \"{src,tests}/**/*.{js,ts}\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.4.4",
|
||||
"@babel/core": "^7.4.5",
|
||||
"@babel/preset-env": "^7.4.4",
|
||||
"@babel/preset-typescript": "^7.3.3",
|
||||
"@elyby/eslint-plugin": "^0.2.0",
|
||||
"@types/eslint": "^4.16.6",
|
||||
"@types/estree": "^0.0.39",
|
||||
"@types/estree": "^0.0.40",
|
||||
"@types/node": "^12.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "^1.9.1",
|
||||
"@typescript-eslint/parser": "^1.9.0",
|
||||
"eslint": "^5.16.0",
|
||||
"jest": "^24.8.0",
|
||||
"typescript": "^3.4.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": ">=5.16.0"
|
||||
"@typescript-eslint/eslint-plugin": "^2.11.0",
|
||||
"@typescript-eslint/parser": "^2.11.0",
|
||||
"eslint": "^6.0.0",
|
||||
"eslint-plugin-react": "^7.13.0",
|
||||
"eslint-plugin-react-hooks": "^1.6.0 | ^2.0.0"
|
||||
}
|
||||
}
|
||||
|
@@ -1,34 +1,22 @@
|
||||
import { Linter } from 'eslint';
|
||||
|
||||
const config: Linter.Config = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2018,
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
},
|
||||
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
|
||||
// @ts-ignore
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
'@elyby',
|
||||
],
|
||||
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:react/recommended',
|
||||
],
|
||||
|
||||
rules: {
|
||||
// possible errors (including eslint:recommended)
|
||||
'no-extra-parens': ['warn', 'all', {
|
||||
nestedBinaryExpressions: false,
|
||||
ignoreJSX: 'multi-line',
|
||||
}],
|
||||
'valid-jsdoc': ['warn', {
|
||||
requireParamDescription: false,
|
||||
requireReturn: false,
|
||||
@@ -77,6 +65,8 @@ const config: Linter.Config = {
|
||||
'no-octal': 'error',
|
||||
'no-proto': 'error',
|
||||
'no-redeclare': 'warn',
|
||||
'no-return-assign': 'error',
|
||||
'no-return-await': 'error',
|
||||
'no-script-url': 'error',
|
||||
'no-self-compare': 'error',
|
||||
'no-sequences': 'error',
|
||||
@@ -115,7 +105,7 @@ const config: Linter.Config = {
|
||||
'array-bracket-spacing': 'off', // disable because we want spaces on destructured arrays
|
||||
'block-spacing': ['error', 'never'],
|
||||
'brace-style': ['error', '1tbs', {
|
||||
allowSingleLine: true,
|
||||
allowSingleLine: false,
|
||||
}],
|
||||
'comma-spacing': 'error',
|
||||
'comma-style': 'error',
|
||||
@@ -124,6 +114,7 @@ const config: Linter.Config = {
|
||||
'consistent-this': ['error', 'that'],
|
||||
'camelcase': 'warn',
|
||||
'eol-last': 'warn',
|
||||
'func-call-spacing': 'error',
|
||||
'id-length': ['error', {
|
||||
min: 2,
|
||||
exceptions: ['x', 'y', 'i', '$'],
|
||||
@@ -131,7 +122,6 @@ const config: Linter.Config = {
|
||||
'indent': ['error', 4, {
|
||||
SwitchCase: 1,
|
||||
}],
|
||||
'jsx-quotes': 'error',
|
||||
'key-spacing': ['error', {
|
||||
mode: 'minimum',
|
||||
}],
|
||||
@@ -145,7 +135,6 @@ const config: Linter.Config = {
|
||||
'no-negated-condition': 'warn',
|
||||
'no-nested-ternary': 'error',
|
||||
'no-new-object': 'error',
|
||||
'no-spaced-func': 'error',
|
||||
'no-trailing-spaces': 'warn',
|
||||
'no-unneeded-ternary': 'warn',
|
||||
'one-var': ['error', 'never'],
|
||||
@@ -186,93 +175,7 @@ const config: Linter.Config = {
|
||||
'prefer-spread': 'warn',
|
||||
'prefer-template': 'warn',
|
||||
'require-yield': 'error',
|
||||
|
||||
// react
|
||||
'react/display-name': 'warn',
|
||||
'react/forbid-prop-types': 'warn',
|
||||
'react/jsx-boolean-value': 'warn',
|
||||
'react/jsx-closing-bracket-location': 'off',
|
||||
'react/jsx-curly-spacing': 'warn',
|
||||
'react/jsx-handler-names': ['warn', {
|
||||
eventHandlerPrefix: 'on',
|
||||
eventHandlerPropPrefix: 'on',
|
||||
}],
|
||||
'react/jsx-indent-props': 'warn',
|
||||
'react/jsx-key': 'warn',
|
||||
'react/jsx-max-props-per-line': 'off',
|
||||
'react/jsx-no-bind': ['error', {
|
||||
allowArrowFunctions: true,
|
||||
}],
|
||||
'react/jsx-no-duplicate-props': 'warn',
|
||||
'react/jsx-no-literals': 'off',
|
||||
'react/jsx-no-undef': 'warn',
|
||||
'react/jsx-pascal-case': 'warn',
|
||||
'react/jsx-uses-react': 'warn',
|
||||
'react/jsx-uses-vars': 'warn',
|
||||
'react/jsx-no-comment-textnodes': 'warn',
|
||||
'react/jsx-tag-spacing': ['warn', {
|
||||
beforeClosing: 'never',
|
||||
}],
|
||||
'react/jsx-wrap-multilines': 'warn',
|
||||
'react/no-deprecated': 'warn',
|
||||
'react/no-did-mount-set-state': 'warn',
|
||||
'react/no-did-update-set-state': 'warn',
|
||||
'react/no-direct-mutation-state': 'warn',
|
||||
'react/require-render-return': 'warn',
|
||||
'react/no-is-mounted': 'warn',
|
||||
'react/no-multi-comp': 'warn',
|
||||
'react/no-string-refs': 'warn',
|
||||
'react/no-unknown-property': 'warn',
|
||||
'react/prefer-es6-class': 'warn',
|
||||
'react/react-in-jsx-scope': 'off',
|
||||
'react/self-closing-comp': 'warn',
|
||||
'react/sort-comp': ['warn', {
|
||||
order: ['lifecycle', 'render', 'everything-else'],
|
||||
}],
|
||||
|
||||
// Ely.by's custom rules
|
||||
'@elyby/jsx-closing-bracket-location': 'warn',
|
||||
},
|
||||
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
rules: {
|
||||
'camelcase': 'off',
|
||||
'indent': 'off',
|
||||
'no-array-constructor': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
|
||||
'react/prop-types': 'off',
|
||||
|
||||
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
||||
'@typescript-eslint/array-type': ['error', 'generic'],
|
||||
'@typescript-eslint/ban-types': 'error',
|
||||
'@typescript-eslint/camelcase': 'error',
|
||||
'@typescript-eslint/class-name-casing': 'error',
|
||||
'@typescript-eslint/explicit-member-accessibility': 'error',
|
||||
'@typescript-eslint/indent': 'error',
|
||||
'@typescript-eslint/interface-name-prefix': 'error',
|
||||
'@typescript-eslint/member-delimiter-style': 'error',
|
||||
'@typescript-eslint/no-angle-bracket-type-assertion': 'error',
|
||||
'@typescript-eslint/no-array-constructor': 'error',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-inferrable-types': 'error',
|
||||
'@typescript-eslint/no-misused-new': 'error',
|
||||
'@typescript-eslint/no-namespace': 'error',
|
||||
'@typescript-eslint/no-object-literal-type-assertion': 'error',
|
||||
'@typescript-eslint/no-parameter-properties': 'error',
|
||||
'@typescript-eslint/no-triple-slash-reference': 'error',
|
||||
'@typescript-eslint/no-unused-vars': 'warn',
|
||||
'@typescript-eslint/no-use-before-define': 'error',
|
||||
'@typescript-eslint/no-var-requires': 'error',
|
||||
'@typescript-eslint/prefer-for-of': 'warn',
|
||||
'@typescript-eslint/prefer-interface': 'error',
|
||||
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
||||
'@typescript-eslint/type-annotation-spacing': 'error',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default config;
|
89
src/configs/react.ts
Normal file
89
src/configs/react.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Linter } from 'eslint';
|
||||
|
||||
const config: Linter.Config = {
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
},
|
||||
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
|
||||
// @ts-ignore
|
||||
plugins: [
|
||||
'react-hooks',
|
||||
'@elyby',
|
||||
],
|
||||
|
||||
extends: [
|
||||
'plugin:react/recommended',
|
||||
],
|
||||
|
||||
rules: {
|
||||
// stylistic
|
||||
'jsx-quotes': 'error',
|
||||
|
||||
// react
|
||||
'react/display-name': 'warn',
|
||||
'react/forbid-prop-types': 'warn',
|
||||
'react/jsx-boolean-value': 'warn',
|
||||
'react/jsx-closing-bracket-location': 'off',
|
||||
'react/jsx-curly-spacing': 'warn',
|
||||
'react/jsx-fragments': ['error', 'syntax'],
|
||||
'react/jsx-handler-names': ['warn', {
|
||||
eventHandlerPrefix: 'on',
|
||||
eventHandlerPropPrefix: 'on',
|
||||
}],
|
||||
'react/jsx-indent-props': 'warn',
|
||||
'react/jsx-key': 'warn',
|
||||
'react/jsx-one-expression-per-line': ['warn', {
|
||||
allow: 'literal',
|
||||
}],
|
||||
'react/jsx-max-props-per-line': 'off',
|
||||
'react/jsx-no-bind': ['error', {
|
||||
allowArrowFunctions: true,
|
||||
}],
|
||||
'react/jsx-no-duplicate-props': 'warn',
|
||||
'react/jsx-no-literals': 'off',
|
||||
'react/jsx-no-undef': 'warn',
|
||||
'react/jsx-pascal-case': 'warn',
|
||||
'react/jsx-props-no-multi-spaces': 'warn',
|
||||
'react/jsx-uses-react': 'warn',
|
||||
'react/jsx-uses-vars': 'warn',
|
||||
'react/jsx-no-comment-textnodes': 'warn',
|
||||
'react/jsx-tag-spacing': ['warn', {
|
||||
beforeClosing: 'never',
|
||||
}],
|
||||
'react/jsx-wrap-multilines': 'warn',
|
||||
'react/no-deprecated': 'warn',
|
||||
'react/no-did-mount-set-state': 'warn',
|
||||
'react/no-did-update-set-state': 'warn',
|
||||
'react/no-direct-mutation-state': 'error',
|
||||
'react/no-is-mounted': 'warn',
|
||||
'react/no-multi-comp': 'warn',
|
||||
'react/no-string-refs': 'warn',
|
||||
'react/no-this-in-sfc': 'error',
|
||||
'react/no-unknown-property': 'warn',
|
||||
'react/no-will-update-set-state': 'error',
|
||||
'react/prefer-es6-class': 'warn',
|
||||
'react/react-in-jsxscope': 'off',
|
||||
'react/require-render-return': 'warn',
|
||||
'react/self-closing-comp': 'warn',
|
||||
'react/sort-comp': ['warn', {
|
||||
order: ['lifecycle', 'render', 'everything-else'],
|
||||
}],
|
||||
|
||||
// React hooks
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/exhaustive-deps': 'warn',
|
||||
|
||||
// Ely.by's custom rules
|
||||
'@elyby/jsx-closing-bracket-location': 'warn',
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
66
src/configs/typescript.ts
Normal file
66
src/configs/typescript.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { Linter } from 'eslint';
|
||||
|
||||
const config: Linter.Config = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
|
||||
// @ts-ignore
|
||||
plugins: [
|
||||
'@typescript-eslint/eslint-plugin',
|
||||
],
|
||||
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
rules: {
|
||||
'camelcase': 'off',
|
||||
'func-call-spacing': 'off',
|
||||
'indent': 'off',
|
||||
'no-array-constructor': 'off',
|
||||
'no-extra-parens': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
'valid-jsdoc': 'off',
|
||||
'semi': 'off',
|
||||
|
||||
'react/prop-types': 'off',
|
||||
|
||||
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
||||
'@typescript-eslint/array-type': ['error', {
|
||||
default: 'generic',
|
||||
readonly: 'generic',
|
||||
}],
|
||||
'@typescript-eslint/camelcase': 'error',
|
||||
'@typescript-eslint/class-name-casing': 'error',
|
||||
'@typescript-eslint/consistent-type-assertions': 'error',
|
||||
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
||||
'@typescript-eslint/explicit-member-accessibility': 'error',
|
||||
'@typescript-eslint/func-call-spacing': 'error',
|
||||
'@typescript-eslint/indent': 'error',
|
||||
'@typescript-eslint/interface-name-prefix': ['error', 'never'],
|
||||
'@typescript-eslint/member-delimiter-style': 'error',
|
||||
'@typescript-eslint/no-array-constructor': 'error',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-extra-parens': ['warn', 'all', {
|
||||
nestedBinaryExpressions: false,
|
||||
ignoreJSX: 'multi-line',
|
||||
}],
|
||||
'@typescript-eslint/no-inferrable-types': ['error', {
|
||||
ignoreParameters: true,
|
||||
}],
|
||||
'@typescript-eslint/no-misused-new': 'error',
|
||||
'@typescript-eslint/no-namespace': 'error',
|
||||
'@typescript-eslint/no-parameter-properties': 'error',
|
||||
'@typescript-eslint/no-unused-vars': 'error',
|
||||
'@typescript-eslint/no-use-before-define': 'error',
|
||||
'@typescript-eslint/no-useless-constructor': 'warn',
|
||||
'@typescript-eslint/no-var-requires': 'error',
|
||||
'@typescript-eslint/prefer-for-of': 'warn',
|
||||
'@typescript-eslint/prefer-namespace-keyword': 'error',
|
||||
'@typescript-eslint/semi': 'error',
|
||||
'@typescript-eslint/triple-slash-reference': 'error',
|
||||
'@typescript-eslint/type-annotation-spacing': 'error',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default config;
|
@@ -1,8 +1,12 @@
|
||||
import allRules from './rules';
|
||||
import config from './configs/all';
|
||||
import baseConfig from './configs/base';
|
||||
import reactConfig from './configs/react';
|
||||
import typescriptConfig from './configs/typescript';
|
||||
|
||||
export const rules = allRules;
|
||||
|
||||
export const configs = {
|
||||
config,
|
||||
base: baseConfig,
|
||||
react: reactConfig,
|
||||
typescript: typescriptConfig,
|
||||
};
|
||||
|
Reference in New Issue
Block a user