WIP Do not flag whitespace only lines (includes tabs) in AvoidTrailingWhiteSpace rule
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.
- [x] PR has a meaningful title
- [x] Use the present tense and imperative mood when describing your changes
- [x] Summarized changes
- [ ] User facing documentation needed
- [x] Change is not breaking
- [x] Make sure you've added a new test if existing tests do not effectively test the code changed
- [x] 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
- If the PR is work in progress, please add the prefix
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 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
-Fixswitch - 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
- 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.