Linter: Duration/Interval integer properties must include a unit suffix
- Dominant language
- TypeScript
- Stars
- 27
- Forks
- 90
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 164
Description
Parent: #4442
## Convention
**DO** End property or parameter names of type integer that represent intervals or durations with units, e.g. `MonitoringInterval` → `MonitoringIntervalInSeconds`. If value is not ISO 8601 duration/time, drop `Interval`/`Duration` suffix and use unit.
> Source: [Azure SDK for .NET Mgmt Naming Conventions](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/dev/Mgmt-Naming-Conventions.md)
## Observed today
A scan of `Azure/azure-rest-api-specs` (334 `client.tsp` files, 10,754 csharp-scoped `@@clientName` decorators) shows **79** decorators currently encoding this rule by hand. Examples:
- `diskSizeGB` → `DiskSizeInGB` (azurelargeinstance/resource-manager/Microsoft.AzureLargeInstance/AzureLargeInstance/client.tsp)
- `blockSizeBytes` → `BlockSizeInBytes` (azurestackhci/resource-manager/Microsoft.AzureStackHCI/StackHCIVM/client.tsp)
- `diskSizeGB` → `DiskSizeInGB` (azurestackhci/resource-manager/Microsoft.AzureStackHCI/StackHCIVM/client.tsp)
- `logicalSectorBytes` → `LogicalSectorInBytes` (azurestackhci/resource-manager/Microsoft.AzureStackHCI/StackHCIVM/client.tsp)
- `physicalSectorBytes` → `PhysicalSectorInBytes` (azurestackhci/resource-manager/Microsoft.AzureStackHCI/StackHCIVM/client.tsp)
- `memoryMB` → `MemoryInMB` (azurestackhci/resource-manager/Microsoft.AzureStackHCI/StackHCIVM/client.tsp)
## Proposed linter
**Detection**
Flag integer-typed properties whose name ends with `Interval`, `Duration`, `Timeout`, `Period`, or contains `Size`/`Length` without an `In` suffix. Allowed units: `InSeconds`, `InMilliseconds`, `InMs`, `InMinutes`, `InHours`, `InDays`, `InBytes`, `InKB`, `InMB`, `InGB`, `InTB`.
**Auto-fix**
Suggest `In` rename via `@@clientName`. Unit must be supplied by author or inferred from `@encode("seconds", int32)` etc.
**Scope**
The rule should be csharp-scoped — it only flags violations of the .NET convention, not the underlying TypeSpec name. It should suggest inserting a `@@clientName(..., "csharp")` override when the underlying TypeSpec name is intentional, or renaming the TypeSpec model when the convention applies cross-language.
## Acceptance criteria
- [ ] New lint rule registered in the appropriate ruleset (`@azure-tools/typespec-client-generator-core` or `@azure-tools/typespec-azure-resource-manager`).
- [ ] Doc page under `website/src/content/docs/docs/libraries/.../rules/`.
- [ ] Unit tests covering positive / negative cases and the auto-fix.
- [ ] A `.chronus/changes/` entry.
Contributor guide
Research direction
Start by inspecting existing lint rules and registration in @azure-tools/typespec-client-generator-core and @azure-tools/typespec-azure-resource-manager. Then review the rule documentation layout under website/src/content/docs/docs/libraries/.../rules/ and existing unit tests and .chronus/changes/ entries. Done means the csharp-scoped rule, positive and negative tests, auto-fix coverage, documentation page, and change entry are present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation, testing, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100