Repository navigation
Lint missing diagnostic formatting arguments - #65103
Conversation
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
…pers Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
|
Copilot Fix the missing argument as described here tsc/internal/checker/checker.go:9477:20: diagnosticargs: diagnostic Type_0_does_not_satisfy_the_constraint_1 requires at least 2 formatting arguments, got 0 (customlint) |
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
|
Copilot you should be using a baseline test, not a unit test, for this change |
Fixed in e9f7e8c: the diagnostic now receives the type argument and instantiated constraint. Added a regression test that fails before the fix. All tests passed; |
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Replaced the unit test and test-only checker export with a compiler fixture and diagnostic/type/symbol baselines in 91eb495. Tests pass; |
There was a problem hiding this comment.
🟡 Changes recommended
The lint rule misses missing formatting arguments in method-expression localization calls and named callback calls, leaving production usage patterns unchecked.
2 open issues
What changed in this PR
Adds preventive linting for missing diagnostic formatting arguments in the native TypeScript compiler and fixes argument formatting in a type-constraint diagnostic chain. Circular-config behavior remains unchanged.
Changes:
- Registers an analyzer that derives required argument counts from diagnostic placeholders.
- Adds golden fixtures for diagnostic calls, wrappers, and localization methods.
- Supplies type and constraint arguments in the checker, with compiler regression coverage.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/typeArgumentConstraintDiagnostic.ts |
Adds type-constraint diagnostic cases. |
tsc/testdata/baselines/reference/compiler/typeArgumentConstraintDiagnostic.types |
Records inferred types. |
tsc/testdata/baselines/reference/compiler/typeArgumentConstraintDiagnostic.symbols |
Records symbol bindings. |
tsc/testdata/baselines/reference/compiler/typeArgumentConstraintDiagnostic.errors.txt |
Records expected constraint errors. |
tsc/internal/checker/checker.go |
Supplies missing diagnostic formatting arguments. |
tools/customlint/testdata/internal/diagnostics/diagnostics.go.golden |
Records the diagnostic fixture baseline. |
tools/customlint/testdata/internal/diagnostics/diagnostics.go |
Defines diagnostic messages for lint tests. |
tools/customlint/testdata/diagnosticargs/diagnosticargs.go.golden |
Records expected lint reports. |
tools/customlint/testdata/diagnosticargs/diagnosticargs.go |
Exercises formatting-argument checks and exclusions. |
tools/customlint/plugin.go |
Registers the new analyzer. |
tools/customlint/diagnosticargs.go |
Implements diagnostic formatting-argument checks. |
Review effort: Balanced
| if call.Ellipsis.IsValid() { | ||
| return | ||
| } | ||
| signature, ok := pass.TypesInfo.TypeOf(call.Fun).(*types.Signature) |
| if selection != nil && selection.Kind() == types.MethodVal && | ||
| isDiagnosticMessage(selection.Recv()) && selector.Sel.Name == "Localize" { | ||
| check(call, selector.X, len(call.Args)-fixed) | ||
| } |
|
Copilot review will repeatedly come back with infinite lint rule tweaks; feel free to decide a stopping point and say "good enough" |
|
This found one true positive and zero false positives so that's my "good enough" |

TS18000 leaves
{0}unsubstituted because its diagnostic constructor receives no formatting arguments. This adds preventive linting without changing circular-config behavior.message, args...calls and localization methods. Allow extra arguments; skip unknown messages and expanded slices.