Skip to content

Format Document: Changes Tabs for Spaces #1466

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

Closed
midacts opened this issue Aug 3, 2018 · 4 comments
Closed

Format Document: Changes Tabs for Spaces #1466

midacts opened this issue Aug 3, 2018 · 4 comments

Comments

@midacts
Copy link

midacts commented Aug 3, 2018

System Details

  • Operating system name and version: Windows 10.0.15063
  • VS Code version: 1.25.1 1dfc5e557209371715f655691b1235b6b26a06be x64
  • PowerShell extension version: 1.8.2
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.15063.1155
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.1155
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:

PS C:\> code -v
1.25.1
1dfc5e557209371715f655691b1235b6b26a06be
x64

PS C:\> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      8      2      0


PS C:\> code --list-extensions --show-versions
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
ApplicationInsights:Sender [ { Error: self signed certificate in certificate chain
      at TLSSocket.<anonymous> (_tls_wrap.js:1088:38)
      at emitNone (events.js:86:13)
      at TLSSocket.emit (events.js:188:7)
      at TLSSocket._finishInit (_tls_wrap.js:610:8)
      at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38) code: 'SELF_SIGNED_CERT_IN_CHAIN' } ]

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.15063.1155
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.1155
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am using PowerShell.

I have lines of code link this which are key value pairs
After running Right click -> Format document, it replaces the tabs with spaces for the white spaces between the key and the "=" sign
My settings:

{
   "editor.insertSpaces": false,
   "editor.tabSize": 4,
   "files.encoding": "utf8",
   "files.eol": "\r\n",
}

Example

"key"	= "test"

changes to

"key" = "test"

Does this issue occur when all extensions are disabled?: No, because there isnt an option to Format document when --disable-extension used.

@rjmholt
Copy link
Contributor

rjmholt commented Aug 6, 2018

Hi @midacts, can you execute the following command to see if you get the same result:

> Invoke-Formatter (Get-Content -Raw ./path/to/your/script.ps1) > output.ps1

If output.ps1 here also has the converted tabs/spaces, then the problem is occurring in PSScriptAnalyzer's Invoke-Formatter command. Otherwise, it is likely a problem in EditorServices.

@midacts
Copy link
Author

midacts commented Aug 16, 2018

Running the above command turned all tabs into spaces and saved the file as UTF-16 LE.

I did notice, in examples like PSCustomObjects, it didnt replaces all spaces with tabs, maybe 1+ of the tabs stayed a tab and all the rest were changed to spaces.

Question

What would next steps be?

@midacts
Copy link
Author

midacts commented Aug 16, 2018

Thanks for the great lead.

Running Invoke-Formatter with '-Verbose' shows that it is using a 'Settings\CodeFormatting.psd1' file in the PSScriptAnalyzer module.

I made my own codeformatting.psd1 file and it did use tabs EXCEPT in the case of key/value pairs. It converted to spaces between the key and the equal sign.

PSScriptAnalyzer issue opened

@TylerLeonhardt
Copy link
Member

Thanks for doing that! I'll close this now since it's a Script Analyzer issue. Let me know if you feel otherwise! 👍

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

No branches or pull requests

3 participants