Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure @typescript-eslint rules

I'm trying to convert to @typescript-eslint but the documentation seems sorely lacking. For example, I'm getting errors like this:

Line 58:  Expected a semicolon             @typescript-eslint/member-delimiter-style

I want to enforce no semicolons or commas. I found the documentation for that rule. https://github.com/bradzacher/eslint-plugin-typescript/blob/master/docs/rules/member-delimiter-style.md

But it doesn't seem to give any examples of how to configure it in a real eslint file! Anyone know how?

like image 345
CorayThan Avatar asked Jun 29 '19 09:06

CorayThan


People also ask

How do I add rules to TypeScript-ESLint?

Usage. Add @typescript-eslint/parser to the parser field and @typescript-eslint to the plugins section of your . eslintrc configuration file, then configure the rules you want to use under the rules section.

How do I configure ESLint rules?

There are two primary ways to configure ESLint: Configuration Comments - use JavaScript comments to embed configuration information directly into a file. Configuration Files - use a JavaScript, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories.

Can I use ESLint with TypeScript?

ESLint is a JavaScript linter that you can use to lint either TypeScript or JavaScript code.


1 Answers

Using a .eslintrc.js configuration file you have to add this to the "rules" section:

"rules": {
    "@typescript-eslint/member-delimiter-style": ["error", {
      multiline: {
        delimiter: 'none',    // 'none' or 'semi' or 'comma'
        requireLast: true,
      },
      singleline: {
        delimiter: 'semi',    // 'semi' or 'comma'
        requireLast: false,
      },
    }]
}

Worked for me for the "@typescript-eslint/explicit-function-return-type" parameter. Options are from the rules project site on github

Thanks to maxkoryukov for improving my original answer.

like image 129
BerniP Avatar answered Sep 24 '22 05:09

BerniP