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

Invalid plugin-option value. Expected null, false or "", but received true. #9204

Open
Shinigami92 opened this issue Sep 15, 2020 · 11 comments
Labels
area:api Issues with Prettier's Application Programming Interface area:plugin api status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug

Comments

@Shinigami92
Copy link
Member

Environments:

  • Prettier Version: 2.1.1
  • Running Prettier via: CLI
  • Runtime: Node.js v14
  • Operating System: Arch Linux 5.4.64-1-lts

Steps to reproduce:

I have added aliases for my plugin options so it can better support specific options for pug embedded in vue.

So at first I tried to define an option like:

// pugSingleQuote
{
	since: '1.6.0',
	category: CATEGORY_PUG,
	type: 'boolean',
	default: false,
	description: "Use single quotes instead of double quotes."
}

But then I needed implemented a strategy to fallback to prettier's default/configured values if the aliases are not set.
Therefor I need to have a triple state boolean (true, false, null)

// pugSingleQuote
{
	since: '1.6.0',
	category: CATEGORY_PUG,
	type: 'choice',
	default: null,
	choices: [
		{
			value: null,
			description: 'Use `singleQuote` value.'
		},
		{
			value: true,
			description: 'Use single quotes instead of double quotes.'
		},
		{
			value: false,
			description: 'Use double quotes instead of double quotes.'
		}
	]
}

So null is just the default and shut not be set by a customer
But true or false should be valid values...
false is working fine
true results in an error 👀

Expected behavior:

true should be a valid choice and not be interpreted as "" (empty-string)

Actual behavior:

[error] Error: Invalid --pug-single-quote value. Expected null, false or "", but received true.

image

@Shinigami92
Copy link
Member Author

LOL it's even more funnier
When I use { "pugSingleQuote": "" } I get:

[error] Invalid pugSingleQuote value. Expected null, false or true, but received "". 👀
I thought you expect "" ?!

@fisker
Copy link
Member

fisker commented Sep 15, 2020

I think there are only boolean and string for CLI,

const [boolean, string] = partition(

I'm not sure how we treat --print-width.

@Shinigami92
Copy link
Member Author

printWidth is just an int

But what I need here is true, false or something that lets me fall back to a plugin managed value
And I don't want to use "true" instead of true

@fisker
Copy link
Member

fisker commented Sep 15, 2020

I mean cli only accept string and boolean, where does this --print-width get transformed.

@Shinigami92
Copy link
Member Author

You mean you are searching the code for this?

I'm a little bit confused cause my problem doesn't have anything to do with --print-width ^^'

@fisker
Copy link
Member

fisker commented Sep 15, 2020

I think it's the same thing, what we got for --print-width from CLI has to be string, and we are using as int.

--pug-single-quot should treat as string too, otherwise there will only boolean value, but we need use as boolean and null

@Shinigami92
Copy link
Member Author

But why is the plain value true via .prettierrc.json interpreted as empty string and vice versa?
I understand that via CLI only strings can be serialized. But I configured the value in the config as json. And this should not be limited to this fallback.
Also I think that it is just a silly check like !myVal instead of myVal === false somewhere. Or in other words: I think there is somewhere a equality check instead of strict equality check.

If this can not be fixed by plugin support in prettier itself, please explain me how I can expect a boolean value that is also nullable or undefinable?

I need a better docu for defining options in plugins

@fisker
Copy link
Member

fisker commented Sep 16, 2020

Ah, sorry I misunderstood the problem, I don't know, need investigate.

@thorn0 thorn0 added area:api Issues with Prettier's Application Programming Interface status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug labels Nov 5, 2020
@wscherphof
Copy link

Is there a workaround for still having single quotes?

@kaangokdemir
Copy link

kaangokdemir commented May 27, 2022

I also have the same problem. But for --pug-bracket-same-line instead

@dockleryxk
Copy link

Still happening for me in prettier v3.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Issues with Prettier's Application Programming Interface area:plugin api status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug
Projects
None yet
Development

No branches or pull requests

6 participants