| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Just as a note... I did attempt to use reflection rather than a hard-coded list of keywords. The keyword list is in the Tokenizer. public static HashSet<string> GetReservedWordsFromTokenizer()
{
// Get the assembly containing Tokenizer
var asm = typeof(Token).Assembly;
// Get the internal Tokenizer type
var tokenizerType = asm.GetType("System.Management.Automation.Language.Tokenizer");
// Get the private static readonly field s_keywordTokenKind
var field = tokenizerType.GetField("s_keywordTokenKind", BindingFlags.NonPublic | BindingFlags.Static);
// Get the TokenKind[] value
var tokenKinds = field.GetValue(null) as Array;
var reservedWords = new HashSet<string>(
tokenKinds.Cast<Enum>().Select(tk => tk.ToString()),
StringComparer.OrdinalIgnoreCase
);
return reservedWords;
}With similar on the PowerShell side for the tests. This worked fine in PS7 but I can't seem to get it to work in PS5.1 - I can't access the s_keywordTokenKind or s_keywordText field. |
Sorry, something went wrong.
That makes sense to me. We've run into similar issues in PSES because the visibility of some of them changed making them available through reflection in PS7 but still not in PS5.1. Oh well 🫠 |
Sorry, something went wrong.
There was a problem hiding this comment.
Patrick Meinecke (@SeeminglyScience) can you take a look at this too? Seems pretty good to me and reasonable to add as a default.
Sorry, something went wrong.
…ed word, and reserved word with a letter missing
…st for good measure
Co-authored-by: Andy Jordan <2226434+andyleejordan@users.noreply.github.com>
There was a problem hiding this comment.
I'm good with this, just want Patrick Meinecke (@SeeminglyScience) to double check. I'll send it his way.
Sorry, something went wrong.
There was a problem hiding this comment.
Definitely a useful rule, ty Liam! Couple of small changes
Sorry, something went wrong.
…bility Co-authored-by: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
assembly, base, command, hidden, in, inlinescript, interface, module, namespace, private, public, static
|
We did it, high-fives all round 🫸🫷 |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM!
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
Adds a new rule that warns when reserved words are used as function names.
Fixes #2099
I wrote a blog post about putting this together 😀
PR Checklist