diff --git a/.eslintrc b/.eslintrc index 818b6e36cc..1fe388b4b5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,35 +1,43 @@ { - "rules": { - "indent": [ - 2, - 2, - { "SwitchCase": 1 } - ], - "quotes": [ - 2, - "single" - ], - "linebreak-style": [ - 2, - "unix" - ], - "semi": [ - 2, - "always" - ], - "react/react-in-jsx-scope": 1, - "react/jsx-uses-react": 1 - }, + "extends": ["eslint-config-airbnb"], "env": { - "es6": true, "browser": true, "node": true }, "ecmaFeatures": { - "jsx": true, - "modules": true + "jsx": true }, + "parser": "babel-eslint", "plugins": [ - "react" - ] + "react", + "babel" + ], + "rules": { + "constructor-super": 2, + "comma-dangle": 0, + "func-names": 0, + "guard-for-in": 0, + "one-var": [2, { "initialized": "never" }], + "prefer-const": 0, + "key-spacing": 0, + "no-eq-null": 0, + "no-else-return": 0, + "no-param-reassign": 0, + "no-this-before-super": 2, + "no-undef": 2, + "no-unused-vars": [2, { "vars": "all", "args": "none" }], + "babel/object-shorthand": 0, + "react/jsx-boolean-value": 0, + "react/jsx-no-duplicate-props": 2, + "react/prop-types": [2, { "ignore": [ "children", "className", "style" ] }], + "react/sort-comp": 0, + "react/wrap-multilines": 0, + "react/no-multi-comp": 0, + "react/prop-types": 0, + "space-after-keywords": 0, + "space-before-blocks": 0, + "space-before-function-paren": 0, + "spaced-comment": 0, + "vars-on-top": 0 + } } diff --git a/components/affix/demo/offset.md b/components/affix/demo/offset.md index a6a505cfba..87858a2385 100644 --- a/components/affix/demo/offset.md +++ b/components/affix/demo/offset.md @@ -10,7 +10,7 @@ var Affix = antd.Affix; React.render( - + , document.getElementById('components-affix-demo-offset')); diff --git a/components/affix/index.jsx b/components/affix/index.jsx index dd9698c8cb..e290fc8e84 100644 --- a/components/affix/index.jsx +++ b/components/affix/index.jsx @@ -3,10 +3,10 @@ import joinClasses from 'react/lib/joinClasses'; import rcUtil from 'rc-util'; function getScroll(w, top) { - var ret = w['page' + (top ? 'Y' : 'X') + 'Offset']; - var method = 'scroll' + (top ? 'Top' : 'Left'); + let ret = w['page' + (top ? 'Y' : 'X') + 'Offset']; + let method = 'scroll' + (top ? 'Top' : 'Left'); if (typeof ret !== 'number') { - var d = w.document; + let d = w.document; //ie6,7,8 standard mode ret = d.documentElement[method]; if (typeof ret !== 'number') { @@ -18,12 +18,12 @@ function getScroll(w, top) { } function getOffset(element) { - var rect = element.getBoundingClientRect(); - var body = document.body; - var clientTop = element.clientTop || body.clientTop || 0; - var clientLeft = element.clientLeft || body.clientLeft || 0; - var scrollTop = getScroll(window, true); - var scrollLeft = getScroll(window); + let rect = element.getBoundingClientRect(); + let body = document.body; + let clientTop = element.clientTop || body.clientTop || 0; + let clientLeft = element.clientLeft || body.clientLeft || 0; + let scrollTop = getScroll(window, true); + let scrollLeft = getScroll(window); return { top: rect.top + scrollTop - clientTop, @@ -31,7 +31,7 @@ function getOffset(element) { }; } -var Affix = React.createClass({ +let Affix = React.createClass({ getDefaultProps() { return { @@ -39,6 +39,10 @@ var Affix = React.createClass({ }; }, + propTypes: { + offset: React.PropTypes.number + }, + getInitialState() { return { affix: false, @@ -47,9 +51,9 @@ var Affix = React.createClass({ }, handleScroll() { - var affix = this.state.affix; - var scrollTop = getScroll(window, true); - var elemOffset = getOffset(this.getDOMNode()); + let affix = this.state.affix; + let scrollTop = getScroll(window, true); + let elemOffset = getOffset(this.getDOMNode()); if (!affix && (elemOffset.top - this.props.offset) < scrollTop) { this.setState({ @@ -85,8 +89,8 @@ var Affix = React.createClass({ }, render() { - var affix = this.state.affix ? 'ant-affix' : ''; - var className = this.props.className; + let affix = this.state.affix ? 'ant-affix' : ''; + let className = this.props.className; return (
diff --git a/components/alert/index.jsx b/components/alert/index.jsx index 525b127561..493f2c539c 100644 --- a/components/alert/index.jsx +++ b/components/alert/index.jsx @@ -34,29 +34,30 @@ export default React.createClass({ }); }, render() { - var iconClass = this.props.description ? + let iconClass = this.props.description ? 'ant-alert-with-description-icon anticon-' : 'ant-alert-icon anticon-'; switch (this.props.type) { - case 'success': - iconClass += 'check-circle'; - break; - case 'info': - iconClass += 'info-circle'; - break; - case 'error': - iconClass += 'exclamation-circle'; - break; - case 'warn': - iconClass += 'question-circle'; - break; - default: - iconClass += 'default'; + case 'success': + iconClass += 'check-circle'; + break; + case 'info': + iconClass += 'info-circle'; + break; + case 'error': + iconClass += 'exclamation-circle'; + break; + case 'warn': + iconClass += 'question-circle'; + break; + default: + iconClass += 'default'; } - let html, closeName = !this.state.closing ? ' ' + this.props.prefixCls + '-close' : ''; + let html; + let closeName = !this.state.closing ? ' ' + this.props.prefixCls + '-close' : ''; if (this.props.description) { let close = this.props.closable ? - + : ''; html =
@@ -74,7 +75,7 @@ export default React.createClass({ } else { let close = this.props.closable ? - + : ''; html =
@@ -85,7 +86,7 @@ export default React.createClass({ } return this.state.closed ? null : {html} diff --git a/components/badge/index.jsx b/components/badge/index.jsx index 13e8765370..aeea82da50 100644 --- a/components/badge/index.jsx +++ b/components/badge/index.jsx @@ -38,4 +38,8 @@ AntBadge.defaultProps = { dot: false }; +AntBadge.propTypes = { + dot: React.PropTypes.bool +}; + export default AntBadge; diff --git a/components/breadcrumb/index.jsx b/components/breadcrumb/index.jsx index c5ec56f216..c3be890eaf 100644 --- a/components/breadcrumb/index.jsx +++ b/components/breadcrumb/index.jsx @@ -3,9 +3,12 @@ import React from 'react'; let prefixCls = 'ant-breadcrumb'; let BreadcrumbItem = React.createClass({ + propTypes: { + href: React.PropTypes.string + }, render() { - var link = {this.props.children}; - var slash = /; + let link = {this.props.children}; + let slash = /; if (typeof this.props.href === 'undefined') { link = {this.props.children}; } @@ -14,6 +17,9 @@ let BreadcrumbItem = React.createClass({ }); let Breadcrumb = React.createClass({ + propTypes: { + router: React.PropTypes.object + }, contextTypes: { router: React.PropTypes.object }, @@ -21,14 +27,14 @@ let Breadcrumb = React.createClass({ let crumbs, routes, params; let ReactRouter = this.props.router; if (this.context.router && ReactRouter) { - var Link = ReactRouter.Link; + let Link = ReactRouter.Link; routes = this.context.router.state.branch; params = this.context.router.state.params; crumbs = routes.map(function(route, i) { - var name = route.breadcrumbName.replace(/\:(.*)/g, function(replacement, key) { + let name = route.breadcrumbName.replace(/\:(.*)/g, function(replacement, key) { return params[key] || replacement; }); - var link; + let link; if (i === routes.length - 1) { link = {name}; } else { diff --git a/components/datepicker/index.jsx b/components/datepicker/index.jsx index 9a759432dc..49368b09fe 100644 --- a/components/datepicker/index.jsx +++ b/components/datepicker/index.jsx @@ -16,10 +16,10 @@ let defaultCalendarValue = new GregorianCalendar(zhCn); defaultCalendarValue.setTime(Date.now()); -function createPicker(Calendar) { +function createPicker(TheCalendar) { return React.createClass({ getInitialState() { - var value; + let value; if (this.props.value) { value = new GregorianCalendar(zhCn); value.setTime(new Date(this.props.value).valueOf()); @@ -56,8 +56,8 @@ function createPicker(Calendar) { this.props.onSelect(new Date(v.getTime())); }, render() { - var calendar = ( - + showClear={false} /> ); - var sizeClass = ''; + let sizeClass = ''; if (this.props.size === 'large') { sizeClass = ' ant-input-lg'; } else if (this.props.size === 'small') { diff --git a/components/input-number/index.jsx b/components/input-number/index.jsx index bcf8f25d4d..1cf80e56ba 100644 --- a/components/input-number/index.jsx +++ b/components/input-number/index.jsx @@ -8,7 +8,7 @@ export default React.createClass({ }; }, render() { - var sizeClass = ''; + let sizeClass = ''; if (this.props.size === 'large') { sizeClass = 'ant-input-number-lg'; } else if (this.props.size === 'small') { diff --git a/components/menu/index.jsx b/components/menu/index.jsx index b9daf74808..d123462166 100644 --- a/components/menu/index.jsx +++ b/components/menu/index.jsx @@ -11,15 +11,16 @@ const AntMenu = React.createClass({ render() { let openAnimation = ''; switch (this.props.mode) { - case 'horizontal': - openAnimation = 'slide-up'; - break; - case 'vertical': - openAnimation = 'zoom'; - break; - case 'inline': - openAnimation = animation; - break; + case 'horizontal': + openAnimation = 'slide-up'; + break; + case 'vertical': + openAnimation = 'zoom'; + break; + case 'inline': + openAnimation = animation; + break; + default: } if (this.props.mode === 'inline') { return ; diff --git a/components/message/index.jsx b/components/message/index.jsx index 9f9ddb20de..56b6a89518 100644 --- a/components/message/index.jsx +++ b/components/message/index.jsx @@ -3,8 +3,7 @@ import Notification from 'rc-notification'; let defaultDuration = 1.5; let top; - -var messageInstance; +let messageInstance; function getMessageInstance() { messageInstance = messageInstance || Notification.newInstance({ diff --git a/components/modal/confirm.jsx b/components/modal/confirm.jsx index 5d334cd49c..5d43a80674 100644 --- a/components/modal/confirm.jsx +++ b/components/modal/confirm.jsx @@ -1,12 +1,12 @@ import React from 'react'; import Dialog from './index'; -var div; +let div; export default function (props) { - var d; + let d; props = props || {}; props.iconClassName = props.iconClassName || 'anticon-exclamation-circle'; - var width = props.width || 375; + let width = props.width || 375; function close() { d.setState({ @@ -15,9 +15,9 @@ export default function (props) { } function onCancel() { - var cancelFn = props.onCancel; + let cancelFn = props.onCancel; if (cancelFn) { - var ret; + let ret; if (cancelFn.length) { ret = cancelFn(close); } else { @@ -35,9 +35,9 @@ export default function (props) { } function onOk() { - var okFn = props.onOk; + let okFn = props.onOk; if (okFn) { - var ret; + let ret; if (okFn.length) { ret = okFn(close); } else { @@ -54,12 +54,12 @@ export default function (props) { } } - var body =
+ let body =
{props.title}
{props.content}
; - var footer =
+ let footer =
; diff --git a/components/notification/index.jsx b/components/notification/index.jsx index 4809747007..ec4ce3efa5 100644 --- a/components/notification/index.jsx +++ b/components/notification/index.jsx @@ -1,6 +1,6 @@ +import React from 'react'; import Notification from 'rc-notification'; import assign from 'object-assign'; -import React from 'react'; let top = 24; let notificationInstance; @@ -31,20 +31,20 @@ function notice(args) { let prefixCls = ' ant-notification-notice-content-icon-'; let iconClass = 'anticon anticon-'; switch (args.icon) { - case 'success': - iconClass += 'check-circle-o'; - break; - case 'info': - iconClass += 'info-circle-o'; - break; - case 'error': - iconClass += 'exclamation-circle-o'; - break; - case 'warn': - iconClass += 'question-circle-o'; - break; - default: - iconClass += 'info-circle'; + case 'success': + iconClass += 'check-circle-o'; + break; + case 'info': + iconClass += 'info-circle-o'; + break; + case 'error': + iconClass += 'exclamation-circle-o'; + break; + case 'warn': + iconClass += 'question-circle-o'; + break; + default: + iconClass += 'info-circle'; } getNotificationInstance().notice({ @@ -94,7 +94,7 @@ function notice(args) { } } -var api = { +let api = { open(args){ notice(args); }, @@ -110,7 +110,7 @@ var api = { ['success', 'info', 'warn', 'error'].forEach((type) => { api[type] = (args) => { - var newArgs = assign({}, args, { + let newArgs = assign({}, args, { icon: type }); return api.open(newArgs); diff --git a/components/progress/index.jsx b/components/progress/index.jsx index 1d1f5f1bc0..d5042cd482 100644 --- a/components/progress/index.jsx +++ b/components/progress/index.jsx @@ -10,7 +10,7 @@ const statusColorMap = { 'success': '#87d068' }; -var Line = React.createClass({ +let Line = React.createClass({ propTypes: { status: React.PropTypes.oneOf(['normal', 'exception', 'active', 'success']), showInfo: React.PropTypes.bool, @@ -26,13 +26,14 @@ var Line = React.createClass({ }; }, render() { - var props = assign({}, this.props); + let props = assign({}, this.props); - if (parseInt(props.percent) === 100) { + if (parseInt(props.percent, 10) === 100) { props.status = 'success'; } - var progressInfo, fullCls = ''; + let progressInfo; + let fullCls = ''; if(props.showInfo === true){ if (props.status === 'exception') { progressInfo = ( @@ -54,7 +55,7 @@ var Line = React.createClass({ }else { fullCls = ' ' + prefixCls + '-line-wrap-full'; } - var percentStyle = { + let percentStyle = { width: props.percent + '%', height: props.strokeWidth }; @@ -72,7 +73,7 @@ var Line = React.createClass({ } }); -var Circle = React.createClass({ +let Circle = React.createClass({ getDefaultProps: function () { return { width: 132, @@ -82,22 +83,22 @@ var Circle = React.createClass({ }; }, render() { - var props = assign({}, this.props); + let props = assign({}, this.props); - if (parseInt(props.percent) === 100) { + if (parseInt(props.percent, 10) === 100) { props.status = 'success'; } - var style = { + let style = { 'width': props.width, 'height': props.width, 'fontSize': props.width * 0.16 + 6 }; - var progressInfo; + let progressInfo; if (props.status === 'exception') { progressInfo = ( - + ); } else if (props.status === 'success') { @@ -128,5 +129,3 @@ export default { Line: Line, Circle: Circle }; - - diff --git a/components/radio/group.jsx b/components/radio/group.jsx index 85064c75ad..5aadfd88f7 100644 --- a/components/radio/group.jsx +++ b/components/radio/group.jsx @@ -2,7 +2,7 @@ import React from 'react'; import Radio from './radio'; function getCheckedValue(children) { - var checkedValue = null; + let checkedValue = null; React.Children.forEach(children, function (radio) { if (radio.props && radio.props.checked) { checkedValue = radio.props.value; @@ -20,7 +20,7 @@ export default React.createClass({ }; }, getInitialState: function () { - var props = this.props; + let props = this.props; return { value: props.value || props.defaultValue || getCheckedValue(props.children) }; @@ -33,8 +33,8 @@ export default React.createClass({ } }, render: function () { - var props = this.props; - var children = React.Children.map(props.children, (radio) => { + let props = this.props; + let children = React.Children.map(props.children, (radio) => { if (radio.props) { return
diff --git a/components/tooltip/index.jsx b/components/tooltip/index.jsx index 1b8ee09cec..4ac4b05b1b 100644 --- a/components/tooltip/index.jsx +++ b/components/tooltip/index.jsx @@ -8,7 +8,7 @@ export default React.createClass({ }; }, render() { - var transitionName = ({ + let transitionName = ({ top: 'zoom-down', bottom: 'zoom-up', left: 'zoom-right', diff --git a/components/upload/uploadList.jsx b/components/upload/uploadList.jsx index 7edb042235..8ef510a06e 100644 --- a/components/upload/uploadList.jsx +++ b/components/upload/uploadList.jsx @@ -1,5 +1,4 @@ import React from 'react'; -import getFileItem from './getFileItem'; const prefixCls = 'ant-upload'; import Animate from 'rc-animate'; diff --git a/package.json b/package.json index 062027911f..2c3cc7c570 100644 --- a/package.json +++ b/package.json @@ -65,14 +65,17 @@ "velocity-animate": "^1.2.2" }, "devDependencies": { - "autoprefixer-loader": "~2.0.0", + "autoprefixer-loader": "^2.0.0", "babel": "^5.8.12", "babel-core": "^5.8.12", + "babel-eslint": "^4.1.0", "babel-loader": "^5.3.2", "busboy": "^0.2.9", "chalk": "^1.1.0", "css-loader": "^0.14.1", "eslint": "^1.1.0", + "eslint-config-airbnb": "^0.0.8", + "eslint-plugin-babel": "^2.1.1", "eslint-plugin-react": "^3.3.1", "extract-text-webpack-plugin": "^0.8.1", "gh-pages": "^0.3.1",