Skip to content

Commit

Permalink
[eslint-plugin] Allow OperationOptions in ts-naming-options rule (#…
Browse files Browse the repository at this point in the history
…32447)

and remove the linting suppression on it. Also adjust packages to suppress this rule more specifically.
  • Loading branch information
jeremymeng authored Jan 7, 2025
1 parent b2bfb66 commit f033ee6
Show file tree
Hide file tree
Showing 24 changed files with 32 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Requires client method options parameter types to be suffixed with `Options` and prefixed with the method name.

Exception: `OperationOptions` type is allowed when an operation doesn't need any custom options.

## Examples

### Good
Expand All @@ -17,6 +19,9 @@ class ServiceClient {
upsertItem(options: UpsertItemOptions): Item {
/* code to return instance of Item */
}
deleteItem(options: OperationOptions): void {
/* code to return instance of Item */
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default createRule({
const paramTypeName = typeAnnotation.typeName.name;
if (paramTypeName.endsWith("Options")) {
// check that parameter type is prefixed with method name
if (!optionsRegex.test(paramTypeName)) {
if (paramTypeName !== "OperationOptions" && !optionsRegex.test(paramTypeName)) {
const prefixKind = method.kind === "constructor" ? "class" : "method";
context.report({
node: param,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ ruleTester.run("ts-naming-options", rule, {
{
code: "class ExampleClient { createExample(options: CreateExampleOptions = {}) {}; };",
},
// OperationOptions is allowed
{
code: "class ExampleClient { public createExample(options: OperationOptions) {}; };",
},
// multiple methods
{
code: "class ExampleClient { createExample(options: CreateExampleOptions) {}; upsertExample(options: UpsertExampleOptions) {}; };",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export class CommunicationIdentityClient {
*/
public revokeTokens(
user: CommunicationUserIdentifier,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<void> {
return tracingClient.withSpan(
Expand All @@ -145,7 +144,6 @@ export class CommunicationIdentityClient {
*
* @param options - Additional options for the request.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
public createUser(options: OperationOptions = {}): Promise<CommunicationUserIdentifier> {
return tracingClient.withSpan(
"CommunicationIdentity-createUser",
Expand Down Expand Up @@ -197,7 +195,6 @@ export class CommunicationIdentityClient {
*/
public deleteUser(
user: CommunicationUserIdentifier,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<void> {
return tracingClient.withSpan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class TestCommunicationIdentityClient {
public async getTokenTest(
user: CommunicationUserIdentifier,
scopes: TokenScope[],
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<CommunicationAccessToken> {
// casting is a workaround to enable min-max testing
Expand All @@ -36,7 +35,6 @@ export class TestCommunicationIdentityClient {

public async revokeTokensTest(
user: CommunicationUserIdentifier,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<void> {
// casting is a workaround to enable min-max testing
Expand All @@ -47,7 +45,6 @@ export class TestCommunicationIdentityClient {
}

public async createUserTest(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<CommunicationUserIdentifier> {
// casting is a workaround to enable min-max testing
Expand All @@ -59,7 +56,6 @@ export class TestCommunicationIdentityClient {

public async createUserAndTokenTest(
scopes: TokenScope[],
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<CommunicationUserToken> {
// casting is a workaround to enable min-max testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.
/// <reference lib="esnext.asynciterable" />

/* eslint-disable @azure/azure-sdk/ts-naming-options */
import type { CommunicationTokenCredential } from "@azure/communication-common";
import {
createCommunicationAuthPolicy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.
/// <reference lib="esnext.asynciterable" />

/* eslint-disable @azure/azure-sdk/ts-naming-options */
import type { CommunicationTokenCredential } from "@azure/communication-common";
import {
createCommunicationAuthPolicy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/* eslint-disable @azure/azure-sdk/ts-naming-options */
import {
createCommunicationAuthPolicy,
isKeyCredential,
Expand Down Expand Up @@ -113,6 +112,7 @@ export class SipRoutingClient {
* Lists the SIP trunks.
* @param options - The options parameters.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
public listTrunks(options: ListSipTrunksOptions = {}): PagedAsyncIterableIterator<SipTrunk> {
const { span, updatedOptions } = tracingClient.startSpan(
"SipRoutingClient-listTrunks",
Expand Down Expand Up @@ -163,6 +163,7 @@ export class SipRoutingClient {
* Lists the SIP trunk routes.
* @param options - The options parameters.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
public listRoutes(options: ListSipRoutesOptions = {}): PagedAsyncIterableIterator<SipTrunkRoute> {
const { span, updatedOptions } = tracingClient.startSpan(
"SipRoutingClient-listRoutes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import type {
CreateHttpPollerOptions,
RunningOperation,
OperationResponse,
OperationState} from "@azure/core-lro";
import {
createHttpPoller,
OperationState,
} from "@azure/core-lro";
import { createHttpPoller } from "@azure/core-lro";

/**
* A simple poller that can be used to poll a long running operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class BasicClient {
/**
* Represents a consumer which receives a message, creates a new span for processing the message, and links
* the new span to the message span (via traceheader propagation).
* @param traceparentHeader The {@link https://www.w3.org/TR/trace-context/#traceparent-header} header of the remote operation.
* @param traceparentHeader - The {@link https://www.w3.org/TR/trace-context/#traceparent-header} header of the remote operation.
* @param options - The Operation Options.
*/
async withSpanLinks(traceparentHeader: string, options: OperationOptions = {}): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/* eslint-disable @azure/azure-sdk/ts-naming-options */
import type {
OperationOptions,
InternalClientPipelineOptions,
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/event-hubs/src/eventHubProducerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class EventHubProducerClient {
* @throws MessagingError if an error is encountered while sending a message.
* @throws Error if the underlying connection or sender has been closed.
*/
async sendBatch(batch: EventDataBatch, options?: OperationOptions): Promise<void>; // eslint-disable-line @azure/azure-sdk/ts-naming-options
async sendBatch(batch: EventDataBatch, options?: OperationOptions): Promise<void>;
async sendBatch(
batch: EventDataBatch | EventData[],
options: SendBatchOptions | OperationOptions = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ export class DocumentModelAdministrationClient {
ctx: OperationContext,
options: PollerOptions<State> & OperationOptions,
args: [flatResponse: unknown, error?: unknown],
) {
): void | undefined {
const retryAfterHeader = rawResponse.headers.get("retry-after");
// Convert the header value to milliseconds. If the header is not a valid number, then it is an HTTP
// date.
Expand Down Expand Up @@ -896,7 +896,6 @@ export class DocumentModelAdministrationClient {
*/
public getDocumentClassifier(
classifierId: string,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<DocumentClassifierDetails> {
return this._tracing.withSpan(
Expand Down Expand Up @@ -966,7 +965,6 @@ export class DocumentModelAdministrationClient {
*/
public deleteDocumentClassifier(
classifierId: string,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<void> {
return this._tracing.withSpan(
Expand Down
1 change: 1 addition & 0 deletions sdk/keyvault/keyvault-admin/src/accessControlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class KeyVaultAccessControlClient {
constructor(
vaultUrl: string,
credential: TokenCredential,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: AccessControlClientOptions = {},
) {
this.vaultUrl = vaultUrl;
Expand Down
3 changes: 2 additions & 1 deletion sdk/keyvault/keyvault-admin/src/settingsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export class KeyVaultSettingsClient {
* @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net`. You should validate that this URL references a valid Key Vault or Managed HSM resource. See https://aka.ms/azsdk/blog/vault-uri for details.
* @param credential - An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the \@azure/identity package to create a credential that suits your needs.
* @param options - options used to configure Key Vault API requests.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
constructor(vaultUrl: string, credential: TokenCredential, options: SettingsClientOptions = {}) {
this.vaultUrl = vaultUrl;

Expand Down Expand Up @@ -129,6 +129,7 @@ export class KeyVaultSettingsClient {
*
* @param options - the optional parameters.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
async getSettings(options: ListSettingsOptions = {}): Promise<ListSettingsResponse> {
const { settings } = await this.client.getSettings(this.vaultUrl, options);
return { settings: settings?.map(makeSetting) ?? [] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/// <reference lib="esnext.asynciterable" />

/* eslint-disable @azure/azure-sdk/ts-naming-options */
import type { InternalPipelineOptions } from "@azure/core-rest-pipeline";
import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
import type { FullOperationResponse, OperationOptions } from "@azure/core-client";
Expand Down Expand Up @@ -1495,6 +1494,7 @@ export class MetricsAdvisorAdministrationClient {
* ```
*/
public listDataSourceCredential(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: ListDataSourceCredentialsOptions = {},
): PagedAsyncIterableIterator<DataSourceCredentialEntityUnion, CredentialsPageResponse> {
const iter = this.listItemsOfDataSourceCredentials(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,6 @@ export class MetricsAdvisorClient {
public async getIncidentRootCauses(
detectionConfigId: string,
incidentId: string,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<GetIncidentRootCauseResponse> {
return tracingClient.withSpan(
Expand Down Expand Up @@ -1449,7 +1448,6 @@ export class MetricsAdvisorClient {
*/
public async addFeedback(
feedback: MetricFeedbackUnion,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<MetricFeedbackUnion> {
return tracingClient.withSpan(
Expand All @@ -1475,7 +1473,6 @@ export class MetricsAdvisorClient {
*/
public async getFeedback(
id: string,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: OperationOptions = {},
): Promise<MetricFeedbackUnion> {
return tracingClient.withSpan(
Expand Down
1 change: 0 additions & 1 deletion sdk/notificationhubs/notification-hubs/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import azsdkEslint from "@azure/eslint-plugin-azure-sdk";
export default azsdkEslint.config([
{
rules: {
"@azure/azure-sdk/ts-naming-options": "warn",
"n/no-unsupported-features/node-builtins": "off",
"n/no-process-exit": "off",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class NotificationHubsServiceClient implements NotificationHubsClientContext {
constructor(
connectionString: string,
hubName: string,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: NotificationHubsClientOptions = {},
) {
this.hubName = hubName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export class NotificationHubsClient {
*/
deleteRegistration(
registrationId: string,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: EntityOperationOptions = {},
): Promise<NotificationHubsResponse> {
return deleteRegistration(this._client, registrationId, options);
Expand All @@ -203,6 +204,7 @@ export class NotificationHubsClient {
* @returns A paged async iterable containing all of the registrations for the notification hub.
*/
listRegistrations(
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: RegistrationQueryLimitOptions = {},
): PagedAsyncIterableIterator<RegistrationDescription> {
return listRegistrationsMethod(this._client, options);
Expand All @@ -216,6 +218,7 @@ export class NotificationHubsClient {
*/
listRegistrationsByChannel(
channel: RegistrationChannel,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: RegistrationQueryLimitOptions = {},
): PagedAsyncIterableIterator<RegistrationDescription> {
return listRegistrationsByChannelMethod(this._client, channel, options);
Expand All @@ -229,6 +232,7 @@ export class NotificationHubsClient {
*/
listRegistrationsByTag(
tag: string,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: RegistrationQueryLimitOptions = {},
): PagedAsyncIterableIterator<RegistrationDescription> {
return listRegistrationsByTagMethod(this._client, tag, options);
Expand All @@ -242,6 +246,7 @@ export class NotificationHubsClient {
*/
sendBroadcastNotification(
notification: Notification,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: BroadcastSendNotificationOptions = {},
): Promise<NotificationHubsMessageResponse> {
return sendBroadcastNotificationMethod(this._client, notification, options);
Expand Down Expand Up @@ -350,6 +355,7 @@ export class NotificationHubsClient {
*/
beginSubmitNotificationHubJob(
notificationHubJob: NotificationHubJob,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: PolledOperationOptions = {},
): Promise<NotificationHubJobPoller> {
return beginSubmitNotificationHubJobMethod(this._client, notificationHubJob, options);
Expand Down
Loading

0 comments on commit f033ee6

Please sign in to comment.