April 13, 2021
  • Announcements
  • Angular
  • Linting
  • Tools

ESLint for Ionic Angular

Mike Hartington

Director of Developer Relation...

Today I’m happy to share that Ionic’s starter projects now ship with modern linting, powered by ESLint. This gives us a consistent linting tool across all project types, but also removes a deprecated dependency. Let’s dive in and rewind the clock to 2018.

Sunsetting TSLint

If you were looking for a linting tool for a TypeScript project, chances are you ended up using TSLint. TSLint was a static analysis tool that would check a TypeScript code base to enforce a consistent code style and make sure the project didn’t break any rules, aka your standard linting tool. Now, TSLint isn’t the only tool in this space. Another linting tool that was the de facto standard in JavaScript projects was ESLint. ESLint and TSLint provided a similar set of features, but ESLint didn’t have support for TypeScript.

Fast forward to 2019, and the landscape was starting to look different. The TypeScript community was looking to improve the tooling landscape and provide a more unified experience for TypeScript and JavaScript devs. The maintainers of TSLint took this opportunity to announce the deprecation of TSLint and plans to help support ESLint as the linter for both TypeScript and JavaScript.

Now in 2021, the TSLint repo has been archived and the TypeScript-ESLint team, headed up by James Henry and others, have been working to support developers.

From one linting tool to another

With the history listed out of the way, let’s upgrade a project to use ESLint. This process can be done manually, but why do that when we can automate it. For most projects, the quickest way to upgrade is to use Angular-ESLint and run their schematics. First commit any open changes and make a new branch (just to be sure):

git add .
git commit -m "pre eslint"
git checkout -b feat-eslint

Then we can add the schematics for Angular-ESLint

ng add @angular-eslint/schematics

From here, we can convert our existing TSLint config to ESLint with the following command:

ng g @angular-eslint/schematics:convert-tslint-to-eslint {{YOUR_PROJECT_NAME_GOES_HERE}}

Once this is done, you can run ESLint against your project! The schematic won’t remove TSLint from your package.json or the tslint.json from your project. These can be removed:

rm tslint.json
npm uninstall tslint

Commit your changes and make send one sweet pull request!

Where do we go now?

With ESLint installed and configured, projects can make use of the extensive ecosystem of plugins available, like Prettier. With new Ionic Angular projects using ESLint, you can rest assured knowing you will have stable tools for the future of your development. A huge thank you to James Henry and Brad Zacher for building and maintaining TypeScript-ESLint and Angular-ESLint.

Mike Hartington

Director of Developer Relation...