TypeError: Cannot read property 'type' of undefined with babel-eslint@8.1.2
See original GitHub issueTell us about your environment
- ESLint Version: 4.14.0
- Node Version: v8.9.1
- npm Version: 5.6.0
What parser (default, Babel-ESLint, etc.) are you using? Babel-ESLint@8.1.2
Please show your full configuration:
Configuration
extends: airbnb
parser: 'babel-eslint'
rules:
indent:
- error
- 2
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- never
no-unused-expressions:
- off
no-unused-vars:
- warn
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
src/pages/basic/ForgetPassWord.jsx
import React from 'react'
import { observer, inject } from 'mobx-react'
import { Steps, Form, Radio, Input, Button, message } from 'antd'
import _ from 'lodash'
import xingyeLogo from '../../assets/images/xingyeyinhang.png'
import school from '../../assets/images/educloud-logo.png'
import { SYSTEM_CODE, VERIFY_CODE } from '../../../../educloud-common/consts/consts.system'
import { encrypt } from '../../utils/helper'
import './ForgetPassWord.css'
const Step = Steps.Step
const FormItem = Form.Item
const RadioGroup = Radio.Group
const FormItemLayout = {
labelCol: { span: 5 },
wrapperCol: { span: 15 },
}
@inject(['forgetPassWord'])
@observer
class ForgetPassWord extends React.Component {
constructor(props) {
super(props);
this.store = this.props.forgetPassWord
this.state = {
current: 0,
};
}
render() {
const { current } = this.state
return (
<div
style={{overflowY: 'auto', height: '100%', background: '#ecf0f5'}}
className='common-scroll'>
<div style={{background: '#e8e8e8', padding: '25px 30px', display: 'flex', alignItems: 'center'}}>
<img src={xingyeLogo} alt="兴业银行" />
<img style={{margin: '0 10px 0 10px'}} src={school} alt="学校" />
<span style={{fontSize: 18, fontWeight: 'bold'}}>教育云平台</span>
</div>
<div style={{width: 860, margin: '35px auto 0 auto'}}>
<Steps style={{background: '#ecf0f5'}} current={current}>
<Step title="证件检查" />
<Step title="重置登陆密码" />
<Step title="完成" />
</Steps>
</div>
<div
style={{
width: 820,
margin: '25px auto 0 auto',
padding: '0 30px 35px 30px',
border: '2px solid #eee',
background: '#fff',
borderTop: '3px solid #3c8dbc'}}>
<h3 style={{
fontSize: 16,
padding: 10,
borderBottom: '2px solid #eee',
marginBottom: 15
}}>
重置密码
</h3>
{this.StepPage()}
</div>
</div>
)
}
next = () => {
this.setState({
current: ++this.state.current
})
}
StepPage = () => {
const { current } = this.state;
switch (current) {
case 0:
return <CertCheck next={this.next} store={this.store} />
case 1:
return <ResetPassWord next={this.next} store={this.store} />
case 2:
return <Done {...this.props} />
default:
return
}
}
}
//证件检查块
@observer
class CertCheckBlock extends React.Component {
constructor(props) {
super(props)
}
// 手机号验证
checkPhone = (rule, value, callback) => {
if (!value) {
callback('不能为空')
return
}
const length = value.length;
const isPhone = /^1\d{10}$/.test(value);
const isLength = _.isEqual(length, 11);
if (!length) {
callback();
} else if (length !== 11) {
callback('手机号格式不正确,请输入11位手机号!');
} else if (!isPhone) {
callback('手机号格式不正确,请输入11位手机号!');
} else if (!isLength) {
callback('手机号格式不正确,请输入11位手机号!');
} else {
callback();
}
}
render() {
const { getFieldDecorator } = this.props.form
return (
<div>
<FormItem label="手机号码:" {...FormItemLayout}>
{getFieldDecorator('phone', {
rules: [
{required: true, message: '手机号码必填!'},
{validator: this.checkPhone.bind(this) },
],
})(
<Input style={{width: 400}}
onKeyDown={(e) => { if (e.keyCode === 13) {this.onNext()} }} />
)}
</FormItem>
<div style={{textAlign: 'center'}}>
<Button style={{fontSize: 16}} onClick={() => {this.onNext()}} type="primary">下一步</Button>
</div>
</div>
)
}
onNext = () => {
const self = this
this.props.form.validateFieldsAndScroll((err, values) => {
if(!err) {
const body = self.props.form.getFieldsValue()
self.props.store.getPhone(body, (res) => {
if (SYSTEM_CODE.ACCT_UN_AVAILABLE === res.respCode) {
self.props.store.phone = body.phone
self.props.next()
} else if (SYSTEM_CODE.FORMAT_FAILED === res.respCode) {
message.error('电话格式不正确')
} else if (SYSTEM_CODE.LOGIN_SUCCESS === res.respCode) {
message.error('未找到用户,请确认手机号码')
}
})
}
})
}
}
const CertCheck = Form.create()(CertCheckBlock)
//重置登陆密码块
class ResetPassWordBlock extends React.Component {
constructor(props) {
super(props);
this.state = {
isSendOut: false,
count: 60,
randomNumber: undefined
}
}
componentWillUnmount() {
clearInterval(this.timer)
}
//密码格式校验
checkPassWrod = (rule, value, callback) => {
const form = this.props.form;
const isRule = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/.test(value);
if (!isRule) {
callback('密码由数字和字母组成');
} else {
callback();
}
}
checkRepeatPassword = (rule, value, callback) => {
const passWord = this.props.form.getFieldsValue(['password']).password
const isRule = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/.test(value);
if (!isRule) {
callback('密码由数字和字母组成');
} else if (passWord !== value) {
callback('两次密码不一致')
} else {
callback()
}
}
sendOutVerify = () => {
const self = this
const body = {
mobile: self.props.store.phone,
argMap: {
schoolName: ''
}
}
this.props.store.sendVerificationCode(body, () => {
self.countDown()
})
}
countDown = () => {
if (!this.state.isSendOut) {
this.timer = setInterval(function () {
this.setState((prevState) => ({ count: prevState.count - 1, isSendOut: true }), () => {
if (this.state.count === 0) {
this.setState({ isSendOut: false, count: 60 });
clearInterval(this.timer);
}
})
}.bind(this), 1000)
}
}
render() {
const { getFieldDecorator } = this.props.form
const { phone } = this.props.store
const { isSendOut, randomNumber } = this.state
const text = isSendOut ? `${this.state.count}秒后重新发送` : '发送验证码'
return (
<div>
<p style={{color: '#999'}}>以下是您在本平台登记过的手机号码,我们将向选中手机发送验证码</p>
<RadioGroup defaultValue={`${phone}`}>
<div style={{margin: '8px'}}>
<Radio value={`${phone}`}>{phone}</Radio>
</div>
</RadioGroup>
<div style={{marginTop: 15}}>
<FormItem label="图形验证码:" {...FormItemLayout} className="imageCode">
{getFieldDecorator('imgCode', {
rules: [{required: true, message: '图形验证码必填!'}],
})(
<Input
style={{width: 250, float: 'left'}}
placeholder="右侧验证码" />
)}
<div
style={{
width: 90,
height: 35,
float: 'left',
background: '#fff',
margin: '0 10px'}}>
<img
style={{width: 80, height: 30, margin: 5}}
src={`${process.env.REACT_APP_API_SMS_URL}/api/v1/captcha/${randomNumber}`}
alt="验证码" />
</div>
<div
onClick={() => {this.changeImaCode()}}
style={{float: 'left', color: '#00a4e1', cursor: 'pointer'}}>
看不清楚?换一张
</div>
</FormItem>
<FormItem label="短信验证码:" {...FormItemLayout}>
{getFieldDecorator('messageCode', {
rules: [{required: true, message: '短信验证码必填!'}],
})(
<Input
style={{width: 250}}
placeholder="收到的验证码" />
)}
<Button
style={{
marginLeft: 15,
background: isSendOut ? '#6f7072' : '#f39c13',
border: 0,
color: '#fff',
cursor: isSendOut ? 'no-drop' :'pointer'}}
type="primary"
onClick={() => {isSendOut ? null : this.sendOutVerify()}}>
{text}
</Button>
</FormItem>
<FormItem label="登陆密码:" {...FormItemLayout}>
{getFieldDecorator('password', {
rules: [
{required: true, message: '登录密码必填!'},
{validator: this.checkPassWrod.bind(this)}
],
})(
<Input
type="password"
style={{width: 400}}
placeholder="设置登陆密码,8-16位数字字母组合" />
)}
</FormItem>
<FormItem label="确认密码证码:" {...FormItemLayout}>
{getFieldDecorator('repeatPassWord', {
rules: [
{required: true, message: '确认密码必填!'},
{validator: this.checkRepeatPassword.bind(this)}
],
})(
<Input
type="password"
style={{width: 400}}
placeholder="再次输入密码" />
)}
</FormItem>
</div>
<div style={{textAlign: 'center'}}>
<Button style={{fontSize: 16}} onClick={() => {this.onNext()}} type="primary">提交</Button>
</div>
</div>
)
}
changeImaCode = (value) => {
const date = new Date()
const timeStamp = Date.parse(date)
this.setState({
randomNumber: timeStamp
})
}
onNext = () => {
const self = this
const { form } = this.props
form.validateFieldsAndScroll((err, values) => {
if(!err) {
const data = form.getFieldsValue()
//图形验证码的body
const imgCodeCheck = {verifyCode: data.imgCode}
//短信验证码的body
const messageCodeCheck = {
mobile: self.props.store.phone,
verifyCode: data.messageCode
}
//修改用户密码的body
const body = {password: encrypt(data.password)}
//图形验证码校验
self.props.store.checkImageVerificationCode(imgCodeCheck, (res) => {
//成功
if (res.respCode === VERIFY_CODE.SUCCESS) {
//短信校验码
self.props.store.checkVerificationCode(messageCodeCheck, (res) => {
if (res.respCode === VERIFY_CODE.SUCCESS) {
//发起修改密码
self.props.store.forgetPassWord(body, (res) => {
if (res.respCode === SYSTEM_CODE.LOGIN_SUCCESS) {
message.success('修改成功')
self.props.next()
} else if (res.respCode === SYSTEM_CODE.FORMAT_FAILED) {
message.error('密码格式不正确')
}
})
} else if (res.respCode === VERIFY_CODE.FAILED) {
form.setFields({
messageCode: {
value: values.messageCode,
errors: [new Error(`${res.message}`)]
}
})
} else {
message.error('短信验证码异常')
}
})
} else if (res.respCode === VERIFY_CODE.FAILED) {
form.setFields({
imgCode: {
value: values.imgCode,
errors: [new Error(`${res.message}`)]
}
})
} else {
message.error('图片验证码异常')
}
})
}
})
}
}
const ResetPassWord = Form.create()(ResetPassWordBlock)
//完成
class Done extends React.Component {
render() {
return (
<div>
<div>
<div style={{padding: '20px 20px'}}>
<div className="doneMeassage">恭喜您!完成登陆密码的重置!请返回登录页,重新登陆....</div>
<div style={{textAlign: 'center'}}>
<Button
onClick={() => {this.goLogin()}}
style={{fontSize: 16, marginBottom: 50}}
type="primary">
返回
</Button>
</div>
</div>
</div>
</div>
)
}
goLogin = () => {
this.props.history.push('/login')
}
}
export default ForgetPassWord
yarn run eslint src/pages/basic/ForgetPassWord.jsx --debug
What did you expect to happen?
What actually happened? Please include the actual, raw output from ESLint.
yarn run v1.3.2
$ /Users/bk/.../educloud-web/node_modules/.bin/eslint src/pages/basic/ForgetPassWord.jsx --debug
eslint:cli Running on files +0ms
eslint:glob-util Creating list of files to process. +0ms
eslint:ignored-paths Looking for ignore file in /Users/bk/project/project_business/emsoft/EduCloud/educloud-web +0ms
eslint:ignored-paths Could not find ignore file in cwd +1ms
eslint:cli-engine Processing /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/src/pages/basic/ForgetPassWord.jsx +0ms
eslint:cli-engine Linting /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/src/pages/basic/ForgetPassWord.jsx +2ms
eslint:config Constructing config file hierarchy for /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/src/pages/basic +0ms
eslint:config Using .eslintrc and package.json files +1ms
eslint:config Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/.eslintrc.yml +5ms
eslint:config-file Loading YAML config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/.eslintrc.yml +0ms
eslint:config-file Loading airbnb +884ms
eslint:config-file Attempting to resolve eslint-config-airbnb +1ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb/index.js +2ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb/rules/react-a11y.js +10ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb/rules/react-a11y.js +1ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb/rules/react.js +586ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb/rules/react.js +0ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/strict.js +70ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/strict.js +1ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/index.js +5ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/index.js +0ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/imports.js +5ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/imports.js +1ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/es6.js +205ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/es6.js +0ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/variables.js +48ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/variables.js +0ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/style.js +17ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/style.js +1ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/node.js +192ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/node.js +0ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/errors.js +5ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/errors.js +1ms
eslint:config-file Loading /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/best-practices.js +11ms
eslint:config-file Loading JS config file: /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint-config-airbnb-base/rules/best-practices.js +0ms
eslint:config Using /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/.eslintrc.yml +2s
eslint:config-ops Using config from partial cache +0ms
eslint:config-ops Apply environment settings to config +1ms
eslint:config-ops Creating config for environment node +1ms
eslint:config-ops Creating config for environment es6 +0ms
eslint:linter Linting code for /Users/bk/project/project_business/emsoft/EduCloud/educloud-web/src/pages/basic/ForgetPassWord.jsx (pass 1) +0ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +0ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +758ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +17ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +70ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +85ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +72ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +7ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +15ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +12ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +219ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +7ms
eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","start","end","loc","static","computed","key","variance","value","range"] +102ms
Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
at isForInRef (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/rules/no-unused-vars.js:410:24)
at variable.references.some.ref (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/rules/no-unused-vars.js:447:21)
at Array.some (<anonymous>)
at isUsedVariable (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/rules/no-unused-vars.js:446:40)
at collectUnusedVariables (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/rules/no-unused-vars.js:569:26)
at collectUnusedVariables (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/rules/no-unused-vars.js:576:17)
at Program:exit (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/rules/no-unused-vars.js:621:36)
at listeners.(anonymous function).forEach.listener (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/util/safe-emitter.js:47:58)
at Array.forEach (<anonymous>)
at Object.emit (/Users/bk/project/project_business/emsoft/EduCloud/educloud-web/node_modules/eslint/lib/util/safe-emitter.js:47:38)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing because this issue could not be reproduced. Feel free to open a new issue if you’re still encountering crashes after upgrading to
babel-eslint@8.1.2
.@sugarac It looks fine to me after I updated
babel-eslint
: