DEV Community

Facundo Ezequiel Diaz Cappella
Facundo Ezequiel Diaz Cappella

Posted on • Edited on

3 1

Settings linter in Angular 12

The new version of Angular 12 not include linters because TSLint is deprecated.

For that I'm going to put here how to add eslint in Angular 12.

Prerequisites:

  • Node js -> 12.13.x/14.15.x or later minor
  • npm
  • angular/cli -> v12

First step:

 // create project
 ng new my-new-project
Enter fullscreen mode Exit fullscreen mode

Second step:

// install eslint as dev dependency 
npm install --save-dev eslint
// install ts rules plugin
npm i --save-dev @typescript-eslint/eslint-plugin 
// install eslint parser
npm i --save-dev @typescript-eslint/parser
Enter fullscreen mode Exit fullscreen mode

The next step is, add the rules of our linter:

  • create new file ".eslintrc", on the root folder, with this values:
{
    "parser": "@typescript-eslint/parser",
    "extends": [
      "plugin:@typescript-eslint/recommended",
    ],
    "parserOptions": {
      "ecmaVersion": 2021,
      "sourceType": "module"
    },
    "rules": {
               // custom rules here
    }
}
Enter fullscreen mode Exit fullscreen mode

Last step:
Add this script in package.json

"lint": "eslint \"**/*.{ts,tsx}\" "
Enter fullscreen mode Exit fullscreen mode

For run:

npm run lint
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
chigix profile image
Richard Lea • Edited

There seems official lint support: angular.io/cli/lint now. It might be grateful if the official one could be introduced along with some further comparison with manual configuration under the hood.

Collapse
 
thegoldyman profile image
talamaska

FYI there is package @angular-eslint/angular-eslint that does all the magic.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay