Skip to content

Commit

Permalink
Update dependencies and enable new rules to support TypeScript 4 and …
Browse files Browse the repository at this point in the history
…ESLint 7 (#10)
  • Loading branch information
iansu authored Nov 22, 2020
1 parent 95a4251 commit 7465722
Show file tree
Hide file tree
Showing 11 changed files with 1,390 additions and 641 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.6.0 (November 22, 2020)

- Update dependencies to support TypeScript 4, ESLint 7 and Prettier 2
- Add `config-backend-next` and `config-frontend-next` with rules being considered for a future release
- Enable `@typescript-eslint/no-unused-before-define` rule as error in TypeScript files
- Enable `@typescript-eslint/prefer-optional-chain` rule as warning
- Enable `unicorn/no-reduce` rule as warning
- Enable `unicorn/prefer-optional-catch-binding` rule as warning
- Disable `@typescript-eslint/explicit-module-boundary-types` rule in test files
- Disable `@typescript-eslint/no-empty-function` rule in test files

## 0.5.2 (January 9, 2020)

- Add `varsIgnorePattern` to `@typescript-eslint/no-unused-vars` rule
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Official Neo Financial ESLint configuration

## Available Configs

This package includes 4 different ESLint configs:

- `config-backend`
- `config-frontend`
- `config-backend-next`
- `config-frontend-next`

The `next` versions include some rules that are being considered for inclusion in future versions of the base config. The `next` configs also require you to specify the `project` setting in `parserOptions` for TypeScript projects. The will make ESLint run slower in TypeScript projects.

## Installation

### Install Package
Expand Down Expand Up @@ -30,6 +41,19 @@ Add `.eslintrc` to project root

_Use `eslint-config-neo/config-frontend` for frontend projects_

### Optional: Configure `parserOptions` with `next` configs

If you're using one of the `next` configs you must set the `project` option to include _all_ of your `tsconfig.json` files:

```json
{
"extends": "eslint-config-neo/config-backend",
"parserOptions": {
"project": ["tsconfig.json", "test/tsconfig.json"]
}
}
```

### Make Prettier Config File

Add `.prettierrc` to project root
Expand Down Expand Up @@ -73,7 +97,7 @@ Add the engines field to `package.json`

```json
"engines": {
"node": "^10.10.0"
"node": "^12.0.0"
}
```

Expand Down
10 changes: 10 additions & 0 deletions config-backend-next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: ['./config-base-next.js'],
env: {
node: true,
mongo: true,
},
rules: {
'node/no-unpublished-require': 'warn',
},
};
8 changes: 4 additions & 4 deletions config-backend.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
extends: ['./index.js'],
extends: ['./config-base.js'],
env: {
node: true,
mongo: true
mongo: true,
},
rules: {
'node/no-unpublished-require': 'warn'
}
'node/no-unpublished-require': 'warn',
},
};
30 changes: 30 additions & 0 deletions config-base-next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
extends: ['./config-base.js'],
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
'@typescript-eslint/promise-function-async': [
'error',
{
allowedPromiseNames: ['Thenable'],
checkArrowFunctions: true,
checkFunctionDeclarations: true,
checkFunctionExpressions: true,
checkMethodDeclarations: true,
},
],
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/return-await': 'error',

'unicorn/no-null': 'warn',
},
},
{
files: ['**/test/**/*'],
rules: {
'unicorn/no-null': 'off',
},
},
],
};
140 changes: 140 additions & 0 deletions config-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:node/recommended',
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:unicorn/recommended',
'plugin:promise/recommended',
'prettier',
],
plugins: ['node', 'jest', 'unicorn', 'promise', 'import'],
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module',
},
env: {
es6: true,
'jest/globals': true,
},
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module',
warnOnUnsupportedTypeScriptVersion: true,
},
// if adding a typescript-eslint version of an existing ESLint rule make sure to disable the ESLint rule here
rules: {
// 'tsc' already handles this: https://github.com/typescript-eslint/typescript-eslint/issues/291
'no-dupe-class-members': 'off',
// 'tsc' already handles this: https://github.com/typescript-eslint/typescript-eslint/issues/477
'no-undef': 'off',
'no-use-before-define': 'off',
'no-array-constructor': 'off',

'@typescript-eslint/consistent-type-assertions': 'warn',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/no-array-constructor': 'warn',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_+', varsIgnorePattern: '^_+' }],
'@typescript-eslint/no-use-before-define': ['error', { typedefs: false, enums: false }],
'@typescript-eslint/prefer-optional-chain': 'warn',
},
},
{
files: ['**/test/**/*'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'unicorn/no-null': 'off',
},
},
],
rules: {
eqeqeq: ['error', 'smart'],
'func-names': ['warn', 'as-needed'],
'no-bitwise': 'warn',
'no-console': 'warn',
'no-duplicate-imports': 'error',
'no-eval': 'error',
'no-extra-bind': 'warn',
'no-lonely-if': 'warn',
'no-loop-func': 'error',
'no-mixed-requires': 'error',
'no-new-require': 'error',
'no-param-reassign': 'error',
'no-process-exit': 'off',
'no-return-await': 'error',
'no-throw-literal': 'error',
'no-undef-init': 'error',
'no-unneeded-ternary': 'warn',
'no-use-before-define': ['error', 'nofunc'],
'no-useless-concat': 'warn',
'no-var': 'warn',
'padding-line-between-statements': [
'warn',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: '*', next: 'throw' },
{ blankLine: 'always', prev: '*', next: 'block-like' },
{ blankLine: 'always', prev: 'block-like', next: '*' },
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{ blankLine: 'always', prev: '*', next: ['const', 'let', 'var'] },
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] },
],
'prefer-const': 'warn',
'prefer-template': 'warn',
// disable atomic updates rule until this issue is resolved: https://github.com/eslint/eslint/issues/11899
'require-atomic-updates': 'off',
'require-await': 'off',

'node/exports-style': 'error',
'node/no-unpublished-import': 'off',
'node/no-missing-import': 'off',
'node/no-unsupported-features/es-syntax': [
'warn',
{
ignores: ['modules'],
},
],

'unicorn/catch-error-name': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-abusive-eslint-disable': 'off',
'unicorn/no-fn-reference-in-iterator': 'off',
'unicorn/no-nested-ternary': 'warn',
'unicorn/no-process-exit': 'off',
'unicorn/no-reduce': 'warn',
'unicorn/prefer-optional-catch-binding': 'warn',
'unicorn/prefer-ternary': 'off',
'unicorn/prevent-abbreviations': 'off',

'import/no-restricted-paths': ['error', { zones: [{ target: './src', from: './test' }] }],
'import/no-absolute-path': 'error',
'import/no-useless-path-segments': 'error',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/test/**/*', '**/webpack.*.js'],
optionalDependencies: false,
peerDependencies: false,
},
],
'import/order': [
'warn',
{
groups: [
['builtin', 'external'],
['sibling', 'parent'],
],
'newlines-between': 'always-and-inside-groups',
},
],
'import/newline-after-import': 'warn',
},
};
20 changes: 20 additions & 0 deletions config-frontend-next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
extends: ['./config-base-next.js', 'plugin:react/recommended'],
plugins: ['node', 'react', 'react-hooks'],
env: {
browser: true,
},
settings: {
react: {
version: 'detect',
},
},
rules: {
'node/no-unpublished-require': 'off',

'react/prop-types': 'off',

'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
},
};
12 changes: 6 additions & 6 deletions config-frontend.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module.exports = {
extends: ['./index.js', 'plugin:react/recommended'],
extends: ['./config-base.js', 'plugin:react/recommended'],
plugins: ['node', 'react', 'react-hooks'],
env: {
browser: true
browser: true,
},
settings: {
react: {
version: 'detect'
}
version: 'detect',
},
},
rules: {
'node/no-unpublished-require': 'off',

'react/prop-types': 'off',

'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn'
}
'react-hooks/exhaustive-deps': 'warn',
},
};
Loading

0 comments on commit 7465722

Please sign in to comment.