Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script Analyzer test should make use of multiple custom rule paths #100

Open
johlju opened this issue Jan 30, 2021 · 2 comments
Open

Script Analyzer test should make use of multiple custom rule paths #100

johlju opened this issue Jan 30, 2021 · 2 comments
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.

Comments

@johlju
Copy link
Member

johlju commented Jan 30, 2021

The PSSA test source/Tests/QA/PSSAResource.common.Tests.ps1 currently ignores a repository's Script Analyzer file. I Script Analyzer file can be used to add additional custom rules that should only be run for the repository.

Script Analyzer is run with a settings file like this.

Invoke-ScriptAnalyzer -Path .\output\SqlServerDsc\15.0.1\DSCResources\**\*.psm1 -Recurse -Settings .\.vscode\analyzersettings.psd1

But a better option would be to allow custom rule paths to be specified in the build configuration file build.yml under the key DscTest: together with an option to include additional rules (if the rules are not prefixed with Measue-*).

The custom rule paths that is set must point to one or more module or module files. Since Script Analyzer must be called like this:

Invoke-ScriptAnalyzer `
    -Path .\output\SqlServerDsc\15.0.1\DSCResources\DSC_SqlTraceFlag\*.psm1 `
    -CustomRulePath @(
        '.\output\RequiredModules\DscResource.AnalyzerRules'
        '.\tests\QA\AnalyzerRules\SqlServerDsc.AnalyzerRules.psm1'
     ) `
    -IncludeRule @('Measure-*')
@johlju johlju added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Jan 30, 2021
@johlju johlju changed the title Script Analyzer test should make use of Script Analyzer settings file Script Analyzer test should make use of multiple custom rule paths Jan 30, 2021
@gaelcolas
Copy link
Member

I have mixed feelings about this.
Adding extra files/rules, ok why not but it should not conflict/replace HQRM tests (that's the goal here, after all).
So if someone wants to amend the HQRM tests being run for a pipeline, it should only been done via the build.yaml so that it's clear from a reviewer's perspective.

@johlju
Copy link
Member Author

johlju commented May 4, 2021

We could definitely add an array of analyzer rules to the build.yaml. The scenario is that we added repository specific analyzer rules to the SqlServerDsc repo:

https://github.com/dsccommunity/SqlServerDsc/blob/main/tests/QA/AnalyzerRules/SqlServerDsc.AnalyzerRules.psm1

As a workaround we added a test that runs the analyzer rules:

Analyzer rules: https://github.com/dsccommunity/SqlServerDsc/blob/main/tests/QA/ScriptAnalyzer.Tests.ps1

The QA test is run in the pipeline here: https://github.com/dsccommunity/SqlServerDsc/blob/49f78a8b12c0f540ef76cdcbf6605fffa30c17fa/azure-pipelines.yml#L65-L70

It would have been cleaner that these were run during the regular HQRM tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

2 participants