Home > Software design >  Naming Convention for non-Angular Code Files
Naming Convention for non-Angular Code Files

Time:03-02

Note that I am not asking for opinions on what's your preferred convention here. I am asking for an accepted standard practice on par with the guidelines I am listing here. If there is no single accepted such style, then that is the answer.

There appears to be a single "official" naming convention for TypeScript files in Angular projects - from the official styleguide:

Do follow a pattern that describes the symbol's feature then its type. The recommended pattern is feature.type.ts.

The styleguide goes on to mention commonly used "types" for this pattern:

Do use conventional type names including .service, .component, .pipe, .module, and .directive. Invent additional type names if you must but take care not to create too many.

On the one hand, this sounds like it applies to all TypeScript files in the application. On the other hand, all of the proposed file types are Angular-specific.

So, what about all the other code files that contain client-side application logic, but do not get in touch with Angular at all? Utility and storage classes that are not instantiated using Angular's injection mechanism?

The list of types from the styleguide is open-ended, but it also says I "must but take care not to create too many". As such, I am not sure using the "end of the class name" is the way to go (this would give me a long list such as Manager, Handler, Map, List, Provider, Listener, Source, etc.).

While not mentioned in the styleguide text on the Angular website, is there a commonly accepted "catch-all" type for all the other code, such as ... .code.ts? Or am I getting this wrong and non-Angular code files are not actually covered by that styleguide?

CodePudding user response:

there is no specific angular guideline for non Angular specific files. However i always like to name my files including in them some sort of indicator of what this file refers to. For example for utils i have a separate folders where if there is a global utils file i can name it as app.utils.ts. Similarly for store have a separate directory and you can name files as users.reducers.ts, users.selectors.ts and so on

  • Related