React JSX文件的W3C HTML验证 [英] W3C HTML validation for React JSX files

查看:116
本文介绍了React JSX文件的W3C HTML验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理前端项目时,我总是喜欢使用整理工具.它们可以防止从愚蠢的错误到严重的臭味代码片段.整理工具还建议改进和优化.

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.

验证和整理HTML意味着使用W3C验证程序.在使用普通JavaScript项目时,我使用 grunt-html Grunt NPM模块.当使用Angular 1.x时,我使用 grunt-html-angular-validate 模块,它是相同的验证器,但适用于Angular要求(非标准属性或不完整的HTML文档不会引发错误或警告).但是,我试图为Grunt或Gulp找到一些类似的工具用于React JSX文档,但是运气不好.

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.

是否存在用于React JSX文件的W3C HTML验证器?如果没有,有什么理由吗?

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

注意:我对使用JSXHint之类的工具检查JSX的JavaScript部分不感兴趣,而只是检查HTML部分及其是否符合W3C规范.

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.

推荐答案

是否存在用于React JSX文件的W3C HTML验证器?

Does it exist W3C HTML validators for React JSX files?

否.

如果没有,有什么理由吗?

In case it does not, any reason for it?

因为它们不是HTML.

Because they aren't HTML.

最接近的可能是执行JavaScript以生成DOM,然后将该DOM序列化为HTML(例如,使用.innerHTML),然后添加DOCTYPE声明并验证结果.

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.

服务器端渲染工具(例如Next.js)在这里可能会有所帮助.

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

这篇关于React JSX文件的W3C HTML验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆