@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.
- package/Readme.md +97 -60
- 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
|
-
###
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
|