@testgorilla/tgo-linting
v6.0.0
Published
Linting rules and code quality standards for TestGorilla projects
Downloads
5,124
Maintainers
Keywords
Readme
@testgorilla/tgo-linting
Linting rules and code quality standards for TestGorilla projects.
Installation
npm install @testgorilla/tgo-linting @angular-eslint/template-parser --save-devCompatibility
| tgo-linting | ESLint | angular-eslint | TypeScript | Angular |
| ----------- | --------------------- | -------------- | ---------------- | ------------------------------------------------ |
| 6.x | ^10.0.0 | 22.x | >=4.8.4 <6.1.0 | any (angular-eslint 22 bundles its own compiler) |
| 5.1+ | ^10.0.0 | 21.x | >=4.8.4 <6.0.0 | any (angular-eslint 21 bundles its own compiler) |
| 5.0 | ^9.0.0 \|\| ^10.0.0 | 21.x | >=4.8.4 <6.0.0 | any (angular-eslint 21 bundles its own compiler) |
| 4.x | ^8.57.0 \|\| ^9.0.0 | 20.x | — | any |
ESLint 9 support ended in 5.1.0. 5.0.0 kept the
^9.0.0 || ^10.0.0peer range so repos could adopt the preset before finishing their ESLint 10 migration. All consumers completed that migration alongside the Angular 21 upgrade, so 5.1.0 narrows the range to ESLint 10 only. Stay on 5.0.0 if you are still on ESLint 9 — and note that 5.0.0 also required aneslint-plugin-rxjs-xoverride to install cleanly on 9, which 5.1.0 no longer needs.
Upgrading to 6.0.0
6.0.0 adds TypeScript 6 support, which Angular 22 requires. Every 5.x release capped
the typescript peer below 6.0 (through typescript-eslint 8.56), so any repo that uses
tgo-linting failed to install once it moved to Angular 22. 6.0.0 moves to
typescript-eslint 8.72 and angular-eslint 22, and widens the peer to >=4.8.4 <6.1.0.
It still works on TypeScript 5.9 and Angular 21, so you can bump tgo-linting before or
during your Angular 22 upgrade. Drop any temporary typescript override you added for it.
What changes for consumers:
@angular-eslint/prefer-on-push-component-change-detectionflags only opt-outs. In angular-eslint 22 the rule no longer reports components that omitchangeDetection(in Angular 22, leaving it out means OnPush). It now reports components that setChangeDetectionStrategy.EagerorChangeDetectionStrategy.Default. The rule stays aterror, so expect two things:- After the Angular 22 migration, every component the migration set to
Eageris reported. Either move them to OnPush after checking each one, or keep a project-levelwarnoverride for the rule (a Phase Z deferral, as described in the lint-rollout runbook) until you've audited them. - On Angular 21, components without
changeDetectionstill run asDefaultbut are no longer reported. That gap closes when you move to Angular 22.
- After the Angular 22 migration, every component the migration set to
@angular-eslint/no-conflicting-lifecycleis gone. angular-eslint 22 removed it, so it has been removed from the preset. Delete it from your own config too, or ESLint fails withCould not find rule.- Node 20 is no longer supported by angular-eslint 22. Use Node 22 or later.
No other rules change: the template recommended set (banana-in-box, eqeqeq,
no-negated-async, prefer-control-flow) is now listed in the preset explicitly, because
angular-eslint 22's plugin packages no longer export configs. If your own
eslint.config spreads @angular-eslint/eslint-plugin(-template).configs.*, switch to
the angular-eslint meta-package's flat configs or list the rules yourself.
Upgrading to 5.1.0
5.1.0 restores the @eslint/js recommended baseline in the recommended() preset. Up to
5.0.0 the preset only spread the typescript-eslint configs, whose eslint-recommended slice
disables the core rules TypeScript already covers but never enables the rest — so core
rules such as no-prototype-builtins, no-duplicate-case, no-async-promise-executor,
no-unsafe-optional-chaining and no-misleading-character-class were silently inactive in
consumers. The same release cherry-picks @angular-eslint/template/no-any and
template/no-duplicate-attributes onto the HTML block.
No config change is needed, but expect new violations on first run after the bump. Dry-run
npx eslint . before merging the upgrade.
5.1.0 also drops ESLint 9: both the eslint peer range and the bundled @eslint/js
dependency are now ^10.0.0. @eslint/[email protected] itself declares an eslint: ^10.0.0
peer, so an ESLint 9 install would fail to resolve rather than degrade quietly.
Usage
This package requires ESLint flat config (eslint.config.js/.mjs) and ESLint 10.
Support for legacy .eslintrc.* configs and ESLint 8 was removed in 5.0.0; ESLint 9
support ended in 5.1.0.
Flat Config
Recommended approach:
// eslint.config.js
import tgoPlugin from '@testgorilla/tgo-linting';
export default [
tgoPlugin.configs.recommended,
// Your other configurations
];Manual configuration:
// eslint.config.js
import tgoPlugin from '@testgorilla/tgo-linting';
export default [
{
plugins: {
tgo: tgoPlugin,
},
rules: {
'tgo/require-data-testid': 'warn', // Example rule configuration
},
},
];Important Notes
- Template Parser Required: The
tgo/require-data-testidrule only works with HTML/Angular templates. You must configure@angular-eslint/template-parserfor.htmlfiles. - Angular Projects: If you're using
@angular-eslint, the template parser is usually already configured for HTML files in your overrides.
Rules
Available Rules
| Rule | Description |
| ------------------------- | ----------------------------------------------------------------------------- |
| tgo/require-data-testid | Ensures specific HTML elements have a data-testid attribute for E2E testing |
Rule Documentation
Detailed documentation for each rule, including examples and configuration options, can be found alongside the rule implementation:
- require-data-testid - Enforces data-testid attributes on specified elements
Adding New Rules
To add a new ESLint rule to this package:
Create the rule file in
src/rules/:// src/rules/your-rule-name.ts import { Rule } from 'eslint'; const rule: Rule.RuleModule = { meta: { type: 'problem', // or 'suggestion' or 'layout' docs: { description: 'Your rule description', category: 'Best Practices', recommended: false, }, schema: [], // JSON schema for rule options messages: { // Define error messages here }, }, create(context) { // Your rule implementation return { // AST node visitors }; }, }; export default rule;Add tests in
src/rules/your-rule-name.spec.ts:import { RuleTester } from '@typescript-eslint/rule-tester'; import rule from './your-rule-name'; const ruleTester = new RuleTester({ parser: '@angular-eslint/template-parser', }); ruleTester.run('your-rule-name', rule, { valid: [ // Test cases that should pass ], invalid: [ // Test cases that should fail ], });Export the rule in
src/rules/index.ts:import yourRuleName from './your-rule-name'; export const rules = { 'require-data-testid': requireDataTestId, 'your-rule-name': yourRuleName, };Add to recommended config (optional) in
src/configs/recommended.ts:rules: { 'tgo/require-data-testid': 'warn', 'tgo/your-rule-name': 'error', // or 'warn' }Document the rule in
src/rules/your-rule-name.md:- Describe what the rule does
- Provide configuration options
- Show correct and incorrect code examples
- Explain the rationale
Update this README by adding the new rule to the rules table above
Test your changes:
nx test tgo-linting nx build tgo-linting
Development
Building
nx build tgo-lintingTesting
nx test tgo-lintingLinting
nx lint tgo-lintingLicense
PROPRIETARY - © TestGorilla
