Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs (C#)

Code before:
                bool inParameterSet = (param.Parameter.ParameterSetFlags & validParameterSetFlags) != 0 || param.Parameter.IsInAllSets;
                if (!inParameterSet)
                    continue;

                string name = param.Parameter.Name;
                string type = "[" + ToStringCodeMethods.Type(param.Parameter.Type, dropNamespaces: true) + "] ";
                string helpMessage = null;
                bool isCommonParameter = Cmdlet.CommonParameters.Contains(name, StringComparer.OrdinalIgnoreCase);
                List<CompletionResult> listInUse = isCommonParameter ? commonParamResult : result;

                if (pattern.IsMatch(name))
                {
                    // Then using functions to back dynamic keywords, we don't necessarily
                    // want all of the parameters to be shown to the user. Those that are marked
                    // DontShow will not be displayed. Also, if any of the parameters have
                    // don't show set, we won't show any of the common parameters either.
                    bool showToUser = true;
                    var compiledAttributes = param.Parameter.CompiledAttributes;
                    if (compiledAttributes != null && compiledAttributes.Count > 0)
                    {
                        foreach (var attr in compiledAttributes)
                        {
                            if (attr is not ParameterAttribute pattr)
                            {
                                continue;
                            }
                            if (pattr.DontShow)
                            {
                                showToUser = false;
                                addCommonParameters = false;
                                break;
                            }

                            if (string.IsNullOrWhiteSpace(helpMessage))
                            {
                                helpMessage = GetParameterHelpMessage(pattr, commandAssembly);    
                            }
                        }
                    }

                    if (showToUser)
                    {
                        string completionText = "-" + name + colonSuffix;
                        string tooltip = string.IsNullOrWhiteSpace(helpMessage)
                            ? $"{type}{name}"
                            : $"{type}{name} - {helpMessage}";
                        listInUse.Add(new CompletionResult(completionText, name, CompletionResultType.ParameterName,
                                                           tooltip));
                    }
                }
                else if (parameterName != string.Empty)

Review comment (suggestion):
It is good using fast return in large methods but here too short code. Please use the usual condition:
```suggestion
                            if (attr is ParameterAttribute pattr)
                            {
                                if (pattr.DontShow)
                                {
                                    ...
                                }
                                
                                ...
                            }
```

Code after:
            uint validParameterSetFlags,
            IEnumerable<MergedCompiledCommandParameter> parameters,
            bool withColon,
            Assembly commandAssembly = null)
        {
            var result = new List<CompletionResult>();
            var commonParamResult = new List<CompletionResult>();
            var pattern = WildcardPattern.Get(parameterName + "*", WildcardOptions.IgnoreCase);
            var colonSuffix = withColon ? ":" : string.Empty;

            bool addCommonParameters = true;
            foreach (MergedCompiledCommandParameter param in parameters)
            {
                bool inParameterSet = (param.Parameter.ParameterSetFlags & validParameterSetFlags) != 0 || param.Parameter.IsInAllSets;
                if (!inParameterSet)
                    continue;

                string name = param.Parameter.Name;
                string type = "[" + ToStringCodeMethods.Type(param.Parameter.Type, dropNamespaces: true) + "] ";
                string helpMessage = null;
                bool isCommonParameter = Cmdlet.CommonParameters.Contains(name, StringComparer.OrdinalIgnoreCase);
                List<CompletionResult> listInUse = isCommonParameter ? commonParamResult : result;

                if (pattern.IsMatch(name))
                {
                    // Then using functions to back dynamic keywords, we don't necessarily
                    // want all of the parameters to be shown to the user. Those that are marked
                    // DontShow will not be displayed. Also, if any of the parameters have
                    // don't show set, we won't show any of the common parameters either.
                    bool showToUser = true;
                    var compiledAttributes = param.Parameter.CompiledAttributes;
                    if (compiledAttributes != null && compiledAttributes.Count > 0)
                    {
                        foreach (var attr in compiledAttributes)
                        {
                            if (attr is ParameterAttribute pattr)
                            {
                                if (pattr.DontShow)
                                {
                                    showToUser = false;
                                    addCommonParameters = false;
                                    break;
                                }
                                
                                if (helpMessage is null && TryGetParameterHelpMessage(pattr, commandAssembly, out string attrHelpMessage))
                                {
                                    helpMessage = $" - {attrHelpMessage}";
                                }
                            }
                        }
                    }