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.
答案 0 :(得分:1)
是否存在React JSX文件的W3C HTML验证程序?
没有
万一没有,有什么理由吗?
因为它们不是HTML。
您最接近的可能是执行JavaScript以生成DOM,然后将该DOM序列化为HTML(例如使用.innerHTML
),然后添加DOCTYPE声明并验证结果。
答案 1 :(得分:0)
JSX没有W3C HTML验证器。 JSX是JS,而不是HTML。所以你可以使用eslint插件来lint jsx以避免常见的问题: