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

If no path is found or when using the -ScriptDefinition parameter set, default to the current location for the directory search of the implicit settings file #979

Conversation

@bergmeister
Copy link
Collaborator

bergmeister commented Apr 25, 2018

PR Summary

Fixes #978. This allows usage of the implicit settings file when using the -ScriptDefinition parameter (or avoid a misleading error message about setting parsing when no file is found to be analysed). When no file path was found using the -Path option or using the -ScriptDefinition parameter set, the search for implicit setting files used to rely on a path being present. This PR fixes it to fallback to the current working directory as a search directory for implicit setting file.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets. Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • User facing documentation needed
  • Change is not breaking
  • Make sure you've added a new test if existing tests do not effectively test the code changed
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready
bergmeister added 3 commits Apr 25, 2018
…, default to the current location for the directory search of the implicit settings file
@bergmeister bergmeister changed the title WIP If no path is found or when using the -ScriptDefinition parameter set, default to the current location for the directory search of the implicit settings file If no path is found or when using the -ScriptDefinition parameter set, default to the current location for the directory search of the implicit settings file Apr 25, 2018
@bergmeister bergmeister self-assigned this Apr 26, 2018
@bergmeister bergmeister requested a review from kalgiz Apr 26, 2018
$violations = Invoke-ScriptAnalyzer -Path $project1Root -Recurse
$violations.Count | Should -Be 1
$violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases"
}

It "runs rules from the implicit setting file using the -ScriptDefinition parameter set" {
Push-Location $project1Root

This comment has been minimized.

@kalgiz

kalgiz Apr 27, 2018 Contributor

Can you, please, explain what is happening in here? Why are we pushing the $project1Root?

This comment has been minimized.

@bergmeister

bergmeister Apr 27, 2018 Author Collaborator

Similar to the test above I am testing that PSSA implicitly picks up the settings file (see feature description here). PSSA goes through various search paths like e.g. the supplied path (test above) or current working directory (this test/PR) or even the Desktop.

$violations = Invoke-ScriptAnalyzer -ScriptDefinition 'gci; Write-Host' -Recurse
Pop-Location
$violations.Count | Should -Be 1
$violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases" `

This comment has been minimized.

@kalgiz

kalgiz Apr 27, 2018 Contributor

Maybe Should -BeExactly, I think it should match the case as well.

This comment has been minimized.

@bergmeister

bergmeister Apr 27, 2018 Author Collaborator

Yes, we could use exact matching but I will need to apply that to surrounding test cases for consistency. I was wondering for a while if we should try to come up with a best practice example test template that we either document or even make a test helper method for it since nearly all PSSA tests are kind of the same...

@bergmeister bergmeister merged commit c632ea1 into PowerShell:development May 17, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.