让Facebook的react.js库JSX语法与jslint完美配合?
我正在使用Facebook的 react.js 库.我正在尝试使用其JSX语法,该语法描述了通过以下方式创建视图.
I am playing around with the Facebook's react.js library. I am trying to use their JSX syntax which describes creating a view in the following way.
/** @jsx React.DOM */
var HelloMessage = React.createClass({
render: function() {
return <div>{'Hello ' + this.props.name}</div>;
}
});
React.renderComponent(<HelloMessage name="John" />, mountNode);
JSLint显然不喜欢这样(期望标识符,而是看到了'<';"-JavaScript语法错误),那么如何在我的.jshintrc文件中解决这个问题?
JSLint obviously does not like this ("expected an identifier and instead saw ' <';" - JavaScript syntax error), so how do I get around this in my .jshintrc file?
(更新:该帖子来自2013年,现已过时.)
(Update: This post is from 2013 and obsolete now.)
我使用JSHint + JSX.
I use JSHint + JSX.
它不应该需要JSHint的派生,应该有一种方法告诉JSHint禁用代码块的所有警告.不幸的是,没有这样的方法来禁用 all 警告,仅禁用一组特定的警告,因此我可能最终提交了添加此请求或更改短绒的拉取请求.
It shouldn't require a fork of JSHint, there should be a way to tell JSHint to disable all warnings for a block of code. Unfortunately there is no such way to disable all warnings, only a specific set of warnings, so I may end up submitting a pull request to add this, or change linters.
更新:我们提交了接受请求的拉取请求一个>.要禁用所有警告,请添加/*jshint ignore: start */
以开始该部分,并添加/*jshint ignore: end */
以结束该部分.
Update: We submitted a pull request which was accepted. To disable all warnings, add /*jshint ignore: start */
to start the section, and /*jshint ignore: end */
to end it.
正如您所指出的,Facebook和Instagram使用的工作流是从命令行在IDE外部完成工作.
As you noted, the workflow Facebook and Instagram use is to lint outside the IDE from the command line.
您的另一个选择是将所有JSX模板提取到它们自己的文件中,并使它们成为作用域的函数,而不是存在于隐式词法作用域中.我们尝试了一下,不喜欢样板.
Your other option is to extract all your JSX templates into their own files, and make them a function of scope instead of existing inside an implicit lexical scope. We tried it out and didn't like the amount of boilerplate.
(注意:我不隶属于React团队.)
(Note: I am not affiliated with the React team.)