Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新到 1.2.0 以后,为什么会报错误:JSX 事件名需以 on 命名 #1560

Closed
jswxwxf opened this issue Dec 18, 2018 · 22 comments
Closed
Assignees

Comments

@jswxwxf
Copy link

jswxwxf commented Dec 18, 2018

ESLint(taro/jsx-handler-names) 错误:JSX 事件名需以 `on` 命名
-----
  94 |     if (!order) return null;
  95 |     return (
> 96 |       <Container hasHeader title={this.delivery.deliveryStatusRemark} className="page order-page">
     |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  97 |         <StatusBox order={order} onCancel={this.handleCancel} />
  98 |         <View className='deliver-container' style={`display: ${this.delivery.expressId ? 'block' : 'none'}`}>
  99 |           <Card title={this.delivery.deliveryStatus === 4 ? '包裹已发出' : '包裹已签收'} detail='顺丰单号:' extraDetail={this.delivery.expressNo} renderBeforeIcon={
@taro-bot
Copy link

taro-bot bot commented Dec 18, 2018

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

这个明显不是事件啊……

@jswxwxf jswxwxf changed the title 更新到 1.2.0 以后,为什么会报这个异常 更新到 1.2.0 以后,为什么会报错误:JSX 事件名需以 on 命名 Dec 18, 2018
@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

还有这种错,这些之前都没报啊~ 有什么办法可以关闭这些错误吗?好像不影响运行

ESLint(taro/no-anonymous-function-in-props) 错误:不能在 JSX 参数中使用匿名函数
-----
  90 |         {/* <Related /> */}
  91 |         <ProductActionBar product={product} onClick={this.handlePicker} />
> 92 |         <ProductPicker ref={el => this.productPicker = el} onSubmit={this.handleBuy} />
     |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  93 |       </Container>
  94 |     )
  95 |   }

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

附上我的package.json

{
  "name": "mina",
  "version": "1.0.0",
  "private": true,
  "description": "Woof联合发售",
  "scripts": {
    "build:weapp": "taro build --type weapp",
    "build:swan": "taro build --type swan",
    "build:alipay": "taro build --type alipay",
    "build:h5": "taro build --type h5",
    "build:rn": "taro build --type rn",
    "dev:weapp": "npm run build:weapp -- --watch",
    "dev:swan": "npm run build:swan -- --watch",
    "dev:alipay": "npm run build:alipay -- --watch",
    "dev:h5": "npm run build:h5 -- --watch",
    "dev:rn": "npm run build:rn -- --watch"
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@tarojs/async-await": "^1.2.0",
    "@tarojs/components": "^1.2.0",
    "@tarojs/redux": "^1.2.0",
    "@tarojs/redux-h5": "^1.2.0",
    "@tarojs/router": "^1.2.0",
    "@tarojs/taro": "^1.2.0",
    "@tarojs/taro-alipay": "^1.2.0",
    "@tarojs/taro-h5": "^1.2.0",
    "@tarojs/taro-swan": "^1.2.0",
    "@tarojs/taro-weapp": "^1.2.0",
    "axios": "^0.18.0",
    "classnames": "^2.2.6",
    "dva-core": "^1.4.0",
    "dva-loading": "^2.0.5",
    "lodash": "^4.17.11",
    "moment": "^2.23.0",
    "nervjs": "^1.3.9",
    "react-redux": "^6.0.0",
    "redux": "^4.0.0",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "taro-ui": "^1.5.1",
    "validatorjs": "^3.15.1"
  },
  "devDependencies": {
    "@types/react": "^16.7.17",
    "@types/webpack-env": "^1.13.6",
    "@tarojs/plugin-babel": "^1.2.0",
    "@tarojs/plugin-csso": "^1.2.0",
    "@tarojs/plugin-sass": "^1.2.0",
    "@tarojs/plugin-uglifyjs": "^1.2.0",
    "@tarojs/webpack-runner": "^1.2.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-jsx-stylesheet": "^0.6.5",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-eslint": "^8.2.3",
    "eslint": "^4.19.1",
    "eslint-config-taro": "^1.2.0",
    "eslint-plugin-react": "^7.8.2",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-taro": "^1.2.0"
  }
}

@yuche
Copy link
Contributor

yuche commented Dec 18, 2018

第一个错:
把 this.delivery 放到 this.state 去。

第二个错:
把 el => this.productPicker = el 放到一个函数上去,参考:https://nervjs.github.io/taro/docs/ref.html#docsNav

这个是警告,不会影响你编译,警告是为了让你写更健壮的代码。

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

可以关闭掉吗?我不想改,这些写法地方太多了。

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

应该有地方配置 eslint 吧?

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

另外,第一种情况,这个状态不会变,我为什么要放到 state 里去呢?

@yuche
Copy link
Contributor

yuche commented Dec 18, 2018

那就等下个版本修复吧,这个是写死的

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

额~ 好吧,希望下个版本能把这个开放到配置里去……

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

或者能告诉我写死在代码哪里吗?我可以暂时去 node_modules 里禁用掉 :)

@yuche
Copy link
Contributor

yuche commented Dec 18, 2018

@tarojs/transformer-wx/lib/src/index.js, 159 行 eslint_1.eslintValidation 注释掉

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

好的,谢谢

@yuche yuche added the ESLint label Dec 18, 2018
@yuche yuche self-assigned this Dec 18, 2018
@yuche yuche closed this as completed in a3a4075 Dec 18, 2018
@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

没有这个目录啊~
2018-12-18 10 32 19

@yuche
Copy link
Contributor

yuche commented Dec 18, 2018

是在你 taro 命令行的目录

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

好的,我找找看

@jswxwxf
Copy link
Author

jswxwxf commented Dec 18, 2018

找到,谢啦,不过还是希望下个版本这个能做成配置。:D

@yuche
Copy link
Contributor

yuche commented Dec 18, 2018

@Lionad-Morotar
Copy link

希望能提供一个组件内的数据存储器, 如下面的 store:

export default class MyTenantList extends Component {

  config = {
    navigationBarTitleText: '店铺列表'
  }

  static state = {
    tenantList: [],
    statics: {
      notLong: 0,
      current: 0,
      history: 0
    }
  }

  store = {
    staticsTitle: {
      notLong: '即将到期店铺',
      current: '正在使用店铺',
      history: '已到期店铺'
    },
  }
// ...

@ariesjia
Copy link
Contributor

如果使用mobx的情况下,很多时候会直接把 this上的数据 绑定,就会导致这个eslint的warning,
编译时的eslint 可以能够进行配置么

@yuche
Copy link
Contributor

yuche commented Dec 27, 2018

@ariesjia
image

能看字吗

@ariesjia
Copy link
Contributor

@yuche 可能是我没表述清楚
我并不是期望完全不检查eslint ,我的建议是transformer-wx 中 new CLIEngine 的时候是否可以配置一些rules 比如我想关闭 taro/this-props-function 和 taro/jsx-handler-names 。
或者是否应该讲项目中的 eslintrc 配置 merge 进这里的配置中去。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants