Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

W3C HTML validation for React JSX files

When working on front-end projects I always like to work with linting tools. They prevent from dumb mistakes to serious smelly code pieces. Linting tools also suggest improvements and optimisations.

Validating and linting HTML means using the W3C Validator. When working with vanilla JavaScript projects I use the grunt-html Grunt NPM module. And when working with Angular 1.x I use the grunt-html-angular-validate module, which is the same validator but adapted to Angular requirements (non standard attributes or incomplete HTML documents will not fire errors or warnings). However I have tried to find some similar tool for React JSX documents either for Grunt or Gulp but with not luck.

Does it exist W3C HTML validators for React JSX files? In case it does not, any reason for it?

NOTE: I am not interested on checking the JavaScript part of the JSX with tools like JSXHint but just the HTML part and its compliance with W3C specifications.

like image 380
AxeEffect Avatar asked Apr 15 '16 14:04

AxeEffect


1 Answers

Does it exist W3C HTML validators for React JSX files?

No.

In case it does not, any reason for it?

Because they aren't HTML.


The closest you could come would be to execute the JavaScript to generate a DOM, then serialize that DOM to HTML (e.g. with .innerHTML), and then add a DOCTYPE declaration and validate the result.

This, of course, only gives you a snapshot of the output for a given state of the application.

Server-side rendering tools (such as Next.js) are probably helpful here.

like image 114
Quentin Avatar answered Sep 23 '22 05:09

Quentin