GithubHelp home page GithubHelp logo

Comments (4)

johlju avatar johlju commented on July 30, 2024

@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.

johlju avatar johlju commented on July 30, 2024

@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.

johlju avatar johlju commented on July 30, 2024

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.

johlju avatar johlju commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.