5 Commits
0.1.0 ... 0.2.0

Author SHA1 Message Date
ErickSkrauch
5d0ad26777 Prepare 0.2.0 release 2019-05-28 23:32:15 +03:00
ErickSkrauch
0061bfa295 Update README 2019-05-28 23:32:01 +03:00
ErickSkrauch
d9b7bebd2b Split configs over 3 separate configurations and move all eslint plugins dependencies to the peerDependencies 2019-05-28 01:34:24 +03:00
ErickSkrauch
4c33698c28 Adjust rules configuration 2019-05-27 01:15:07 +03:00
ErickSkrauch
31c531f151 Use own package to lint code 2019-05-24 19:04:47 +03:00
9 changed files with 313 additions and 140 deletions

26
.eslintrc.js Normal file
View File

@@ -0,0 +1,26 @@
module.exports = {
extends: [
'plugin:@elyby/config',
],
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',
},
},
],
};

View File

@@ -9,6 +9,7 @@ cache:
script:
- yarn tsc
- yarn lint
- yarn test
- yarn build

View File

@@ -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/config"
]
}
```
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/config",
"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/config",
"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.

View File

@@ -1,6 +1,6 @@
{
"name": "@elyby/eslint-plugin",
"version": "0.1.0",
"version": "0.2.0",
"description": "Shareable ESLint config for the Ely.by's projects",
"author": {
"name": "erickskrauch",
@@ -22,18 +22,15 @@
},
"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.1.0",
"@types/eslint": "^4.16.6",
"@types/estree": "^0.0.39",
"@types/node": "^12.0.2",
@@ -42,6 +39,10 @@
"typescript": "^3.4.5"
},
"peerDependencies": {
"eslint": ">=5.16.0"
"@typescript-eslint/eslint-plugin": "^1.9.1-alpha.12",
"@typescript-eslint/parser": "^1.9.0",
"eslint": ">=5.16.0",
"eslint-plugin-react": "^7.13.0",
"eslint-plugin-react-hooks": "^1.6.0"
}
}

View File

@@ -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
View 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;

62
src/configs/typescript.ts Normal file
View File

@@ -0,0 +1,62 @@
import { Linter } from 'eslint';
const config: Linter.Config = {
parser: '@typescript-eslint/parser',
// @ts-ignore
plugins: [
'@typescript-eslint',
],
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', 'generic'],
'@typescript-eslint/camelcase': 'error',
'@typescript-eslint/class-name-casing': 'error',
'@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-angle-bracket-type-assertion': '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',
'@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': '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-interface': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/semi': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
},
},
],
};
export default config;

View File

@@ -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,
};

View File

@@ -666,6 +666,15 @@
exec-sh "^0.3.2"
minimist "^1.2.0"
"@elyby/eslint-plugin@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@elyby/eslint-plugin/-/eslint-plugin-0.1.0.tgz#02e1860b8d176dca8dac982e2d3b1837dd6ad293"
integrity sha512-P/mv8wj6E3YbdR7N+f/pPWDZlKIHvVHH7ruOjyRMuGElMWnXycFv3tqA0xJgPE1gTCaa8NYg6jbk6Q8l/d/7xw==
dependencies:
"@typescript-eslint/eslint-plugin" "^1.9.0"
"@typescript-eslint/parser" "^1.9.0"
eslint-plugin-react "^7.13.0"
"@jest/console@^24.7.1":
version "24.7.1"
resolved "https://registry.yarnpkg.com/@jest/console/-/console-24.7.1.tgz#32a9e42535a97aedfe037e725bd67e954b459545"
@@ -911,6 +920,17 @@
requireindex "^1.2.0"
tsutils "^3.7.0"
"@typescript-eslint/eslint-plugin@^1.9.1-alpha.12":
version "1.9.1-alpha.12"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.9.1-alpha.12.tgz#21ae7ac5f7ebf2e22e60a5430d5c008688ac1b00"
integrity sha512-TiFMF/vaQL0L75csNmpY4UwE2AeyBDIIVhB5Dzz7TUYpfy5dHCbu8zwwNB8oN/Z7IHpyKHzbLCgZ4hQ1Cxe5jQ==
dependencies:
"@typescript-eslint/experimental-utils" "1.9.1-alpha.12+cca1714"
eslint-utils "^1.3.1"
functional-red-black-tree "^1.0.1"
regexpp "^2.0.1"
tsutils "^3.7.0"
"@typescript-eslint/experimental-utils@1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-1.9.0.tgz#a92777d0c92d7bc8627abd7cdb06cdbcaf2b39e8"
@@ -918,6 +938,14 @@
dependencies:
"@typescript-eslint/typescript-estree" "1.9.0"
"@typescript-eslint/experimental-utils@1.9.1-alpha.12+cca1714":
version "1.9.1-alpha.12"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-1.9.1-alpha.12.tgz#578d8a3a0e43f2657285699f74066bd9665fac2e"
integrity sha512-zOTD+VQV8JCSm8XDHkASdulglAtanlNyqDHx76n79Q4AFU+KRgKj6e4mUSoBU4/BhnLilC5oZ9f+nmJoXJhgbQ==
dependencies:
"@typescript-eslint/typescript-estree" "1.9.1-alpha.12+cca1714"
eslint-scope "^4.0.0"
"@typescript-eslint/parser@1.9.0", "@typescript-eslint/parser@^1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-1.9.0.tgz#5796cbfcb9a3a5757aeb671c1ac88d7a94a95962"
@@ -936,6 +964,14 @@
lodash.unescape "4.0.1"
semver "5.5.0"
"@typescript-eslint/typescript-estree@1.9.1-alpha.12+cca1714":
version "1.9.1-alpha.12"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.9.1-alpha.12.tgz#c801bd49066ec96cf85720be7d5c22dc444e27a3"
integrity sha512-Kpdlx0nIZ/s8O2NId9zRkY2V+Vie9/3AkXru35cBEk7G5EPhuzLFqiUy0wWZXNBjCVrHeMWivd8a5pomzBR7kg==
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"
abab@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.0.tgz#aba0ab4c5eee2d4c79d3487d85450fb2376ebb0f"
@@ -1677,6 +1713,11 @@ escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"
eslint-plugin-react-hooks@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.6.0.tgz#348efcda8fb426399ac7b8609607c7b4025a6f5f"
integrity sha512-lHBVRIaz5ibnIgNG07JNiAuBUeKhEf8l4etNx5vfAEwqQ5tcuK3jV9yjmopPgQDagQb7HwIuQVsE3IVcGrRnag==
eslint-plugin-react@^7.13.0:
version "7.13.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.13.0.tgz#bc13fd7101de67996ea51b33873cd9dc2b7e5758"