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

Validate the value for using namespace during semantic checks to prevent declaring invalid namespaces #21162

Merged
merged 3 commits into from Feb 1, 2024

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Jan 31, 2024

PR Summary

Fixes #17113
Validate the value for using namespace during semantic checks to prevent declaring invalid namespaces.

This PR is to supersede #19134. Thanks @MartinGC94 and @iSazonov for the initial investigation of the regular expression used to validate the namespace values!

I think the right place for doing the check should be in SemanticChecks, so that the AST generated from using statement is unchanged, so there is no need to make changes to tab completion code.

Parsing error thrown at the semantic check stage

image

AST is unchanged from the parsing

image

About @JamesWTruher's concern expressed in #19134 (comment), the relevant code is as follows.
The variable typeName is of the type TypeName, so typeName.Name must be a valid type name. Therefore, as long as ns, the namespace value, is valid, the newTypeNameToSearch should be valid. By preventing the declaration of any invalid namespace names, we can guarantee new TypeName(...) won't throw here, so I think we don't need to make any changes here.

var newTypeNameToSearch = ns + "." + typeName.Name;
newTypeNameToSearch = typeResolutionState.GetAlternateTypeName(newTypeNameToSearch) ??
newTypeNameToSearch;
var newTypeName = new TypeName(typeName.Extent, newTypeNameToSearch);

PR Checklist

This comment was marked as outdated.

1 similar comment

This comment was marked as outdated.

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM.

This PR has 30 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +23 -7
Percentile : 12%

Total files changed: 3

Change summary by file extension:
.cs : +16 -7
.resx : +3 -0
.ps1 : +4 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@daxian-dbw daxian-dbw added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Jan 31, 2024
@daxian-dbw daxian-dbw merged commit 783fb46 into PowerShell:master Feb 1, 2024
38 checks passed
@daxian-dbw daxian-dbw deleted the namespace branch February 1, 2024 17:42
Copy link
Contributor

microsoft-github-policy-service bot commented Feb 1, 2024

📣 Hey @daxian-dbw, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

dkattan pushed a commit to dkattan/PowerShell that referenced this pull request Feb 19, 2024
xtqqczze pushed a commit to xtqqczze/PowerShell that referenced this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Extra Small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PSReadLine throws an exception when typing a type name after using namespace [NameSpace]
2 participants