PowerShell / PowerShell/PSScriptAnalyzer

Disable PSSA or supress all rules for **one** file without excluding path in settings.psd1?

Offen
#2,067 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Up for Grabs
Vorherrschende Sprache
C#
Sterne
2.2k
Forks
414
Ø Merge
13 Std. 1 Min.
Gemergte PRs (30 T.)
2

Beschreibung

^ These links either isn't relevant anymore (first one, it's moved to Discord, right?), or does not work (the two others)


Say I have a script I'm just using for inspiration, I have no plans of iterating and improving it.

We can use [Diagnostics.CodeAnalysis.SuppressMessageAttribute()] to supress one rule. We can not use wildcard ( [Diagnostics.CodeAnalysis.SuppressMessageAttribute('*','')] ) to suppress all rules, I've tried.

Is it possible to disable PSSA or suppress all rules for one script/file, from inside that file? I don't want to hardcode paths in global PSSA settings.

To get PSSA and VSCode "Problems" tab to stay quiet I now have all these in top of the script:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Used to output text with color')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseLiteralInitializerForHashtable','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]

This is with the following Microsoft maintained script btw.:

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Überprüfung von settings.psd1 und der bestehenden Behandlung von Diagnostics.CodeAnalysis.SuppressMessageAttribute. Überprüfe anschließend den Ordner RuleDocumentation und das gemeldete Verhalten von VSCode Problems. Als erledigt gilt die Aufgabe, wenn ein einzelnes Skript PSScriptAnalyzer deaktivieren oder alle Regeln aus dieser Datei heraus unterdrücken kann, ohne ihren Pfad zu den globalen Einstellungen hinzuzufügen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
powershell
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.