Skip to content

Commit

Permalink
feat: create @typescript-eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jan 24, 2020
1 parent aace8f0 commit d8c0e31
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 19 deletions.
95 changes: 95 additions & 0 deletions @typescript-eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: { sourceType: 'module' },
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier/@typescript-eslint'
],
rules: {
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
// eslint-disable-next-line local/prefer-valid-rules
'@typescript-eslint/camelcase': ['error', { allow: ['child_process'] }],
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/default-param-last': 'error',
'@typescript-eslint/explicit-member-accessibility': 'error',
// eslint-disable-next-line local/prefer-valid-rules
'@typescript-eslint/generic-type-naming': [
'error',
/^T([A-Z][a-zA-Z]+)$|^[A-Z]$/u.toString().slice(1, -2)
],
// eslint-disable-next-line local/prefer-valid-rules
'@typescript-eslint/member-naming': [
'warn',
{ private: '^_', protected: '^_' }
],
'@typescript-eslint/no-dynamic-delete': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-namespace': [
'off', // todo: need to audit existing codebase to see if declare is fine
{
allowDeclarations: true,
allowDefinitionFiles: true
}
],
'@typescript-eslint/no-parameter-properties': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-this-alias': ['error', { allowDestructuring: true }],
'@typescript-eslint/no-throw-literal': 'error',
'@typescript-eslint/no-unnecessary-condition': [
'error',
// todo: remove once https://github.com/typescript-eslint/typescript-eslint/pull/1163 is merged
{ ignoreRhs: true }
],
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-use-before-define': [
'error', // Purely stylistic b/c of TS
{ typedefs: false, variables: false }
],
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'warn',
'@typescript-eslint/prefer-regexp-exec': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'warn',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowBoolean: true,
allowNumber: true
}
],
// yes: with types, this is actually useful and correct
'@typescript-eslint/return-await': 'error',
'@typescript-eslint/unbound-method': 'warn', // can be a bit wrong
'@typescript-eslint/unified-signatures': 'warn', // can be a bit wrong

'array-callback-return': 'off',
'block-scoped-var': 'off',
'consistent-return': 'off', // via --noImplicitReturns
'default-param-last': 'off',
'guard-for-in': 'off',
'init-declarations': 'off', // handled by TS & --noImplicitAny
'no-import-assign': 'off',
'no-invalid-this': 'off',
'no-iterator': 'off',
'no-proto': 'off', // TS2339
'no-setter-return': 'off', // TS2408
'no-throw-literal': 'off', // @typescript-eslint
'no-underscore-dangle': 'off',
'no-useless-constructor': 'off', // @typescript-eslint
'strict': 'off' // via --alwaysStrict
}
};
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ Install this package:

npm install --save-dev eslint-config-ackama

### Additional Setup

#### @typescript-eslint

The `@typescript-eslint` configuration requires type checking to be setup.

You can do this by making a `tsconfig.eslint.json` with the following:

```json
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "coverage", "public", "build", "dist", "lib"],
"include": ["bin", "src", "types", "test", "*.ts", "*.tsx", "*.js", "*.jsx"]
}
```

### Environments

ESLint uses the toplevel `env` property to track what variables are available
Expand All @@ -29,6 +45,35 @@ In general, the primary ones to know about are
You'll find a full list of the envs & their use-cases
[here](https://eslint.org/docs/user-guide/configuring#specifying-environments).

### Notes & Considerations

While the majority of rules enabled by these configurations are sound, a few
have edge cases or are potentially not as suitable as initially hoped.

Some of these edge cases are already well-known, and may have possible fixes in
the future; the details of these rules are documented below.

In general, we are more acceptance of rules that don't catch everything than
rules that report too many false positives.

#### `@typescript-eslint/unbound-method` reports methods as unbound (`console` in particular)

This rule is promising, but needs to be battle tested in real-world code to
determine how accurate it actually is.

One common pattern that is already known to be flagged is with `Console`:

```
Promise.reject().catch(console.error);
```

This will be incorrectly flagged as being unbound. This is because currently the
`Console` methods are not typed as being bound.

There is an open issue tracking implementing an exclusion for `Console` to the
rule on
[`@typescript-eslint`](https://github.com/typescript-eslint/typescript-eslint/issues/1085).

### Releasing

Releases are handled using
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "ISC",
"author": "Gareth Jones",
"files": [
"@typescript-eslint.js",
"flowtype.js",
"index.js",
"jest.js"
Expand Down Expand Up @@ -53,9 +54,9 @@
"@types/eslint": "^6.1.3",
"@types/jest": "^24.9.0",
"@types/node": "^12.12.25",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/experimental-utils": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/experimental-utils": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.8.0",
"eslint-plugin-eslint-comments": "^3.1.2",
Expand Down

0 comments on commit d8c0e31

Please sign in to comment.