This is a custom Prettier plugin for formatting Angular code by adding public/private modifiers and return types to functions and variables.
To use this plugin in your Angular project, follow these steps:
-
Install Prettier and the plugin as dependencies:
npm install angular-syntax-formatter npm install prettier @babel/parser @babel/traverse @babel/generator --save-dev
-
Create a
prettier.config.js
file in the root directory of your project:// prettier.config.js module.exports = { plugins: ["angular-syntax-formatter"], parser: "typescript" };
Once you've installed the plugin and configured Prettier, you can format your Angular code using Prettier as usual. For example:
npx prettier --write src/**/*.ts
This command formats all TypeScript files (*.ts
) in the src
directory and its subdirectories.
- Adds public/private modifiers to functions and variables
- Adds return types to functions and variables
Before formatting:
// Before formatting
class Example {
foo;
bar() {
return 42;
}
}
After formatting:
// After formatting
class Example {
public foo: string;
private bar(): number {
return 42;
}
}
If you encounter any issues or have suggestions for improvement, feel free to open an issue on GitHub.
Pull requests are also welcome!
This project is licensed under the MIT License - see the LICENSE file for details.