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

PSScriptAnalyzer #2370

Merged
merged 8 commits into from
Mar 29, 2019
Merged

PSScriptAnalyzer #2370

merged 8 commits into from
Mar 29, 2019

Conversation

zigford
Copy link
Contributor

@zigford zigford commented Mar 17, 2019

I use powershell in Vim a lot and have not written any significant vimscript before, and I saw there was an open issue #1264 for a new linter.

@zigford
Copy link
Contributor Author

zigford commented Mar 23, 2019

Ps, I’m not sure why this is failing at the moment. Could someone with more knowledge of the tests give me a hint?


" let g:ale_powershell_psscriptanalyzer_exclusions =
" \ 'PSAvoidUsingWriteHost,PSAvoidGlobalVars'
call ale#Set('powershell_psscriptanalyzer_exclusions',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just write '' as the second argument here.

call ale#Set('powershell_psscriptanalyzer_module',
\ 'psscriptanalyzer')

" GetExecutable {{{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of these {{{ and }}} comments. You can use the indentation levels for folding instead.

\ . l:module . ';$m.Version.ToString()}"')

return l:executable . l:module_string
endfunction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you aren't using the code, you should remove it.

let l:tempscript =
\ ale#util#Tempname() . (has('win32') ? '\' : '/') . l:filename

if ale#command#CreateTempFile(a:buffer, l:tempscript, a:input)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ale#command#CreateFile or ale#Command#ManageFile instead. CreateTempFile isn't intended for use outside of some very specific parts of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback, implemented your suggestions in commit a839a9e

@w0rp
Copy link
Member

w0rp commented Mar 29, 2019

I'll merge this and fix the linter errors.

@w0rp w0rp merged commit 000c37e into dense-analysis:master Mar 29, 2019
@coolaj86
Copy link

@zigford Do you know how / where I specify the PSScriptAnalyzerSettings.psd1 for my project on Mac / Linux?

I've looked through the source here (though I don't read VimScript very well) and a few PowerShell docs on Microsoft Learn, but I can't figure out how to do it.

This is what I have in the root of my project directory (where I'm running vim from), but the warnings are not being ignored as I expected:

./PSScriptAnalyzerSettings.psd1:

@{
    IncludeRules = @()
    ExcludeRules = @(
        'PSAvoidUsingCmdletAliases',
        'PSUseDeclaredVarsMoreThanAssignments'
    )
}

When I run vim ./bat/install.ps1 I still see all the errors.

@zigford
Copy link
Contributor Author

zigford commented Oct 18, 2023

@zigford Do you know how / where I specify the PSScriptAnalyzerSettings.psd1 for my project on Mac / Linux?

I've looked through the source here (though I don't read VimScript very well) and a few PowerShell docs on Microsoft Learn, but I can't figure out how to do it.

This is what I have in the root of my project directory (where I'm running vim from), but the warnings are not being ignored as I expected:

./PSScriptAnalyzerSettings.psd1:

@{
    IncludeRules = @()
    ExcludeRules = @(
        'PSAvoidUsingCmdletAliases',
        'PSUseDeclaredVarsMoreThanAssignments'
    )
}

When I run vim ./bat/install.ps1 I still see all the errors.

I think it’s in the :help but put something like this in your vimrc
" Suppress Write-Host and Global vars warnings
let g:ale_powershell_psscriptanalyzer_exclusions = 'PSAvoidUsingWriteHost,PSAvoidGlobalVars'

@coolaj86
Copy link

I am using g:ale_powershell_psscriptanalyzer_exclusions right now, however, my understanding is that I should be able to place a PSScriptAnalyzerSettings.psd1 in the project root with any and all supported options and have that pass through as -Settings <project-root>/PSScriptAnalyzerSettings.psd1 just like VS Code and other editors that support PowerShell.

I suppose that wasn't available at the time or otherwise didn't get implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants