PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.85k stars 373 forks source link

Add a linter warning for special quote characters #1880

Closed notgriffin closed 1 year ago

notgriffin commented 1 year ago

Prerequisites

Summary

Users who copy and paste code may inadvertently grab special quote characters and not normal quote characters. The linter should warn that special quotes were used to surround a string. Otherwise the code will likely error out.

Proposed Design

Add a linting rule to warn when special quote characters are used to surround a string

StevenBucher98 commented 1 year ago

Thanks for the issue @notgriffin! Do you want " as the default normal quote character? Or maybe this enhancement can allow you to choose which one is correct

StevenBucher98 commented 1 year ago

@notgriffin Was this something you had a problem with? The PowerShell parser does some work to help manage the different quote characters.

notgriffin commented 1 year ago

Hi @StevenBucher98! Yes the " U+0022 and/or ' U+0027 should be the default quote character. This was something I had a problem with where the linter did not flag this as an issue even though it was causing code issues. The linter I think should not error on any of the following unicode character values when quoting a string: U+201C, U+201D, U+201F, U+2019, U+301D, U+301E, U+301F, U+FF02, U+201A, U+2018, U+201B, U+2758, or U+275C.

bergmeister commented 1 year ago

The specific input is useful but me it feels like issue #1436 already covers this

notgriffin commented 1 year ago

Yeah I guess it covers it to come degree, although I think that issue should then be expanded to include the characters I specified above.

bergmeister commented 1 year ago

yes, that's what I meant by 'your specific is useful', can you comment this on the other issue please and we close this as a duplicate?