[Request] Auto-complete boolean component properties in boolean style
If a blade component has a boolean property, you can use a boolean attribute in the XML. For example:
class Toggle extends Component
{
public function __construct(bool $toggled = false)
{
// ...
}
}
<x-toggle toggled />
Right now PhpStorm will autocomplete the property expecting a value:
<x-toggle toggled="" />
Is it possible to not autocomplete the ="" when the prop is a boolean?
Thank you, Chris! I don't have time to use all these new features, so each issue like that helps a lot. I'll try to implement it.
It seems like something with the plugin changed and now it's triggering a notice when using boolean attributes:

I was able to address this issue with my Alpine.js plugin using:
(Although I'm not sure if the BasicXmlAttributeDescriptor is actually doing anything here.)
Does it happen only with Laravel Idea turned on? Maybe it's an issue with XmlTag descriptor... I've found this code in the IntelliJ sources (RequiredAttributesInspectionBase.java):
XmlAttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributesDescriptors(tag);
Set<String> requiredAttributes = null;
for (XmlAttributeDescriptor attribute : attributeDescriptors) {
if (attribute != null && attribute.isRequired()) {
if (requiredAttributes == null) {
requiredAttributes = new HashSet<>();
}
requiredAttributes.add(attribute.getName(tag));
}
}
if (requiredAttributes != null) {
for (final String attrName : requiredAttributes) {
if (!hasAttribute(tag, attrName) &&
!XmlExtension.getExtension(tag.getContainingFile()).isRequiredAttributeImplicitlyPresent(tag, attrName)) {
LocalQuickFix insertRequiredAttributeIntention = isOnTheFly ? XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, attrName) : null;
final String localizedMessage = XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName);
reportOneTagProblem(
tag,
attrName,
localizedMessage,
insertRequiredAttributeIntention,
holder,
getIntentionAction(attrName),
isOnTheFly
);
}
}
}
}
Also there:
private static boolean hasAttribute(XmlTag tag, String attrName) {
final XmlAttribute attribute = tag.getAttribute(attrName);
if (attribute == null) return false;
if (attribute.getValueElement() != null) return true;
if (!(tag instanceof HtmlTag)) return false;
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
return descriptor != null && HtmlUtil.isBooleanAttribute(descriptor, tag);
}
So, seems, HtmlUtil.isBooleanAttribute(descriptor, tag) returns false for your attributes.
Hm. Would it be possible to provide hinting about which attributes are required/boolean based on the definition in the component class? i.e. if the constructor parameter has a bool type then it's marked as a boolean attribute, and if the constructor parameter doesn't have a default value it's marked as required?