prettier / plugin-ruby

Prettier Ruby Plugin
MIT License
1.46k stars 97 forks source link

TypeError: Cannot read property 'toString' of null on all ruby files #876

Closed benjarrell closed 3 years ago

benjarrell commented 3 years ago

I am getting TypeError: Cannot read property 'toString' of null on all ruby files (that I have tried anyway, one example below). Other file formats work with Prettier as expected.

Metadata

All other options are the defaults.

Input

Code snippet

# frozen_string_literal: true

# tier.rb

Facter.add(:tier) do
  confine kernel: ['Linux']
  setcode do
    tier = Facter::Util::Resolution.exec("/bin/hostname -s | /bin/awk -F \- '{ print \$1 }'")
    case tier
    when %r{one|two}
      'internal'
    else
      tier
    end
  end
end

Facter.add(:tier) do
  confine kernel: ['windows']
  setcode do
    tier = Facter::Util::Resolution.exec("C:\\windows\\system32\\windowspowershell\\v1.0\\powershell.exe -Command \"Write-Output $env:COMPUTERNAME | ForEach-Object { $_.Split('-')[0] } | Select-String -Pattern
 '^([a-z]){2,}' | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value.ToLower() }\"")
    case tier
    when %r{one|two}
      'internal'
    else
      tier
    end
  end
end

Output

Running prettier --ruby-netcat-command nc --loglevel debug --check tier.rb gives me:

[debug] normalized argv: {"_":["tier.rb"],"check":true,"color":true,"editorconfig":true,"ruby-netcat-command":"nc","loglevel":"debug","config-precedence":"cli-override","debug-repeat":0,"ignore-path":".prettierignore","plugin":[],"plugin-search-dir":[]}
Checking formatting...
[debug] resolve config from 'tier.rb'
[debug] loaded options `null`
[debug] applied config-precedence (cli-override): {"rubyNetcatCommand":"nc"}
tier.rb[error] tier.rb: TypeError: Cannot read property 'toString' of null
[error]     at parseSync (C:\local\yarnpkgs\global\node_modules\@prettier\plugin-ruby\src\parser\parseSync.js:130:34)
[error]     at Object.parse (C:\local\yarnpkgs\global\node_modules\@prettier\plugin-ruby\src\ruby\parser.js:8:10)
[error]     at Object.parse (C:\local\yarnpkgs\global\node_modules\prettier\index.js:13625:19)
[error]     at coreFormat (C:\local\yarnpkgs\global\node_modules\prettier\index.js:14899:14)
[error]     at format (C:\local\yarnpkgs\global\node_modules\prettier\index.js:15131:14)
[error]     at Object.formatWithCursor (C:\local\yarnpkgs\global\node_modules\prettier\index.js:57542:12)
[error]     at format (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:15883:14)
[error]     at Object.formatFiles (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:16067:16)
[error]     at Object.run (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:16538:14)
[error]     at Object.<anonymous> (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:16553:5)
[error]     at Module._compile (internal/modules/cjs/loader.js:1063:30)
[error]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
[error]     at Module.load (internal/modules/cjs/loader.js:928:32)
[error]     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
[error]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
[error]     at internal/main/run_main_module.js:17:47
All matched files use Prettier code style!
kddnewton commented 3 years ago

If you're using nc you shouldn't need to manually set your netcat command. But if you still do, you'll need to set your command to nc -U (or whatever option your specific netcat uses to trigger unix sockets). Let me know if that doesn't work for you.

benjarrell commented 3 years ago

I am getting the same result with the option removed. I added it after digging into the problem, as I have 2 different telnet commands as well as an ncat command that does not support -U.

prettier --loglevel debug --check tier.rb
[debug] normalized argv: {"_":["tier.rb"],"check":true,"color":true,"editorconfig":true,"loglevel":"debug","config-precedence":"cli-override","debug-repeat":0,"ignore-path":".prettierignore","plugin":[],"plugin-search-dir":[]}
Checking formatting...
[debug] resolve config from 'tier.rb'
[debug] loaded options `null`
[debug] applied config-precedence (cli-override): {}
tier.rb[error] tier.rb: TypeError: Cannot read property 'toString' of null
[error]     at parseSync (C:\local\yarnpkgs\global\node_modules\@prettier\plugin-ruby\src\parser\parseSync.js:130:34)
[error]     at Object.parse (C:\local\yarnpkgs\global\node_modules\@prettier\plugin-ruby\src\ruby\parser.js:8:10)
[error]     at Object.parse (C:\local\yarnpkgs\global\node_modules\prettier\index.js:13625:19)
[error]     at coreFormat (C:\local\yarnpkgs\global\node_modules\prettier\index.js:14899:14)
[error]     at format (C:\local\yarnpkgs\global\node_modules\prettier\index.js:15131:14)
[error]     at Object.formatWithCursor (C:\local\yarnpkgs\global\node_modules\prettier\index.js:57542:12)
[error]     at format (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:15883:14)
[error]     at Object.formatFiles (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:16067:16)
[error]     at Object.run (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:16538:14)
[error]     at Object.<anonymous> (C:\local\yarnpkgs\global\node_modules\prettier\bin-prettier.js:16553:5)
[error]     at Module._compile (internal/modules/cjs/loader.js:1063:30)
[error]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
[error]     at Module.load (internal/modules/cjs/loader.js:928:32)
[error]     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
[error]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
[error]     at internal/main/run_main_module.js:17:47
All matched files use Prettier code style!
kddnewton commented 3 years ago

Looks like you're running on windows. I didn't even realize, but this is busted on windows since we switched to the unixserver. I'm working on support for it, tracking in https://github.com/prettier/plugin-ruby/pull/890