Skip to content

[PROTOTYPE] Enforce code styles in build - #3144

Draft
alzimmermsft wants to merge 4 commits into
microsoft:mainfrom
alzimmermsft:EnforceCodeStylesInBuild
Draft

[PROTOTYPE] Enforce code styles in build#3144
alzimmermsft wants to merge 4 commits into
microsoft:mainfrom
alzimmermsft:EnforceCodeStylesInBuild

Conversation

@alzimmermsft

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes some changes to the build to enforce code style rules while building the project and enabling more diagnostics to be raised.

GitHub issue number?

[Link to the GitHub issue this PR addresses]

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies. Follow the changelog entry guide
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes running the script ./eng/scripts/Process-PackageReadMe.ps1. See Package README
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated command list in servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • Updated test prompts in servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@vukelich vukelich left a comment

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.

Some just questions. Some subjective. A couple actual issues.

/// <item>
/// <description>
/// <see cref="IAzureTokenCredentialProvider"/> via <see cref="Authentication.AuthenticationServiceCollectionExtensions.AddSingleIdentityTokenCredentialProvider"/>.
/// This can be overridden using <see cref="Authentication.AuthenticationServiceCollectionExtensions.AddAzureTokenCredentialProvider"/>

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.

Are the lines about overriding no longer true? I believe I left those clues in the doc comments intentionally when adding this code due to some design issues at app start up.

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.

AuthenticationServiceCollectionExtensions.AddAzureTokenCredentialProvider doesn't exist as an API anymore, so unless this was something external I missed, this doesn't exist anymore.

/// <param name="subscription">The subscription ID or name</param>
/// <param name="retryPolicy">Optional retry policy configuration</param>
/// <param name="converter">Function to convert JsonElement to the target type</param>
/// <param name="tableName">Optional table name to query (default: "resources")</param>

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.

Do or don't: I'm torn on (default: "resources") in the doc comment.

From a maintainability stance, this can easily diverge from the code. Other places solve this by defining a static string or const string, so that both the code and the doc comment resolve to the same string value. For example, see IOptionsSnapshot<TOptions>.Get(String).

(Aside: If a const string, then the value can be used in the default parameter syntax because its compile-time. If static string, then it must be used in the method body BUT the value is a runtime value not a compiler-time value, which allows for dependent libraries to use the new value without being recompiled. The .NET Options.DefaultName is static.)

On the other hand, the "resources" table name does have direct ARG meaning, so it provides the reader some better understanding of the system.

Though, using that table is the default behavior of the ARG API. We could be fine with a null default value and let ARG's query engine do what it does. Switching to letting ARG handle it would be more scope than this code change wants, but it can be beneficial to reduce our own business logic when it exists downstream already.

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.

In this PR, I'd say let's leave it as-is, as it documents current behaviors and won't introduce scope creep. But I also agree with this comment, and I'm in the opinion that something this meaningful should require explicit interaction by the caller to indicate the table to query and we provide some canned consts to help. This has been a spot where we've seen a few bugs as the default was used but the needed ARG table was something else (hence why this is a parameter in the first place).

/// <param name="azureLocation">The Azure location for the resource.</param>
/// <param name="content">The content to create or update the resource with.</param>
/// <param name="jsonTypeInfo">The JSON type information for serialization.</param>
/// <param name="cancellationToken">Cancellation token</param>

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.

Minor: A cancellation token. fits a little better since the other parameters are also expressed as sentences.

I won't repeat this comment for each place that it's applicable. I'm sure the repo has inconsistent language for this parameter.

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.

Update: the language used is inconsistent in the repo. in .NET, and across lines added in this PR. Idk what to suggest or say.

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.

I may have left this to an agent to decide what to do. I'll work on making this consistent across what we own.

SetDefaultPollInterval();
}

[Conditional("DEBUG")]

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.

This is not necessarily equivalent to the previous code. Using [Conditional(...)] will include or omit invocations to the attached method, but it keeps the method body in the source code. If unused code paths are removed by other compliation configurations, then it'll be similar to what we had before.

What is the aim for this change? Was there an analyzers requiring it?

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.

The analyzers and IDEs get a bit weird on preprocessor blocks on properly conveying when code is still used. This was making it so they do understand this code does get used. The other option here was to have #pragma statements to disable analyzer rules that flag the code as unused.

No strong opinion on which to use here.

Comment thread tools/Azure.Mcp.Tools.AppService/src/Models/DiagnosisResult.cs
using Microsoft.Mcp.Core.Areas.Server.Options;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Extensions;
using Microsoft.Mcp.Core.Services.ProcessExecution;

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.

How'd this become needed?

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.

Doc references

Comment thread tools/Azure.Mcp.Tools.Functions/src/Services/Helpers/GitHubUrlValidator.cs Outdated
Comment thread tools/Azure.Mcp.Tools.KeyVault/src/Services/IKeyVaultService.cs Outdated
});
}

#pragma warning disable IDE0060 // Remove unused parameter

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.

Why the disable rather than remove string completionNote?

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.

This ties back to the only usage of the required tool parameter completion-note. This needs a deeper follow up than just deleting it (in my opinion).

@alzimmermsft
alzimmermsft requested a review from vukelich July 24, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants