question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Rule idea] No empty non void elements

See original GitHub issue

Hello,

I would love to implement a new rule to avoid non-empty void elements in templates.

Something that could lead to raise an error on <p></p> or <div></div> for example. Of course nothing would happen on <p>{{myVar}}</p> or any void elements (<br >).

Here is the applied configuration I will use:

const NON_VOID_TAGS = [
  'h1',
  'h2',
  'h3',
  'h4',
  'h5',
  'h6',
  'p',
  'span',
  'a',
  'ul',
  'ol',
  'li',
  'div',
];

Here are the use cases:

// BAD
<h1></h1>
<h2></h2>
<h3></h3>
<h4></h4>
<h5></h5>
<h6></h6>
<p></p>
<span></span>
<a></a>
<ul></ul>
<ol></ol>
<li></li>
<div></div>

// GOOD
<h1>My title</h1>
<h2>My title</h2>
<h3>My title</h3>
<h4>My title</h4>
<h5>My title</h5>
<h6>My title</h6>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<span>Lorem ipsum</span>
<a>my Link</a>
<ul><li>item</li></ul>
<ol>item</ol>
<li>item</li>
<div>something here</div>

I still do have a concern about the div element here, as we may want to use and empty one to create visual stylised elements with css. Maybe we can add or remove the div in the configuration list with a specific config value ?

I was thinking to call this rule no-empty-non-void-elements and disable it by default ?

In order to submit an acceptable final PR, do you have some auto generated files (like Changelog ?) or stuff I must perform during new rule implementation ? In plus than Documentation and tests.

Thanks

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rwjbluecommented, May 31, 2019

Gotcha, I was misinterpreting the term “void” in your original post. I typically use the term “void elements” to refer to things like:

<input>
<br>
<img>

Which apparently are actually called empty elements.

I’d vaguely prefer to avoid confusing my future self by not using void in the name here, what do you think about something like blacklist-childless-elements?

1reaction
rwjbluecommented, Jun 3, 2019

Seems great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are (non-void) self-closing tags valid in HTML5?
On HTML elements that are designated as void elements (essentially "An element that existed before HTML5 and which was forbidden to have any...
Read more >
Questionable .children requirement for void types · Issue #3482
It feels weird to require an arbitrary property and a text node inside our non-text elements (as void blocks are supposed to be),...
Read more >
When should I use non-void functions? - Unity Forum
there are no absolute rules, but as a general guideline: 1) Methods that do not return (defined as void) perform an action that...
Read more >
Describe the void elements in HTML - GeeksforGeeks
Void elements doesn't have ending tags and can only have attributes but do not contain any kind of content. These elements can have...
Read more >
If both <br> and <br /> are valid syntaxes, which one should I ...
Though HTML allows one to use or not use closing tags for empty elements, the idea is not about what you are allowed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found