【发布时间】:2017-06-09 14:53:26
【问题描述】:
这甚至可能不是 Gulp 的事情。这可能是我担心的 Webpack 配置,也可能是我的 linting 设置。我认为必须有一个合适的 ES 或 TS Lint 我需要绑定到 Gulp,所以当它为这个 React Asp.net Core 应用程序构建我的客户端和服务器生成的 Js 文件时,它不会那么挑剔。我在 Visual Studio Code 中,通常只需右键单击并格式化文档就可以解决这样的小问题,但是当我运行 gulp 时,这个新项目会变得疯狂。这些小错误对我来说似乎对间距和其他方面过于挑剔。有人对此有经验吗?
9:18 error A space is required after '{' object-curly-spacing
9:28 error A space is required before '}' object-curly-spacing
14:1 error Trailing spaces not allowed no-trailing-spaces
9:18 error A space is required after '{' object-curly-spacing
9:28 error A space is required before '}' object-curly-spacing
14:1 error Trailing spaces not allowed no-trailing-spaces
15:3 error handleChange should be placed after componentDidMount react/sort-comp
以下是此错误示例的来源示例。
import React, { Component } from 'react';
import Helmet from 'react-helmet';
// import { connect } from 'react-redux';
import { } from 'react-bootstrap';
export default class Test extends Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
componentDidMount() { }
render() {
return (
<div>
<Helmet title="Test" />
<form onSubmit={this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
</div>
);
}
}
【问题讨论】:
-
如果没有引发错误的代码,很难提供帮助。您能否在问题中包含有问题的部分?
-
您的 linter 配置的样式规则与您格式化代码的方式不匹配。更改代码样式或重新配置 linter 以删除规则“object-curly-spacing”和“no-trailing-spaces”。
-
@Aurora0001,我添加了代码。如果你看到任何东西,请告诉我。谢谢。
-
Gulp 和 webpack 只是工具运行器;他们会运行您要求他们使用的任何工具。在这种情况下,包括 ESLint。
-
转到 eslint.org/docs/rules 并找到您真正想要包含的规则并相应地更改您的 eslint 配置文件 eslint.org/docs/user-guide/configuring。如果您尚未定义配置文件,您将获得更严格的 linter。此外,TS linter 可以容纳除上面链接中的选项之外的其他选项。
标签: reactjs gulp webpack lint eslint