Override Magento\Catalog\Block\Product\Compare\ListCompare using Preference
<preference for="Magento\Catalog\Block\Product\Compare\ListCompare"
type="Vendor\Catalog\Block\Product\Compare\ListCompare"/>
And update below function
/**
* Retrieve Product Compare Attributes
*
* @return array
*/
public function getAttributes()
{
if ($this->_attributes === null) {
$this->_attributes = $this->getItems()->getComparableAttributes();
}
// Remove Null Attribute From Compare List
foreach ($this->_attributes as $attribute) {
$size = sizeof($this->getItems());
$count = 0;
foreach ($this->getItems() as $item) {
$itemAttribute = $item->getData($attribute->getName());
$trimAttribute = trim($itemAttribute);
if (is_null($itemAttribute) || empty($trimAttribute)) {
$count++;
}
if ($count == $size) {
unset($this->_attributes[$attribute->getName()]);
}
}
}
return $this->_attributes;
}
This is working for me in Magento2