Comments (4)
@PlagueHO I gave this a try to fix this one with PSSA custom rules. But can't seem to get it to report warnings in AppVeyor. 😞 I can see it being called three times as expected in Appveyor here.
Actually, when adding my code, the parameter custom rule stops working as well. But if I start Invoke-ScriptAnalyzer
locally all custom rules works. 🤔
Would you mind take a look at the code? It must be a simple mistake somewhere that I fail to see.
I have a test branch test-dscresource-tests here that should trigger each of the custom rule (all three Measue-* functions). It should trigger on MSFT_xCluster.pms1 as seen here johlju/FailoverClusterDsc@1a63b6d.
And the actually new custom rule is in this branch.
Tested it locally:
PS V:\Source\xFailOverCluster> Invoke-ScriptAnalyzer -Path .\DSCResources\MSFT_xCluster\MSFT_xCluster.psm1 -CustomRulePath ..\DscResource.Tests\DscResource.AnalyzerRules\DscResource.
AnalyzerRules.psm1
RuleName Severity FileName Line Message
-------- -------- -------- ---- -------
PSDSCDscTestsPresent Information MSFT_xClus 1 No tests found for resource 'MSFT_xCluster'
ter.psm1
PSDSCDscExamplesPresent Information MSFT_xClus 1 No examples found for resource 'MSFT_xCluster'
ter.psm1
PSDSCUseVerboseMessageInDSCResource Information MSFT_xClus 19 There is no call to Write-Verbose in DSC function ‘Get-Targe
ter.psm1 tResource’. If you are using Write-Verbose in a helper funct
ion, suppress this rule application.
DscResource.AnalyzerRules\Measure-F Warning MSFT_xClus 413 Functions should not have the open brace on the same line as
unctionBlockBraces ter.psm1 the function name. See https://github.com/PowerShell/DscRes
ources/blob/master/StyleGuidelines.md#one-newline-before-bra
ces
DscResource.AnalyzerRules\Measure-F Warning MSFT_xClus 469 Opening brace on function should be followed by a new line.
unctionBlockBraces ter.psm1 See https://github.com/PowerShell/DscResources/blob/master/S
tyleGuidelines.md#one-newline-after-opening-brace
DscResource.AnalyzerRules\Measure-F Warning MSFT_xClus 488 Opening brace on functions should only be followed by one ne
unctionBlockBraces ter.psm1 w line. See https://github.com/PowerShell/DscResources/blob/
master/StyleGuidelines.md#one-newline-after-opening-brace
DscResource.AnalyzerRules\Measure-P Warning MSFT_xClus 433 The [Parameter()] attribute must start with an upper case 'P
arameterBlockParameterAttribute ter.psm1 '. See https://github.com/PowerShell/DscResources/blob/maste
r/StyleGuidelines.md#correct-format-for-parameter-block
DscResource.AnalyzerRules\Measure-P Warning MSFT_xClus 495 A [Parameter()] attribute must be the first attribute of eac
arameterBlockParameterAttribute ter.psm1 h parameter and be on its own line. See https://github.com/P
owerShell/DscResources/blob/master/StyleGuidelines.md#correc
t-format-for-parameter-block
DscResource.AnalyzerRules\Measure-S Warning MSFT_xClus 449 Statements should not have the open brace on the same line a
tatementBlockBraces ter.psm1 s the statement. See https://github.com/PowerShell/DscResour
ces/blob/master/StyleGuidelines.md#one-newline-before-braces
DscResource.AnalyzerRules\Measure-S Warning MSFT_xClus 459 Opening brace on statements should be followed by a new line
tatementBlockBraces ter.psm1 . See https://github.com/PowerShell/DscResources/blob/master
/StyleGuidelines.md#one-newline-after-opening-brace
DscResource.AnalyzerRules\Measure-S Warning MSFT_xClus 463 Opening brace on statements should only be followed by one n
tatementBlockBraces ter.psm1 ew line. See https://github.com/PowerShell/DscResources/blob
/master/StyleGuidelines.md#one-newline-after-opening-brace
from dscresource.tests.
@PlagueHO When stripping code from the first function Measure-FunctionBlockBraces
called by Invoke-ScriptAnalyzer
the parameter rule is started to work again. It seems the code does something wrong at one point, maybe throws an error which is not shown anywhere. And that cause everything to fail.
Very strange that this works locally though. Investigating further. If you see something obvious I missed, then please let me know. :)
from dscresource.tests.
This one is making me scratch my head. 😄
So it seems that the the file locally has '\r\n' in the file, while the cloned one in AppVeyor has '\n'. Making sure the file is the same (replaced to '\n') regardless where it was run made thing to start work. Also, add check so it doesn't try to index into arrays that aren't long enough, that was one bug for other files than the one I tested on, but it was not thrown any errors. Now at the end of the day I realized that we starting Invoke-ScriptAnalyzer with 'SilentlyContinue'
so that can explain that it didn't throw any errors.
BUT, for some reason Measure-StatementBlockBraces
is reporting every line twice 😞 I have not been able to found out why yet. It works locally, and added the same code inside the Meta.Tests.ps1 just to be able to debug, but it works there as well.
https://ci.appveyor.com/project/johlju/xfailovercluster/build/1.6.216.0#L274
# ---- LINE 449
VERBOSE: if ( $true ) {
VERBOSE: Found: StatementOpeningBraceNotOnSameLine
# ---- LINE 459
VERBOSE: { Write-Verbose 'Hello for the third tme' -Verbose
VERBOSE: Found: StatementOpeningBraceShouldBeFollowedByNewLine
# ---- LINE 463
VERBOSE:
VERBOSE: Found: StatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
But ScriptAnalyzer is returning double entries in AppVeyor.
MSFT_xCluster.psm1 (Line 449): Statements should not have the open brace on the same line as the statement. See https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#one-newline-before-braces
MSFT_xCluster.psm1 (Line 459): Opening brace on statements should be followed by a new line. See https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#one-newline-after-opening-brace
MSFT_xCluster.psm1 (Line 463): Opening brace on statements should only be followed by one new line. See https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#one-newline-after-opening-brace
MSFT_xCluster.psm1 (Line 449): Statements should not have the open brace on the same line as the statement. See https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#one-newline-before-braces
MSFT_xCluster.psm1 (Line 459): Opening brace on statements should be followed by a new line. See https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#one-newline-after-opening-brace
MSFT_xCluster.psm1 (Line 463): Opening brace on statements should only be followed by one new line. See https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#one-newline-after-opening-brace
Locally, with the exact same version (latest) as AppVeyor it works
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSDSCDscTestsPresent Information MSFT_xClus 1 No tests found for resource 'MSFT_xCluster'
ter.psm1
PSDSCDscExamplesPresent Information MSFT_xClus 1 No examples found for resource 'MSFT_xCluster'
ter.psm1
PSDSCUseVerboseMessageInDSCResource Information MSFT_xClus 19 There is no call to Write-Verbose in DSC function ‘Get-Targe
ter.psm1 tResource’. If you are using Write-Verbose in a helper funct
ion, suppress this rule application.
DscResource.AnalyzerRules\Measure-F Warning MSFT_xClus 413 Functions should not have the open brace on the same line as
unctionBlockBraces ter.psm1 the function name. See https://github.com/PowerShell/DscRes
ources/blob/master/StyleGuidelines.md#one-newline-before-bra
ces
DscResource.AnalyzerRules\Measure-F Warning MSFT_xClus 469 Opening brace on function should be followed by a new line.
unctionBlockBraces ter.psm1 See https://github.com/PowerShell/DscResources/blob/master/S
tyleGuidelines.md#one-newline-after-opening-brace
DscResource.AnalyzerRules\Measure-F Warning MSFT_xClus 488 Opening brace on functions should only be followed by one ne
unctionBlockBraces ter.psm1 w line. See https://github.com/PowerShell/DscResources/blob/
master/StyleGuidelines.md#one-newline-after-opening-brace
DscResource.AnalyzerRules\Measure-P Warning MSFT_xClus 433 The [Parameter()] attribute must start with an upper case 'P
arameterBlockParameterAttribute ter.psm1 '. See https://github.com/PowerShell/DscResources/blob/maste
r/StyleGuidelines.md#correct-format-for-parameter-block
DscResource.AnalyzerRules\Measure-P Warning MSFT_xClus 495 A [Parameter()] attribute must be the first attribute of eac
arameterBlockParameterAttribute ter.psm1 h parameter and be on its own line. See https://github.com/P
owerShell/DscResources/blob/master/StyleGuidelines.md#correc
t-format-for-parameter-block
DscResource.AnalyzerRules\Measure-S Warning MSFT_xClus 449 Statements should not have the open brace on the same line a
tatementBlockBraces ter.psm1 s the statement. See https://github.com/PowerShell/DscResour
ces/blob/master/StyleGuidelines.md#one-newline-before-braces
DscResource.AnalyzerRules\Measure-S Warning MSFT_xClus 459 Opening brace on statements should be followed by a new line
tatementBlockBraces ter.psm1 . See https://github.com/PowerShell/DscResources/blob/master
/StyleGuidelines.md#one-newline-after-opening-brace
DscResource.AnalyzerRules\Measure-S Warning MSFT_xClus 463 Opening brace on statements should only be followed by one n
tatementBlockBraces ter.psm1 ew line. See https://github.com/PowerShell/DscResources/blob
/master/StyleGuidelines.md#one-newline-after-opening-brace
from dscresource.tests.
Finally! This was me being a newbie with Script Analyzer (and AST). The problem was that it calls the measure function for each script block. I thought that was the entire file because that is how it behaved locally. But in AppVeyor it was called first for the entire file, then for each function statement script block (why it didn't do that locally is still a mystery).
This has been nagging me for days... Finally I can send in a PR for this! 😄
from dscresource.tests.
Related Issues (20)
- Nuget Spec Generated by AppVeyor invalid for PS Module Repository HOT 1
- Additional localization tests
- When opt-in to markdown links check, the cloned DscResource.Tests is also checked HOT 1
- Remove manual step in auto-documentation HOT 1
- Auto-documentation should document helper functions inside the Modules folder HOT 4
- Refactor DscResource.DocumentationHelper/PowerShellHelp.psm1/New-DscResourcePowerShellHelp
- New-DscResourcePowerShellHelp: Should output the help keyword .EXAMPLE in upper-case HOT 1
- Test-PublishMetadata: Exception Raised If the Example being tested has an invalid GUID
- Invoke-AppveyorAfterTestTask: Exception Calling New-DscResourcePowerShellHelp when Type is 'Wiki' HOT 2
- Wikik documentation should separate read-only parameters from the parameters table
- Wiki documentation should create code quotes for variables in parameter descriptions
- New-DscResourcePowerShellHelp: Generates white space on blank rows in the .DESCRIPTION section
- New-DscResourcePowerShellHelp: Files are generated as UTF-8 with BOM
- The custom rules should be listed and reference the style guideline rule it belongs to HOT 1
- Code formatting: newlines before and after if statement block HOT 1
- Add Tests to Ensure DSC Resource Names are added to DSCResourcesToExport in Manifest
- Generation of Wikipages throws an error HOT 3
- New-DscResourceWikiSite: Array DataTypes Have Changed Format HOT 3
- Get-MofSchemaObject: Credential Attribute Output DataType has Changed
- Common Tests - File Formatting: References missing cmdlets HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dscresource.tests.