- 1. Presentation
- 2. Prerequisites
- 3. Installation
- 4. StackBlitz
- 5. Create your Angular project step by step
- 5.1. Case 1: Generate a new Angular app using directly ESlint schematics & use Prettier
- 5.1.1. Step #1: Remove the old Angular app
- 5.1.2. Step #2: Generate an empty Angular workspace
- 5.1.3. Step #3: Install ESLint
- 5.1.4. Step #4: Generate a new Angular app in the workspace using ESLint
- 5.1.5. Step #5: Install Prettier locally
- 5.1.6. Step #6: Format all files with Prettier
- 5.1.7. Script available
- 5.2. Case 2: Create an original Angular app, convert TSLint to ESlint & use Prettier
- 5.1. Case 1: Generate a new Angular app using directly ESlint schematics & use Prettier
- 6. Set up your editor
- 7. Semantic Versioning
- 8. Resources
- 9. License
Create a new Angular project with a minimal configuration of ESLint & Prettier, set up your editor (PHPStorm, VSCode) and launch the project in StackBlitz.
Versions used :
| Label | Version |
|---|---|
node |
v18.13.0 |
npm |
8.19.3 |
Angular |
15.1.5 |
@angular-eslint/schematics |
15.2.1 |
Prettier |
2.7.1 |
PHPStorm |
2022.3.2 |
VS Code |
1.75.1 |
To launch locally that project, you will need to install NVM (Node Version Manager) or Node.
|
π
|
More information on: |
In my case, I used Node in KDE Neon (see https://github.com/nodejs/snap).
If you want to regenerate step by step a new Angular project, you will need to install/update a global Angular CLI:
$ npm install -g @angular/cli|
π
|
More information on https://angular.io/cli |
-
$ git clone [email protected]:jprivet-dev/angular-eslint-prettier.git -
$ cd angular-eslint-prettier/app -
$ npm install -
$ ng serve -
Open your browser on http://localhost:4200/
After installation, you can Set up your editor.
|
π
|
More information on https://developer.stackblitz.com/guides/integration/open-from-github |
Angular CLI locally generates by default the main.ts file without zone.js:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));Which creates an error (NG0908) when I launch the project in StackBlitz:
Error: NG0908: In this configuration Angular requires Zone.jsAt this stage, locally everything works fine with $ ng serve.
So to solve the problem in StackBlitz, I have to import zone.js in main.ts:
import 'zone.js/dist/zone'; // Avoid error in StackBlitz
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));After that, everything worked perfectly on StackBlitz:
But triggers a warning locally with $ ng serve:
Warning: .../angular-stackblitz/src/main.ts depends on 'zone.js/dist/zone'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies|
|
I created an issue on StackBlitz: stackblitz/core#2366. I am looking for a single solution without Still searchingβ¦β |
|
π‘
|
It is possible to create the content of the To do this, just remove |
|
π
|
Prerequisites: Install a global Angular CLI (optional) |
$ ng new app --create-application false --defaults
$ cd app$ ng add @angular-eslint/schematics|
π‘
|
If you have that error: Execute the following command (the More information on: |
At the end of the process, you will get a confirmation message:
...
CREATE .eslintrc.json (984 bytes)
UPDATE package.json (1451 bytes)
UPDATE angular.json (3456 bytes)
β Packages installed successfully.$ ng generate @angular-eslint/schematics:application app --project-root --routing --style scss --defaults --strict$ npm install --save-dev --save-exact prettier
$ echo {} >.prettierrc.json
$ cp .gitignore .prettierignore|
π‘
|
Base your .prettierignore on .gitignore and .eslintignore (if you have one).
|
|
π
|
More information on https://prettier.io/docs/en/install.html. |
Automatically execute all the above commands, in the angular-eslint-prettier folder, with the following script:
$ . scripts/generate-app.sh|
π
|
Prerequisites: Install a global Angular CLI (optional) |
$ ng new app --skip-git true --routing --style scss --defaults --strict
$ cd app$ ng add @angular-eslint/schematics|
π‘
|
If you have that error: Execute the following command (the More information on: |
At the end of the process, you will get a confirmation message:
...
CREATE .eslintrc.json (984 bytes)
UPDATE package.json (1451 bytes)
UPDATE angular.json (3456 bytes)
β Packages installed successfully.# Avoid error: Path "/tslint.json" does not exist.
$ echo {} >tslint.json
$ ng g @angular-eslint/schematics:convert-tslint-to-eslintAt the end of the process, you will get a confirmation message:
...
DELETE tslint.json
UPDATE angular.json (3456 bytes)
UPDATE package.json (1451 bytes)
β Packages installed successfully.$ npm install --save-dev --save-exact prettier
$ echo {} >.prettierrc.json
$ cp .gitignore .prettierignore|
π‘
|
Base your .prettierignore on .gitignore and .eslintignore (if you have one).
|
|
π
|
More information on https://prettier.io/docs/en/install.html |
Automatically execute all the above commands, in the angular-eslint-prettier folder, with the following script:
$ . scripts/convert-app.shPhpStorm is a cross-platform IDE that provides consistent experience on the Windows, macOS, and Linux operating systems.
|
π
|
More information on https://www.jetbrains.com/help/phpstorm/installation-guide.html |
|
π‘
|
In my case I use Node. |
Configure in Settings > Languages & Frameworks > Node.js. PHPStorm automatically finds Node and NPM:
If you use NVM, you can have (for example):
-
Node interpreter:
~/.nvm/versions/node/v16.15.1/bin/node -
Package manager:
npm ~/.nvm/versions/node/v16.15.1/bin/npm
|
π₯
|
Before you start: Configure a local Node.js interpreter. |
Configure in Settings > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint :
After the configuration, you can see the ESLint alerts in your code. For example:
|
π
|
More information on https://www.jetbrains.com/help/phpstorm/eslint.html |
|
π₯
|
Before you start: Configure a local Node.js interpreter. |
Configure in Settings > Languages & Frameworks > JavaScript > Prettier :
|
π
|
More information on https://www.jetbrains.com/help/phpstorm/prettier.html |
After the configuration, you can reformat your code :
-
With the shortcut Ctrl+Alt+Maj+P.
-
From the contextual menu (Right click > Reformat with Prettier).
To reformat on save, Go in Settings > Languages & Frameworks > JavaScript > Prettier, and check On save option:
If you click on All actions on saveβ¦β, you will see the list of all activated actions:
|
π‘
|
I also use the Optimize import option. This removes unused imports and organizes import statements in the current file. See https://www.jetbrains.com/help/phpstorm/creating-and-optimizing-imports.html#optimize-imports. |
Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.
|
π
|
More information on https://code.visualstudio.com/ |
Install the ESLint extension of Microsoft: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint.
After the installation, you can immediately see the ESLint alerts in your code. For example:
Install the Prettier - Code formatter extension: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode.
After the installation, you can reformat your code :
-
With the shortcut Ctrl+Alt+I.
-
From the contextual menu (Right click > Format Document).
If you have an alert Configure Default Formatter:
Click on the button Configureβ¦β and select Prettier - Code formatter:
To reformat on save, go on File > Preferences > Settings [Ctrl+,], and choose Text Editor > Formatting. Check Format On Paste and Format On Save:
From now on, whenever you paste code or save, the code will be reformatted.
Before:
After (on paste code or save):
|
π
|
Based on https://semver.org/ |
v[MAJOR].[ANGULAR_VERSION].[MINOR].[PATCH]
With [ANGULAR_VERSION] = [ANGULAR MAJOR + ANGULAR MINOR]Example, with v1 of this repository with Angular 15.1.6:
v1.1501.0.0

















