Codelyzer: TSLint Rules for Angular Static Analysis
Codelyzer is a set of TSLint rules built specifically for static analysis of Angular TypeScript projects, covering components, directives, templates, and styles. Its own README already tells ESLint users to check out the newer angular-eslint project instead. Reach for Codelyzer if your codebase still runs TSLint and needs Angular-aware checks today; skip it and set up angular-eslint if you're starting fresh or already moving off TSLint.
Understanding Codelyzer: Angular Static Analysis
Codelyzer is a TSLint plugin that adds Angular-specific static analysis rules, checking things like component selector naming, lifecycle interface usage, and template bindings. It works across Angular CLI projects, NativeScript, and Ionic apps, and hooks in through a tslint.json file that extends its rule set, per the README.
Key Rules for Angular Code Quality
- ✓component-class-suffix and directive-class-suffix check that Angular class names end in Component or Directive, or a custom suffix you configure.
- ✓component-selector and directive-selector enforce a naming convention and prefix for selectors, such as requiring kebab-case elements or camelCase attributes.
- ✓Lifecycle rules — contextual-lifecycle, no-conflicting-lifecycle, use-lifecycle-interface — catch Angular lifecycle hooks that are misused or missing their interface.
- ✓Template rules — template-banana-in-box, template-no-negated-async, template-use-track-by-function, template-cyclomatic-complexity — flag common Angular template mistakes.
- ✓Accessibility-focused template rules, like template-accessibility-alt-text and template-accessibility-valid-aria, are listed as Experimental in the README's rules table.
- ✓no-unused-css flags CSS selectors in a component's stylesheet that don't match anything in its template; it's also marked Experimental.
- ✓Advanced configuration through a .codelyzer.js file lets you plug in custom template and style transforms, such as compiling Sass before analysis, per the README's example.
How to Integrate Codelyzer into Your Project
Codelyzer installs differently depending on your setup. Angular CLI projects get it for free. The README says running ng lint on a project created with ng new applies Codelyzer's Angular rules with no extra work, since components already follow the style guide by default. The angular-seed starter also ships with it wired into its own npm run lint script, per the README. For a custom project, install Codelyzer directly with npm i codelyzer tslint @angular/compiler @angular/core, or pull in the tslint-angular preset (npm i tslint-angular) if you'd rather extend one config than list every rule yourself. Either path needs a tslint.json file that extends "codelyzer" or "tslint-angular", and you can install Codelyzer globally with npm install -g codelyzer if you don't want to call it through node_modules/.bin/tslint.
Configuring and Running Codelyzer
Configuration lives in tslint.json. Extending "codelyzer" and turning on individual rules — component-class-suffix, component-selector, no-input-rename, template-banana-in-box, and dozens more — gives you the Angular-aware checks; the README's custom-installation example lists over 30 of them explicitly. There's also a separate Recommended configuration in the README, drawn from the Angular Style Guide, that sets selector prefixes and class suffixes as arrays so you can match your own project's naming convention. To turn off one rule in a single file instead of project-wide, add a tslint:disable:rule-name comment above the offending code. For non-standard templates or styles, Sass included, the README shows an advanced setup: a .codelyzer.js file at your project root where you define transformStyle and transformTemplate hooks, plus custom interpolation markers and a predefinedDirectives list for template references Codelyzer can't otherwise resolve.
Strengths
- ✓Covers a wide surface of Angular-specific concerns in one rule set — selectors, lifecycle hooks, template bindings, CSS-to-template consistency — instead of just generic TypeScript style.
- ✓Drops into Angular CLI projects with no extra wiring: ng lint picks up its rules automatically, per the README.
- ✓Rule-level granularity. You can disable a single rule in one file with a tslint:disable marker instead of an all-or-nothing config.
- ✓Extensible to non-standard template and style pipelines through the .codelyzer.js hook system, so teams on Sass or a custom template language aren't locked out.
- ✓MIT license, so there's no licensing friction to adopting it.
Important Considerations: TSLint Deprecation
- △Codelyzer's rules only run through TSLint, and the README itself tells ESLint users to switch to the angular-eslint project instead — it isn't the path the maintainer points ESLint-based setups toward.
- △Part of the rule set is still labeled Experimental in the README's own status table, including no-unused-css, template-i18n, and the template-accessibility-* rules, so not every rule is presented as settled.
- △One rule, angular-whitespace, is marked Deprecated in that same table.
- △Editor integration isn't automatic everywhere. The README says VSCode needs manual tslint.rulesDirectory and typescript.tsdk settings, while Atom works without that step.
- △Support for template or style languages beyond the defaults isn't built in. Sass, for example, requires writing your own transformStyle hook in a .codelyzer.js file, per the README's example.
Modern Alternatives for Angular Linting
Common Questions About Codelyzer
Codelyzer is released under the MIT license, as listed on its GitHub repository.
Codelyzer ships built into Angular CLI projects. Running ng lint on a project created with ng new applies its Angular-specific TSLint rules automatically, per the README.
Codelyzer rules can be turned off in a specific file by adding a tslint:disable:rule-name marker comment above the code, the same mechanism TSLint uses generally.
Codelyzer is built on TSLint, not ESLint. Its README tells ESLint users to use the separate angular-eslint project instead of running Codelyzer alongside ESLint.
The README's recommended configuration extends Codelyzer's Angular Style Guide-based rules, including selector, lifecycle, and template checks like component-selector and template-banana-in-box, set inside a tslint.json file.
Codelyzer supports custom template and style languages, such as Sass, through a .codelyzer.js hook file where you define transformTemplate and transformStyle functions, per the README's example.
The problem it solves
Angular projects that lint with TSLint don't get Angular-aware rules for free — a generic TSLint config catches TypeScript problems but has no idea what a valid component selector, a correctly implemented lifecycle hook, or a safe template binding looks like. Codelyzer closes that specific gap by packaging the Angular Style Guide's conventions — selector prefixes, class suffixes, lifecycle interface usage, template checks — as a TSLint rule set instead of leaving each team to hand-roll its own.
Best use cases
- •Angular teams still standardized on TSLint who want the framework's own style guide — selector prefixes, class suffixes, lifecycle interfaces — enforced automatically instead of caught in code review.
- •NativeScript or Ionic apps built with Angular, since the README explicitly lists both as supported alongside plain web apps.
- •Projects built on the angular-seed starter, which the README says ships with Codelyzer already wired into its npm run lint script.
- •Teams that need per-file rule exceptions: the tslint:disable marker turns off one rule, like template-use-track-by-function, without disabling the whole linter.
Who should try it — and who should skip
Try Codelyzer if your Angular project is already on TSLint and you want the framework's style guide enforced without hand-writing rules — the selector, lifecycle, and template checks plus the tslint:disable escape hatch make it a fairly complete drop-in. Skip it if you're starting fresh or moving off TSLint: Codelyzer's own README sends ESLint users to angular-eslint instead, so a new project has little reason to adopt a TSLint-only rule set today.
Related repositories
Is codelyzer worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of codelyzer.
