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

Compressed/minified one-liner output #2043

Closed
suchverynice opened this issue Nov 23, 2024 · 1 comment
Closed

Compressed/minified one-liner output #2043

suchverynice opened this issue Nov 23, 2024 · 1 comment

Comments

@suchverynice
Copy link

Per subject, can't figure out why when running PSSA via dprint-plugin-exec and/or via bash???

Steps to reproduce

  • install pwsh via nixOS packages
  • install PSSA, dprint and dprint-plugin-exec per docs
  • run dprint via npm run script
// dprint config fail
{
	lineWidth: 80,
	indentWidth: 2,
	newLineKind: 'auto',
	useTabs: false,
	incremental: false,
	exec: {
		cwd: '${configDir}',
		commands: [
			{
				// Works, but why minified?!
				command: 'pwsh -noprofile -NonInteractive -Command "Invoke-Formatter -ScriptDefinition $Input"',
				stdin: true,
				exts: ['ps1', 'psm1', 'psd1']
			}
		]
	},
	plugins: [
		'https://plugins.dprint.dev/exec-0.5.0.json@8d9972eee71fa1590e04873540421f3eda7674d0f1aae3d7c788615e7b7413d0'
	]
}

Got the same "minified" results in bash:

# GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
# Same "minified" results
echo 'string-of-code' | pwsh -noprofile -noninteractive -c 'Invoke-Formatter -ScriptDefinition $input'
cat 'path/to/file' | pwsh -noprofile -noninteractive -c 'Invoke-Formatter -ScriptDefinition $input'

While either of below works:

// Alternate dprint config that works with same npm run script...
{
	// ...
	exec: {
		cwd: '${configDir}',
		commands: [
			// Works
			{
				command: 'pwsh -noprofile -NonInteractive -Command Invoke-Formatter -ScriptDefinition (Get-Content -Raw -Path {{file_path}})',
				stdin: false,
				exts: ['ps1', 'psm1', 'psd1']
			},
			// Or, this works too
			{
				command: "pwsh -noprofile -NonInteractive -Command Invoke-Formatter -ScriptDefinition ([System.IO.File]::ReadAllText('{{file_path}}'))",
				stdin: false,
				exts: ['ps1', 'psm1', 'psd1']
			}
		]
	},
	plugins: [
		'https://plugins.dprint.dev/exec-0.5.0.json@8d9972eee71fa1590e04873540421f3eda7674d0f1aae3d7c788615e7b7413d0'
	]
}
# Works via pwsh
cat 'in.ps1' | Invoke-Formatter
cat 'in.ps1' | Invoke-Formatter | Out-File -FilePath 'out.ps1' -Encoding utf8
cat 'in.ps1' | Invoke-Formatter | Set-Content -Path 'out.ps1' -Encoding utf8
([System.IO.File]::ReadAllText('in.ps1')) | Invoke-Formatter
([System.IO.File]::ReadAllText('in.ps1')) | Invoke-Formatter | Out-File -FilePath 'out.ps1' -Encoding utf8
([System.IO.File]::ReadAllText('in.ps1')) | Invoke-Formatter | Set-Content -Path 'out.ps1' -Encoding utf8
Get-Content -Raw -Path 'in.ps1' | Invoke-Formatter
Get-Content -Raw -Path 'in.ps1' | Invoke-Formatter | Out-File -FilePath 'out.ps1' -Encoding utf8
Get-Content -Raw -Path 'in.ps1' | Invoke-Formatter | Set-Content -Path 'out.ps1' -Encoding utf8

Expected behavior

# nicely formatted code

Actual behavior

function New-Profile { Write-Host "Running New-Profile function"        $profileName = Split-Path $profile -Leaf  if (Test-Path $profile) { Write-Error "Profile $profileName already exists on this computer." } else { New-Item -type file -Path $profile -Force } }  dir | % { "crtime: {0}" -f $_.creationtime } start-process example.exe start anotherexample.exe & "./dir/meow.exe"  enum Color { Black, White }  function Test-Code { [CmdletBinding()] param (        [int]$ParameterOne  )   end { if (10 -gt $ParameterOne) { "Greater" }       else { "Lesser" } } } enum Color { Black, White }  function Test-Code { [CmdletBinding()] param( [int]$ParameterOne   )   end { if (10 -gt $ParameterOne) { "Greater" } else { "Lesser" } } }

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Linux 6.2.16 #1-NixOS SMP PREEMPT_DYNAMIC Tue Jan  1 00:00…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

1.23.0
@suchverynice
Copy link
Author

Re-read the docs... My bad 😅

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

1 participant