@testgorilla/tgo-linting
Linting rules and code quality standards for TestGorilla projects.
Installation
npm install @testgorilla/tgo-linting @angular-eslint/template-parser --save-dev
Usage
This package supports both modern flat config (ESLint 9+) and legacy config formats (ESLint 8.x and below).
Flat Config (ESLint 9+)
Recommended approach:
import tgoPlugin from '@testgorilla/tgo-linting';
export default [
tgoPlugin.configs.recommended,
];
Manual configuration:
import tgoPlugin from '@testgorilla/tgo-linting';
export default [
{
plugins: {
tgo: tgoPlugin,
},
rules: {
'tgo/require-data-testid': 'warn',
},
},
];
Legacy Config (ESLint 8.x and below)
Using the legacy preset:
const { legacy } = require('@testgorilla/tgo-linting');
module.exports = {
extends: [
],
plugins: ['tgo'],
overrides: [
{
files: ['*.html'],
parser: '@angular-eslint/template-parser',
...legacy,
},
],
};
Manual configuration:
module.exports = {
plugins: ['tgo'],
extends: [
],
overrides: [
{
files: ['*.html'],
parser: '@angular-eslint/template-parser',
rules: {
'tgo/require-data-testid': 'warn',
},
},
],
};
Important Notes
- Template Parser Required: The
tgo/require-data-testid rule only works with HTML/Angular templates. You must configure @angular-eslint/template-parser for .html files.
- Angular Projects: If you're using
@angular-eslint, the template parser is usually already configured for HTML files in your overrides.
Rules
Available Rules
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:
Adding New Rules
To add a new ESLint rule to this package:
-
Create the rule file in src/rules/:
import { Rule } from 'eslint'
const rule: Rule.RuleModule = {
meta: {
type: 'problem',
docs: {
description: 'Your rule description',
category: 'Best Practices',
recommended: false,
},
schema: [],
messages: {
},
},
create(context) {
return {
}
},
}
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: [
],
invalid: [
],
})
-
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',
}
-
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-linting
Testing
nx test tgo-linting
Linting
nx lint tgo-linting
License
PROPRIETARY - © TestGorilla