Skip to content

Add linter rule to block service namespace redefinition in client.tsp#4869

Draft
timotheeguerin with Copilot wants to merge 6 commits into
mainfrom
copilot/add-linter-rule-for-client-tsp
Draft

Add linter rule to block service namespace redefinition in client.tsp#4869
timotheeguerin with Copilot wants to merge 6 commits into
mainfrom
copilot/add-linter-rule-for-client-tsp

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

client.tsp customizations were increasingly reopening the service namespace and injecting new models or operations into the service surface. This change adds a client-generation linter rule to keep client customizations API-neutral: use augment decorators for service types, and put new helper types outside the service namespace.

  • New TCGC rule

    • Adds @azure-tools/typespec-client-generator-core/no-service-namespace-redefinition
    • Reports when client.tsp declares:
      • the service namespace itself
      • any child namespace under the service namespace
    • Allows valid customization patterns such as:
      • @@... augment decorators
      • separate namespaces like Customizations
  • Ruleset enablement

    • Enables the new rule in Azure data-plane and resource-manager rulesets so it applies to client-customized specs by default
  • Docs and examples

    • Adds rule documentation and updates generated linter reference tables
    • Documents the intended split between service definitions and client-only customization code
  • Coverage

    • Adds focused tests for:
      • valid augment-only client.tsp
      • valid helper types in Customizations
      • invalid redefinition of the service namespace
      • invalid declaration of child namespaces under the service namespace

Example:

// main.tsp
@service
namespace Contoso.Widget;

// client.tsp
import "./main.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;
using Contoso.Widget;

namespace Customizations;

model WidgetClientOptions {
  mode: string;
}

@@clientName(Widget.name, "widgetName");

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added int:azure-specs Run integration tests against azure-rest-api-specs lib:tcgc Issues for @azure-tools/typespec-client-generator-core library meta:website TypeSpec.io updates linter Issues related to linter rules labels Jul 10, 2026
- "@azure-tools/typespec-azure-rulesets"
---

Add `no-service-namespace-redefinition` linter rule to prevent `client.tsp` from reopening the service namespace or its child namespaces. Enable the rule in the Azure data-plane and resource-manager rulesets.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot suggest some other names, this doesn't feel specific enough, thinking it should be more related to client(like use-client-namespace-isolation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 1fb8c05 — I renamed the rule to use-client-namespace-isolation across the implementation, tests, rulesets, and docs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I asked for suggestion not to rename yet

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please reply with an answer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some options I think fit better are:

  • use-client-namespace-isolation
  • keep-client-customizations-outside-service-namespace
  • prevent-service-namespace-reopening-in-client
  • no-client-service-namespace-redefinition

My preference is use-client-namespace-isolation if you want it phrased as guidance rather than as a prohibition.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot what about no-service-ns-in-client, lets use that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in efbcfad.

Copilot AI changed the title [WIP] Add linter rule to prevent redefining the service namespace in client.tsp Add linter rule to block service namespace redefinition in client.tsp Jul 10, 2026
Copilot AI requested a review from timotheeguerin July 10, 2026 14:39
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Jul 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-azure-rulesets@4869
npm i https://pkg.pr.new/@azure-tools/typespec-client-generator-core@4869

commit: efbcfad

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@timotheeguerin

Copy link
Copy Markdown
Member

@copilot format

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot format

Fixed in e22d38d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

int:azure-specs Run integration tests against azure-rest-api-specs lib:tcgc Issues for @azure-tools/typespec-client-generator-core library linter Issues related to linter rules meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add linter rule to prevent redefining the service namespace in client.tsp

2 participants