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

WIP Do not flag whitespace only lines (includes tabs) in AvoidTrailingWhiteSpace rule #1048

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

bergmeister
Copy link
Collaborator

@bergmeister bergmeister commented Jul 28, 2018

PR Summary

Fixes #1033 by not flagging whitespace only lines (includes tabs) in AvoidTrailingWhiteSpace rule

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 bergmeister changed the title Do not flag whitespace only lines (includes tabs) Do not flag whitespace only lines (includes tabs) in AvoidTrailingWhiteSpace rule Jul 28, 2018
@JamesWTruher
Copy link
Member

I'm not convinced that this addresses the issue. The heuristic should be checking previous lines for indentation and then making sure that the initial whitespace matches when the line has non non-space characters.

The change as provided would allow a line which contains only whitespace, which could lead to a DOS attack. Imagine a file which contains immense amounts of whitespace on "empty" lines.
Lastly, I really believe that this is a problem with the editor and I don't believe the PSSA should be used to address it. It seems this would lead to lots of extraneous white space in scripts which we should catch as a problem.

@JamesWTruher JamesWTruher self-requested a review August 23, 2018 17:51
Copy link
Member

@JamesWTruher JamesWTruher left a comment

Choose a reason for hiding this comment

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

I'm really not a fan of this change (see my comment below)

@bergmeister
Copy link
Collaborator Author

@JamesWTruher Neither am I (see discussion in linked issue) and for issues inside editors, I agree that the editor settings to auto-delete extraneous whitespace on save are the way to go. But I can understand that it's frustrating for people who run Invoke-ScriptAnalyzer as part of their CI and had a broken build due to the new PSSA version. I am thinking:

  • Implement the SuggestedCorrection so that it can be auto fixed using the new -Fix switch
  • Do not flag whitespace-only lines by default as proposed in this PR but offer an option to be pernickety and warn on whitespace-only lines
    Let me know what you think of that

@rjmholt
Copy link
Contributor

rjmholt commented Aug 24, 2018

  • The SuggestedCorrection suggestion seems like a good one. I can imagine that people who want whitespace up to the indented level will want a different correction though.
  • I think the default should be to flag any lines that have trailing whitespace (including whitespace only lines), (1) because that is a common desire (we are only hearing one side of the argument on this), (2) because it's the current behaviour and has been for a whle, and (3) because it's what the name of the rule implies
  • Ideally the rule should support a configuration option to opt in on ignoring whitespace-only lines
  • Perhaps the rule warning level should be configurable, so that people can make this a non-blocker in CI

One other note: ignoring whitespace-only lines doesn't seem to be exactly what the issue ask was -- that issue implied a desire to check that the whitespace exists to the correct indentation level. That is something that is arguably much more involved to implement; the rule would need to do a stateful, indentation-aware pass over the script.

It's the kind of thing we allow people to define their own rules for. Naturally though, only a rule about whitespace could generate this much discussion.

@bergmeister bergmeister changed the title Do not flag whitespace only lines (includes tabs) in AvoidTrailingWhiteSpace rule WIP Do not flag whitespace only lines (includes tabs) in AvoidTrailingWhiteSpace rule Sep 2, 2018
@rjmholt rjmholt marked this pull request as draft April 21, 2021 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PSAvoidTrailingWhitespace should ignore empty lines indented to match the current block
3 participants