Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add use-safe-access linter rule #14322

Merged
merged 2 commits into from
Jun 17, 2024
Merged

Add use-safe-access linter rule #14322

merged 2 commits into from
Jun 17, 2024

Conversation

anthony-c-martin
Copy link
Member

@anthony-c-martin anthony-c-martin commented Jun 14, 2024

Recommends against the following:

var test = contains(foo, 'bar') ? foo.bar : 'baz'

And instead suggests:

var test = foo.?bar ?? 'baz'
Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

github-actions bot commented Jun 14, 2024

Test this change out locally with the following install scripts (Action run 9552149357)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 9552149357
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 9552149357"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 9552149357
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 9552149357"

Copy link
Contributor

github-actions bot commented Jun 14, 2024

Dotnet Test Results

    72 files   -     36      72 suites   - 36   23m 38s ⏱️ - 10m 19s
10 889 tests  -     12  10 888 ✅  -     12  1 💤 ±0  0 ❌ ±0 
25 674 runs   - 12 809  25 672 ✅  - 12 808  2 💤  - 1  0 ❌ ±0 

Results for commit 2b2dc9e. ± Comparison against base commit 1a695a1.

♻️ This comment has been updated with latest results.


[TestMethod]
public void Codefix_fixes_syntax_which_can_be_simplified() => AssertCodeFix("""
param foo object
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Since """ removes leading spaces, it would be nice to have these indented.

Copy link
Member Author

Choose a reason for hiding this comment

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

My preference is not to indent, even though it is supported by C#. For some tests, the preceding whitespace is meaningful to Bicep. I also like to be able to copy+paste directly from .bicep file <-> code block; I find the formatting is often broken by the editor when attempting to indent.

@StephenWeatherford
Copy link
Contributor

nice

Copy link
Contributor

@StephenWeatherford StephenWeatherford left a comment

Choose a reason for hiding this comment

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

Don't forget to add a bug for documentation thx

[TestMethod]
public void Rule_ignores_syntax_which_cannot_be_simplified() => AssertNoDiagnostics("""
param foo object
var test = contains(foo, 'bar') ? foo.baz : 'baz'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is property access in Azure case-sensitive?

Copy link
Contributor

Choose a reason for hiding this comment

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

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants