Angular eslint: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Created page with "=Introduction= Just a page to setup Eslint ==Install Dependencies== <syntaxhighlight lang="bash"> ng add @angular-eslint/schematics </syntaxhighlight> ==eslintrc.js== In the r..."
 
Line 38: Line 38:
   ]
   ]
}
}
</syntaxhighlight>
==Update ng lint command==
Edit the angular.json
<syntaxhighlight lang="js">
"lint": {
  "builder": "@angular-eslint/builder:lint",
  "options": {
    "lintFilePatterns": [
      "src/**/*.ts",
      "src/**/*.component.html"
    ]
  }
},
</syntaxhighlight>
==Install additional ESLint Plugins==
If you want to install another plugin for ESLint, for example, to lint Jasmine spec files, install appropriate npm-package:
<syntaxhighlight lang="bash">
npm install eslint-plugin-jasmine --save-dev
</syntaxhighlight>
</syntaxhighlight>

Revision as of 02:37, 22 April 2021

Introduction

Just a page to setup Eslint

Install Dependencies

ng add @angular-eslint/schematics

eslintrc.js

In the root of the project create a .eslintrc.js

module.exports = {
  root: true,
  overrides: [
    {
      files: ["*.ts"],
      parserOptions: {
        project: [
          "tsconfig.*?.json",
          "e2e/tsconfig.json"
        ],
        createDefaultProgram: true
      },
      extends: ["plugin:@angular-eslint/recommended"],
      rules: {
        ...
      }
    },
    {
      files: ["*.component.html"],
      extends: ["plugin:@angular-eslint/template/recommended"],
      rules: {
        "max-len": ["error", { "code": 140 }]
      }
    },
    {
      files: ["*.component.ts"],
      extends: ["plugin:@angular-eslint/template/process-inline-templates"]
    }
  ]
}

Update ng lint command

Edit the angular.json

"lint": {
  "builder": "@angular-eslint/builder:lint",
  "options": {
    "lintFilePatterns": [
      "src/**/*.ts",
      "src/**/*.component.html"
    ]
  }
},

Install additional ESLint Plugins

If you want to install another plugin for ESLint, for example, to lint Jasmine spec files, install appropriate npm-package:

npm install eslint-plugin-jasmine --save-dev