You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create test file: `packages/rslint-test-tools/tests/typescript-eslint/rules/<rule-name>.test.ts`
98
+
**IMPORTANT**: TypeScripttest files are maintained from the main branch and should NOT be modified. Focus on Go implementation and Gotests.
99
99
100
-
```typescript
101
-
import { RuleTester } from '@typescript-eslint/rule-tester';
102
-
import { getFixturesRootDir } from '../RuleTester.ts';
100
+
### GoUnitTests
103
101
104
-
const rootDir = getFixturesRootDir();
102
+
Write comprehensive Go tests in `internal/rules/<rule_name>/<rule_name>_test.go`:
105
103
106
-
const ruleTester = new RuleTester({
107
-
languageOptions: {
108
-
parserOptions: {
109
-
project: './tsconfig.json',
110
-
tsconfigRootDir: rootDir,
111
-
},
112
-
},
113
-
});
114
-
115
-
// Use the rule name WITHOUT the @typescript-eslint/ prefix
116
-
ruleTester.run('rule-name', {
117
-
valid: ['valid code examples'],
118
-
invalid: [
119
-
{
120
-
code: 'invalid code',
121
-
errors: [
104
+
```go
105
+
package rule_name
106
+
107
+
import (
108
+
"testing"
109
+
"github.com/web-infra-dev/rslint/internal/rule"
110
+
)
111
+
112
+
func TestRuleNameRule(t *testing.T) {
113
+
rule.RunTest(t, RuleNameRule, []rule.TestCase{
114
+
// Valid cases
122
115
{
123
-
messageId: 'messageId',
124
-
line: 1,
125
-
column: 1,
126
-
endLine: 1,
127
-
endColumn: 10,
116
+
Code: "valid code example",
128
117
},
129
-
],
130
-
},
131
-
],
132
-
});
118
+
// Invalid cases
119
+
{
120
+
Code: "invalid code example",
121
+
Errors: []rule.ExpectedError{
122
+
{
123
+
MessageId: "messageId",
124
+
Line: 1,
125
+
Column: 1,
126
+
},
127
+
},
128
+
},
129
+
})
130
+
}
133
131
```
134
132
135
-
**Important**: The test runner expects exact error positions. Always include line/column information in error expectations.
133
+
### TypeScriptTestFiles
134
+
135
+
**DO NOTCREATEORMODIFY** TypeScript test files. They exist in `packages/rslint-test-tools/tests/typescript-eslint/rules/` and are maintained from the main branch. If a TypeScript test file exists for your rule, it should work automatically once your Go implementation is complete and registered properly.
136
136
137
137
### ManualTesting
138
138
139
139
```bash
140
-
# Build the project
141
-
pnpm build
140
+
# Build the Go binary
141
+
go build ./cmd/rslint
142
142
143
143
# Test directly
144
144
cd packages/rslint/fixtures
@@ -166,15 +166,18 @@ Use the TypeScript AST through the Go shim:
166
166
### RunningTests
167
167
168
168
```bash
169
-
# All tests
170
-
pnpm test
169
+
# Go tests (primary focus)
170
+
go test ./internal/rules/<rule_name>/
171
171
172
-
# Just Go tests
172
+
# All Go tests
173
173
go test ./...
174
174
175
-
# Specific rule tests
175
+
# TypeScript integration tests (after Go implementation is complete)
176
176
cd packages/rslint-test-tools
177
177
pnpm test <rule-name>
178
+
179
+
# All tests (run this before finalizing)
180
+
pnpm test
178
181
```
179
182
180
183
### CIRequirements
@@ -201,42 +204,54 @@ Your changes must pass:
201
204
## CommonPitfalls to Avoid
202
205
203
206
1. **Don't modify** `getAllTypeScriptEslintPluginRules()` - it must match main branch
204
-
2. **Don't change** core infrastructure without understanding impacts
205
-
3. **Always handle nil** from type assertions
206
-
4. **Test with real TypeScript code** to ensure rule behaves correctly
207
-
5. **Missing API registration** - Always add new rules to the hardcoded list in `cmd/rslint/api.go`
208
-
6. **Test failures** - "Expected diagnostics for invalid case" usually means the rule isn't registered in the API
209
-
7. **Wrong rule name in tests** - Use the short name without @typescript-eslint/ prefix in test files
210
-
8. **VSCode test failures** - Diagnostic tests may fail initially due to LSP timing, but should pass consistently after proper rule registration
207
+
2. **Don't create or modify TypeScript test files** - they are maintained from main branch
208
+
3. **Don't change** core infrastructure without understanding impacts
209
+
4. **Always handle nil** from type assertions
210
+
5. **Focus on Go tests first** - ensure your Go implementation passes before running TypeScript tests
211
+
6. **Missing API registration** - Always add new rules to the hardcoded list in `cmd/rslint/api.go`
212
+
7. **Test failures** - "Expected diagnostics for invalid case" usually means the rule isn't registered in the API
213
+
8. **Column position mismatches** - TypeScript-ESLint and Go implementation may calculate positions differently, focus on Go test compatibility
211
214
212
215
## CompleteChecklistforAdding a NewRule
213
216
217
+
### CoreImplementation (Primary Focus)
218
+
214
219
1. [ ] Create rule implementation in `internal/rules/<rule_name>/<rule_name>.go`
215
220
2. [ ] Addnil checks for all AST node type assertions
216
-
3. [ ] Register in `internal/config/config.go` with full @typescript-eslint/ prefix
217
-
4. [ ] Add to hardcoded list in `cmd/rslint/api.go`
218
-
5. [ ] Create test file in `packages/rslint-test-tools/tests/typescript-eslint/rules/`
219
-
6. [ ] Run `pnpm build` to compile everything
220
-
7. [ ] Run `pnpm test` to verify tests pass
221
-
8. [ ] Test manually with CLI: `cd packages/rslint/fixtures && ../bin/rslint src/test.ts`
222
-
9. [ ] Update test snapshots if needed: `pnpm test -u <rule-name>`
223
-
10. [ ] Run Go quality checks: `go vet ./cmd/... ./internal/...` and `go fmt ./cmd/... ./internal/...`
224
-
11. [ ] Run Go unit tests: `go test -parallel 4 ./internal/...`
225
-
12. [ ] Run TypeScript type checking: `pnpm tsc -b tsconfig.json`
226
-
13. [ ] Run all tests: `pnpm test`
227
-
14. [ ] Run linting checks: `pnpm run lint`
228
-
15. [ ] Ensure CI passes (golangci-lint, all tests)
221
+
3. [ ] Create comprehensive Go tests in `internal/rules/<rule_name>/<rule_name>_test.go`
222
+
4. [ ] Register in `internal/config/config.go` with full @typescript-eslint/ prefix
223
+
5. [ ] Add to hardcoded list in `cmd/rslint/api.go`
8. Document any special behavior or options in the rule implementation
245
+
**Primary Validation (Must Pass)**:
246
+
247
+
1. Go tests pass: `go test ./internal/rules/<rule_name>/`
248
+
2. Go quality checks: `go vet ./cmd/... ./internal/...` and `go fmt ./cmd/... ./internal/...`
249
+
3. All Go tests pass: `go test -parallel 4 ./internal/...`
250
+
4. Manual CLI testing works
251
+
252
+
**Secondary Validation**: 5. TypeScript type checking: `pnpm tsc -b tsconfig.json` 6. Linting checks: `pnpm run lint` 7. Integration tests: `pnpm test` (note: some TypeScript test position mismatches are acceptable if Go tests pass) 8. Document any special behavior or options in the rule implementation
253
+
254
+
**Key Principle**: Go implementation and tests are the source of truth. TypeScript tests are integration tests that may have minor position differences.
0 commit comments