A
A
Anton Shvets2018-04-22 17:50:41
typescript
Anton Shvets, 2018-04-22 17:50:41

What is the correct way to set up ESLint for typescript?

I'm transferring back to ts.
I have a route handler for Koa

import { Context } from 'koa';
export class IndexController {
  static manifest({ response: res }: Context) {
    res.body = manifest;
  }
}

eslint configuration
{
  "parser": "typescript-eslint-parser",
  "extends": [
    "airbnb-base"
  ],
  "env": {
    "node": true,
    "es6": true
  },
  "plugins": [
    "import",
    "mongodb",
    "typescript"
  ],
  "rules": {
    "func-names" : "error",
    "no-await-in-loop": "off",
    "strict": "off",
    "import/prefer-default-export": "off",
    "import/extensions": "off"
  },
  "settings": {
    "import/resolver": {
      "node": true,
      "eslint-import-resolver-typescript": true
    }
  }
}

Linter swears at import { Context } from 'koa';Says unused ver.
Is there any way to satisfy the linter in this case without resorting to eslint-disable

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Stolyarov, 2018-04-22
@Ni55aN

For TS there is TSLint

I
Ivan Ganev, 2019-02-20
@IvanGanev

eslint is now focused on working with typescript as well
. Personally, I came up with this eslint setup for typescript:
.eslintrc.json

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "prettier"],
  "extends": [
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "parserOptions": {
    "sourceType": "module",
    "useJSXTextNode": true,
    "project": "./tsconfig.json"
  }
}

.prettierrc
{
  "singleQuote": true,
  "arrowParens": "always",
  "tabWidth": 2,
  "useTabs": false
}

.babelrc is important, it won't work without it.
{
  "plugins": ["babel-plugin-rewire"],
  "presets": [
    "@babel/preset-typescript",
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ]
}

tsconfig.json
{
  "compilerOptions": {
    "diagnostics": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es7"],
    "module": "commonjs",
    "target": "esnext",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "dist/",
    "pretty": true,
    "removeComments": true,
    "strict": true,
    "declaration": true
  },
  "exclude": [
    "src/**/*.spec.*",
    "node_modules",
    "**/__tests__/*",
    "**/__mocks__/*"
  ],
  "include": ["src", "typings"]
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question