@testgorilla/tgo-linting 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/Readme.md +97 -60
  2. package/package.json +1 -1
package/Readme.md CHANGED
@@ -38,7 +38,7 @@ export default [
38
38
  tgo: tgoPlugin,
39
39
  },
40
40
  rules: {
41
- 'tgo/require-data-testid': 'warn',
41
+ 'tgo/require-data-testid': 'warn', // Example rule configuration
42
42
  },
43
43
  },
44
44
  ];
@@ -82,7 +82,7 @@ module.exports = {
82
82
  files: ['*.html'],
83
83
  parser: '@angular-eslint/template-parser',
84
84
  rules: {
85
- 'tgo/require-data-testid': 'warn',
85
+ 'tgo/require-data-testid': 'warn', // Example rule configuration
86
86
  },
87
87
  },
88
88
  ],
@@ -96,64 +96,101 @@ module.exports = {
96
96
 
97
97
  ## Rules
98
98
 
99
- ### `tgo/require-data-testid`
100
-
101
- Ensures that specific HTML elements have a `data-testid` attribute for testing purposes. This makes it easier to write stable E2E tests by providing consistent selectors.
102
-
103
- **Severity:** `warn` (in recommended config)
104
-
105
- **Category:** Testing Best Practices
106
-
107
- #### Default Elements
108
-
109
- By default, this rule checks the following elements:
110
- - `button`
111
- - `mat-checkbox`
112
- - `input`
113
- - `mat-radio-button`
114
- - `mat-radio-group`
115
- - `h1`
116
- - `table`, `header-table`, `mat-table`
117
- - `img`
118
- - `textarea`
119
- - `ng-select`
120
- - `video`
121
- - `app-tgo-choice`
122
- - `testgorilla-confirm-dialog`
123
- - `mat-form-field`
124
- - `tgo-checkout-message`
125
- - `mat-dialog-actions`
126
- - `ui-button`
127
-
128
- #### Configuration
129
-
130
- You can customize which elements to check:
131
-
132
- ```javascript
133
- {
134
- rules: {
135
- 'tgo/require-data-testid': ['warn', {
136
- tags: ['button', 'input', 'custom-element']
137
- }]
138
- }
139
- }
140
- ```
141
-
142
- #### Examples
143
-
144
- ❌ **Incorrect**
145
-
146
- ```html
147
- <button>Click me</button>
148
- <input type="text" />
149
- ```
150
-
151
- ✅ **Correct**
152
-
153
- ```html
154
- <button data-testid="submit-button">Click me</button>
155
- <input type="text" data-testid="email-input" />
156
- ```
99
+ ### Available Rules
100
+
101
+ | Rule | Description |
102
+ |------|-------------|
103
+ | `tgo/require-data-testid` | Ensures specific HTML elements have a `data-testid` attribute for E2E testing |
104
+
105
+ ### Rule Documentation
106
+
107
+ Detailed documentation for each rule, including examples and configuration options, can be found alongside the rule implementation:
108
+
109
+ - [require-data-testid](./src/rules/require-data-testid.md) - Enforces data-testid attributes on specified elements
110
+
111
+ ## Adding New Rules
112
+
113
+ To add a new ESLint rule to this package:
114
+
115
+ 1. **Create the rule file** in `src/rules/`:
116
+ ```typescript
117
+ // src/rules/your-rule-name.ts
118
+ import { Rule } from 'eslint'
119
+
120
+ const rule: Rule.RuleModule = {
121
+ meta: {
122
+ type: 'problem', // or 'suggestion' or 'layout'
123
+ docs: {
124
+ description: 'Your rule description',
125
+ category: 'Best Practices',
126
+ recommended: false,
127
+ },
128
+ schema: [], // JSON schema for rule options
129
+ messages: {
130
+ // Define error messages here
131
+ },
132
+ },
133
+ create(context) {
134
+ // Your rule implementation
135
+ return {
136
+ // AST node visitors
137
+ }
138
+ },
139
+ }
140
+
141
+ export default rule
142
+ ```
143
+
144
+ 2. **Add tests** in `src/rules/your-rule-name.spec.ts`:
145
+ ```typescript
146
+ import { RuleTester } from '@typescript-eslint/rule-tester'
147
+ import rule from './your-rule-name'
148
+
149
+ const ruleTester = new RuleTester({
150
+ parser: '@angular-eslint/template-parser',
151
+ })
152
+
153
+ ruleTester.run('your-rule-name', rule, {
154
+ valid: [
155
+ // Test cases that should pass
156
+ ],
157
+ invalid: [
158
+ // Test cases that should fail
159
+ ],
160
+ })
161
+ ```
162
+
163
+ 3. **Export the rule** in `src/rules/index.ts`:
164
+ ```typescript
165
+ import yourRuleName from './your-rule-name'
166
+
167
+ export const rules = {
168
+ 'require-data-testid': requireDataTestId,
169
+ 'your-rule-name': yourRuleName,
170
+ }
171
+ ```
172
+
173
+ 4. **Add to recommended config** (optional) in `src/configs/recommended.ts`:
174
+ ```typescript
175
+ rules: {
176
+ 'tgo/require-data-testid': 'warn',
177
+ 'tgo/your-rule-name': 'error', // or 'warn'
178
+ }
179
+ ```
180
+
181
+ 5. **Document the rule** in `src/rules/your-rule-name.md`:
182
+ - Describe what the rule does
183
+ - Provide configuration options
184
+ - Show correct and incorrect code examples
185
+ - Explain the rationale
186
+
187
+ 6. **Update this README** by adding the new rule to the rules table above
188
+
189
+ 7. **Test your changes**:
190
+ ```bash
191
+ nx test tgo-linting
192
+ nx build tgo-linting
193
+ ```
157
194
 
158
195
  ## Development
159
196
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testgorilla/tgo-linting",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "peerDependencies": {
5
5
  "@angular-eslint/template-parser": ">= 17.0.0 < 20.0.0",
6
6
  "eslint": "^8 || ^9",