update eslintrc and fix code

This commit is contained in:
afc163 2015-09-01 16:18:46 +08:00
parent 23243844ba
commit 691b0147b1
23 changed files with 160 additions and 136 deletions

View File

@ -1,35 +1,43 @@
{ {
"rules": { "extends": ["eslint-config-airbnb"],
"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
},
"env": { "env": {
"es6": true,
"browser": true, "browser": true,
"node": true "node": true
}, },
"ecmaFeatures": { "ecmaFeatures": {
"jsx": true, "jsx": true
"modules": true
}, },
"parser": "babel-eslint",
"plugins": [ "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
}
} }

View File

@ -10,7 +10,7 @@
var Affix = antd.Affix; var Affix = antd.Affix;
React.render( React.render(
<Affix offset="75"> <Affix offset={75}>
<button className="ant-btn ant-btn-primary">固定在距离顶部 75px 的位置</button> <button className="ant-btn ant-btn-primary">固定在距离顶部 75px 的位置</button>
</Affix> </Affix>
, document.getElementById('components-affix-demo-offset')); , document.getElementById('components-affix-demo-offset'));

View File

@ -3,10 +3,10 @@ import joinClasses from 'react/lib/joinClasses';
import rcUtil from 'rc-util'; import rcUtil from 'rc-util';
function getScroll(w, top) { function getScroll(w, top) {
var ret = w['page' + (top ? 'Y' : 'X') + 'Offset']; let ret = w['page' + (top ? 'Y' : 'X') + 'Offset'];
var method = 'scroll' + (top ? 'Top' : 'Left'); let method = 'scroll' + (top ? 'Top' : 'Left');
if (typeof ret !== 'number') { if (typeof ret !== 'number') {
var d = w.document; let d = w.document;
//ie6,7,8 standard mode //ie6,7,8 standard mode
ret = d.documentElement[method]; ret = d.documentElement[method];
if (typeof ret !== 'number') { if (typeof ret !== 'number') {
@ -18,12 +18,12 @@ function getScroll(w, top) {
} }
function getOffset(element) { function getOffset(element) {
var rect = element.getBoundingClientRect(); let rect = element.getBoundingClientRect();
var body = document.body; let body = document.body;
var clientTop = element.clientTop || body.clientTop || 0; let clientTop = element.clientTop || body.clientTop || 0;
var clientLeft = element.clientLeft || body.clientLeft || 0; let clientLeft = element.clientLeft || body.clientLeft || 0;
var scrollTop = getScroll(window, true); let scrollTop = getScroll(window, true);
var scrollLeft = getScroll(window); let scrollLeft = getScroll(window);
return { return {
top: rect.top + scrollTop - clientTop, top: rect.top + scrollTop - clientTop,
@ -31,7 +31,7 @@ function getOffset(element) {
}; };
} }
var Affix = React.createClass({ let Affix = React.createClass({
getDefaultProps() { getDefaultProps() {
return { return {
@ -39,6 +39,10 @@ var Affix = React.createClass({
}; };
}, },
propTypes: {
offset: React.PropTypes.number
},
getInitialState() { getInitialState() {
return { return {
affix: false, affix: false,
@ -47,9 +51,9 @@ var Affix = React.createClass({
}, },
handleScroll() { handleScroll() {
var affix = this.state.affix; let affix = this.state.affix;
var scrollTop = getScroll(window, true); let scrollTop = getScroll(window, true);
var elemOffset = getOffset(this.getDOMNode()); let elemOffset = getOffset(this.getDOMNode());
if (!affix && (elemOffset.top - this.props.offset) < scrollTop) { if (!affix && (elemOffset.top - this.props.offset) < scrollTop) {
this.setState({ this.setState({
@ -85,8 +89,8 @@ var Affix = React.createClass({
}, },
render() { render() {
var affix = this.state.affix ? 'ant-affix' : ''; let affix = this.state.affix ? 'ant-affix' : '';
var className = this.props.className; let className = this.props.className;
return ( return (
<div {...this.props}> <div {...this.props}>

View File

@ -34,7 +34,7 @@ export default React.createClass({
}); });
}, },
render() { render() {
var iconClass = this.props.description ? let iconClass = this.props.description ?
'ant-alert-with-description-icon anticon-' : 'ant-alert-icon anticon-'; 'ant-alert-with-description-icon anticon-' : 'ant-alert-icon anticon-';
switch (this.props.type) { switch (this.props.type) {
case 'success': case 'success':
@ -52,11 +52,12 @@ export default React.createClass({
default: default:
iconClass += '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) { if (this.props.description) {
let close = this.props.closable ? let close = this.props.closable ?
<a onClick={this.handleClose} className={'ant-alert-with-description-close-icon'}> <a onClick={this.handleClose} className={'ant-alert-with-description-close-icon'}>
<span className='ant-alert-with-description-close-icon-x'></span> <span className="ant-alert-with-description-close-icon-x"></span>
</a> : ''; </a> : '';
html = <div data-show={this.state.closing} className={'ant-alert-with-description ant-alert-with-description-' + this.props.type + closeName}> html = <div data-show={this.state.closing} className={'ant-alert-with-description ant-alert-with-description-' + this.props.type + closeName}>
<i className={'anticon ' + iconClass}></i> <i className={'anticon ' + iconClass}></i>
@ -74,7 +75,7 @@ export default React.createClass({
} else { } else {
let close = this.props.closable ? let close = this.props.closable ?
<a onClick={this.handleClose} className={'ant-alert-close-icon'}> <a onClick={this.handleClose} className={'ant-alert-close-icon'}>
<span className='ant-alert-close-icon-x'></span> <span className="ant-alert-close-icon-x"></span>
</a> : ''; </a> : '';
html = <div data-show={this.state.closing} className={'ant-alert ant-alert-' + this.props.type + closeName}> html = <div data-show={this.state.closing} className={'ant-alert ant-alert-' + this.props.type + closeName}>
<i className={'anticon ' + iconClass}></i> <i className={'anticon ' + iconClass}></i>
@ -85,7 +86,7 @@ export default React.createClass({
} }
return this.state.closed ? null : <Animate return this.state.closed ? null : <Animate
component="" component=""
showProp='data-show' showProp="data-show"
transitionName="slide-up" transitionName="slide-up"
onEnd={this.animationEnd}> onEnd={this.animationEnd}>
{html} {html}

View File

@ -38,4 +38,8 @@ AntBadge.defaultProps = {
dot: false dot: false
}; };
AntBadge.propTypes = {
dot: React.PropTypes.bool
};
export default AntBadge; export default AntBadge;

View File

@ -3,9 +3,12 @@ import React from 'react';
let prefixCls = 'ant-breadcrumb'; let prefixCls = 'ant-breadcrumb';
let BreadcrumbItem = React.createClass({ let BreadcrumbItem = React.createClass({
propTypes: {
href: React.PropTypes.string
},
render() { render() {
var link = <a className={prefixCls + '-link'} {...this.props}>{this.props.children}</a>; let link = <a className={prefixCls + '-link'} {...this.props}>{this.props.children}</a>;
var slash = <span className={prefixCls + '-slash'}>/</span>; let slash = <span className={prefixCls + '-slash'}>/</span>;
if (typeof this.props.href === 'undefined') { if (typeof this.props.href === 'undefined') {
link = <span className={prefixCls + '-link'} {...this.props}>{this.props.children}</span>; link = <span className={prefixCls + '-link'} {...this.props}>{this.props.children}</span>;
} }
@ -14,6 +17,9 @@ let BreadcrumbItem = React.createClass({
}); });
let Breadcrumb = React.createClass({ let Breadcrumb = React.createClass({
propTypes: {
router: React.PropTypes.object
},
contextTypes: { contextTypes: {
router: React.PropTypes.object router: React.PropTypes.object
}, },
@ -21,14 +27,14 @@ let Breadcrumb = React.createClass({
let crumbs, routes, params; let crumbs, routes, params;
let ReactRouter = this.props.router; let ReactRouter = this.props.router;
if (this.context.router && ReactRouter) { if (this.context.router && ReactRouter) {
var Link = ReactRouter.Link; let Link = ReactRouter.Link;
routes = this.context.router.state.branch; routes = this.context.router.state.branch;
params = this.context.router.state.params; params = this.context.router.state.params;
crumbs = routes.map(function(route, i) { 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; return params[key] || replacement;
}); });
var link; let link;
if (i === routes.length - 1) { if (i === routes.length - 1) {
link = <span>{name}</span>; link = <span>{name}</span>;
} else { } else {

View File

@ -16,10 +16,10 @@ let defaultCalendarValue = new GregorianCalendar(zhCn);
defaultCalendarValue.setTime(Date.now()); defaultCalendarValue.setTime(Date.now());
function createPicker(Calendar) { function createPicker(TheCalendar) {
return React.createClass({ return React.createClass({
getInitialState() { getInitialState() {
var value; let value;
if (this.props.value) { if (this.props.value) {
value = new GregorianCalendar(zhCn); value = new GregorianCalendar(zhCn);
value.setTime(new Date(this.props.value).valueOf()); value.setTime(new Date(this.props.value).valueOf());
@ -56,8 +56,8 @@ function createPicker(Calendar) {
this.props.onSelect(new Date(v.getTime())); this.props.onSelect(new Date(v.getTime()));
}, },
render() { render() {
var calendar = ( let calendar = (
<Calendar <TheCalendar
disabledDate={this.props.disabledDate} disabledDate={this.props.disabledDate}
locale={CalendarLocale} locale={CalendarLocale}
orient={['top', 'left']} orient={['top', 'left']}
@ -65,9 +65,9 @@ function createPicker(Calendar) {
showTime={this.props.showTime} showTime={this.props.showTime}
prefixCls="ant-calendar" prefixCls="ant-calendar"
showOk={this.props.showTime} showOk={this.props.showTime}
showClear={false}/> showClear={false} />
); );
var sizeClass = ''; let sizeClass = '';
if (this.props.size === 'large') { if (this.props.size === 'large') {
sizeClass = ' ant-input-lg'; sizeClass = ' ant-input-lg';
} else if (this.props.size === 'small') { } else if (this.props.size === 'small') {

View File

@ -8,7 +8,7 @@ export default React.createClass({
}; };
}, },
render() { render() {
var sizeClass = ''; let sizeClass = '';
if (this.props.size === 'large') { if (this.props.size === 'large') {
sizeClass = 'ant-input-number-lg'; sizeClass = 'ant-input-number-lg';
} else if (this.props.size === 'small') { } else if (this.props.size === 'small') {

View File

@ -20,6 +20,7 @@ const AntMenu = React.createClass({
case 'inline': case 'inline':
openAnimation = animation; openAnimation = animation;
break; break;
default:
} }
if (this.props.mode === 'inline') { if (this.props.mode === 'inline') {
return <Menu {...this.props} openAnimation={openAnimation} />; return <Menu {...this.props} openAnimation={openAnimation} />;

View File

@ -3,8 +3,7 @@ import Notification from 'rc-notification';
let defaultDuration = 1.5; let defaultDuration = 1.5;
let top; let top;
let messageInstance;
var messageInstance;
function getMessageInstance() { function getMessageInstance() {
messageInstance = messageInstance || Notification.newInstance({ messageInstance = messageInstance || Notification.newInstance({

View File

@ -1,12 +1,12 @@
import React from 'react'; import React from 'react';
import Dialog from './index'; import Dialog from './index';
var div; let div;
export default function (props) { export default function (props) {
var d; let d;
props = props || {}; props = props || {};
props.iconClassName = props.iconClassName || 'anticon-exclamation-circle'; props.iconClassName = props.iconClassName || 'anticon-exclamation-circle';
var width = props.width || 375; let width = props.width || 375;
function close() { function close() {
d.setState({ d.setState({
@ -15,9 +15,9 @@ export default function (props) {
} }
function onCancel() { function onCancel() {
var cancelFn = props.onCancel; let cancelFn = props.onCancel;
if (cancelFn) { if (cancelFn) {
var ret; let ret;
if (cancelFn.length) { if (cancelFn.length) {
ret = cancelFn(close); ret = cancelFn(close);
} else { } else {
@ -35,9 +35,9 @@ export default function (props) {
} }
function onOk() { function onOk() {
var okFn = props.onOk; let okFn = props.onOk;
if (okFn) { if (okFn) {
var ret; let ret;
if (okFn.length) { if (okFn.length) {
ret = okFn(close); ret = okFn(close);
} else { } else {
@ -54,12 +54,12 @@ export default function (props) {
} }
} }
var body = <div className="ant-confirm-body"> let body = <div className="ant-confirm-body">
<i className={'anticon ' + props.iconClassName}></i> <i className={'anticon ' + props.iconClassName}></i>
<span className="ant-confirm-title">{props.title}</span> <span className="ant-confirm-title">{props.title}</span>
<div className="ant-confirm-content">{props.content}</div> <div className="ant-confirm-content">{props.content}</div>
</div>; </div>;
var footer = <div className="ant-confirm-btns"> let footer = <div className="ant-confirm-btns">
<button type="button" className="ant-btn-default ant-btn ant-btn-lg" onClick={onCancel}> </button> <button type="button" className="ant-btn-default ant-btn ant-btn-lg" onClick={onCancel}> </button>
<button type="button" className="ant-btn-primary ant-btn ant-btn-lg" onClick={onOk}> </button> <button type="button" className="ant-btn-primary ant-btn ant-btn-lg" onClick={onOk}> </button>
</div>; </div>;

View File

@ -1,6 +1,6 @@
import React from 'react';
import Notification from 'rc-notification'; import Notification from 'rc-notification';
import assign from 'object-assign'; import assign from 'object-assign';
import React from 'react';
let top = 24; let top = 24;
let notificationInstance; let notificationInstance;
@ -94,7 +94,7 @@ function notice(args) {
} }
} }
var api = { let api = {
open(args){ open(args){
notice(args); notice(args);
}, },
@ -110,7 +110,7 @@ var api = {
['success', 'info', 'warn', 'error'].forEach((type) => { ['success', 'info', 'warn', 'error'].forEach((type) => {
api[type] = (args) => { api[type] = (args) => {
var newArgs = assign({}, args, { let newArgs = assign({}, args, {
icon: type icon: type
}); });
return api.open(newArgs); return api.open(newArgs);

View File

@ -10,7 +10,7 @@ const statusColorMap = {
'success': '#87d068' 'success': '#87d068'
}; };
var Line = React.createClass({ let Line = React.createClass({
propTypes: { propTypes: {
status: React.PropTypes.oneOf(['normal', 'exception', 'active', 'success']), status: React.PropTypes.oneOf(['normal', 'exception', 'active', 'success']),
showInfo: React.PropTypes.bool, showInfo: React.PropTypes.bool,
@ -26,13 +26,14 @@ var Line = React.createClass({
}; };
}, },
render() { 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'; props.status = 'success';
} }
var progressInfo, fullCls = ''; let progressInfo;
let fullCls = '';
if(props.showInfo === true){ if(props.showInfo === true){
if (props.status === 'exception') { if (props.status === 'exception') {
progressInfo = ( progressInfo = (
@ -54,7 +55,7 @@ var Line = React.createClass({
}else { }else {
fullCls = ' ' + prefixCls + '-line-wrap-full'; fullCls = ' ' + prefixCls + '-line-wrap-full';
} }
var percentStyle = { let percentStyle = {
width: props.percent + '%', width: props.percent + '%',
height: props.strokeWidth height: props.strokeWidth
}; };
@ -72,7 +73,7 @@ var Line = React.createClass({
} }
}); });
var Circle = React.createClass({ let Circle = React.createClass({
getDefaultProps: function () { getDefaultProps: function () {
return { return {
width: 132, width: 132,
@ -82,22 +83,22 @@ var Circle = React.createClass({
}; };
}, },
render() { 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'; props.status = 'success';
} }
var style = { let style = {
'width': props.width, 'width': props.width,
'height': props.width, 'height': props.width,
'fontSize': props.width * 0.16 + 6 'fontSize': props.width * 0.16 + 6
}; };
var progressInfo; let progressInfo;
if (props.status === 'exception') { if (props.status === 'exception') {
progressInfo = ( progressInfo = (
<span className={prefixCls + '-circle-text'}> <span className={prefixCls + '-circle-text'}>
<i className='anticon anticon-exclamation'></i> <i className="anticon anticon-exclamation"></i>
</span> </span>
); );
} else if (props.status === 'success') { } else if (props.status === 'success') {
@ -128,5 +129,3 @@ export default {
Line: Line, Line: Line,
Circle: Circle Circle: Circle
}; };

View File

@ -2,7 +2,7 @@ import React from 'react';
import Radio from './radio'; import Radio from './radio';
function getCheckedValue(children) { function getCheckedValue(children) {
var checkedValue = null; let checkedValue = null;
React.Children.forEach(children, function (radio) { React.Children.forEach(children, function (radio) {
if (radio.props && radio.props.checked) { if (radio.props && radio.props.checked) {
checkedValue = radio.props.value; checkedValue = radio.props.value;
@ -20,7 +20,7 @@ export default React.createClass({
}; };
}, },
getInitialState: function () { getInitialState: function () {
var props = this.props; let props = this.props;
return { return {
value: props.value || props.defaultValue || getCheckedValue(props.children) value: props.value || props.defaultValue || getCheckedValue(props.children)
}; };
@ -33,8 +33,8 @@ export default React.createClass({
} }
}, },
render: function () { render: function () {
var props = this.props; let props = this.props;
var children = React.Children.map(props.children, (radio) => { let children = React.Children.map(props.children, (radio) => {
if (radio.props) { if (radio.props) {
return <Radio return <Radio
key={radio.props.value} key={radio.props.value}

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import Select from 'rc-select'; import Select from 'rc-select';
var AntSelect = React.createClass({ let AntSelect = React.createClass({
getDefaultProps() { getDefaultProps() {
return { return {
prefixCls: 'ant-select', prefixCls: 'ant-select',

View File

@ -2,7 +2,7 @@ import React from 'react';
import Menu from 'rc-menu'; import Menu from 'rc-menu';
import Dropdown from '../dropdown'; import Dropdown from '../dropdown';
var FilterMenu = React.createClass({ let FilterMenu = React.createClass({
getInitialState() { getInitialState() {
return { return {
selectedKeys: this.props.selectedKeys selectedKeys: this.props.selectedKeys

View File

@ -35,7 +35,7 @@ class DataSource {
} }
} }
var AntTable = React.createClass({ let AntTable = React.createClass({
getInitialState() { getInitialState() {
return { return {
// //

View File

@ -4,7 +4,7 @@ const prefixCls = 'ant-tabs';
class AntTabs extends React.Component { class AntTabs extends React.Component {
render() { render() {
var sizeCls = ''; let sizeCls = '';
if (this.props.size === 'mini') { if (this.props.size === 'mini') {
sizeCls = prefixCls + '-mini'; sizeCls = prefixCls + '-mini';
} }

View File

@ -39,7 +39,7 @@ class AntTag extends React.Component {
return this.state.closed ? null return this.state.closed ? null
: <Animate component="" : <Animate component=""
showProp='data-show' showProp="data-show"
transitionName="zoom-tag" transitionName="zoom-tag"
onEnd={this.animationEnd.bind(this)}> onEnd={this.animationEnd.bind(this)}>
<div data-show={!this.state.closing} className={className}> <div data-show={!this.state.closing} className={className}>

View File

@ -8,7 +8,7 @@ export default React.createClass({
}; };
}, },
render() { render() {
var transitionName = ({ let transitionName = ({
top: 'zoom-down', top: 'zoom-down',
bottom: 'zoom-up', bottom: 'zoom-up',
left: 'zoom-right', left: 'zoom-right',

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import getFileItem from './getFileItem';
const prefixCls = 'ant-upload'; const prefixCls = 'ant-upload';
import Animate from 'rc-animate'; import Animate from 'rc-animate';

View File

@ -65,14 +65,17 @@
"velocity-animate": "^1.2.2" "velocity-animate": "^1.2.2"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer-loader": "~2.0.0", "autoprefixer-loader": "^2.0.0",
"babel": "^5.8.12", "babel": "^5.8.12",
"babel-core": "^5.8.12", "babel-core": "^5.8.12",
"babel-eslint": "^4.1.0",
"babel-loader": "^5.3.2", "babel-loader": "^5.3.2",
"busboy": "^0.2.9", "busboy": "^0.2.9",
"chalk": "^1.1.0", "chalk": "^1.1.0",
"css-loader": "^0.14.1", "css-loader": "^0.14.1",
"eslint": "^1.1.0", "eslint": "^1.1.0",
"eslint-config-airbnb": "^0.0.8",
"eslint-plugin-babel": "^2.1.1",
"eslint-plugin-react": "^3.3.1", "eslint-plugin-react": "^3.3.1",
"extract-text-webpack-plugin": "^0.8.1", "extract-text-webpack-plugin": "^0.8.1",
"gh-pages": "^0.3.1", "gh-pages": "^0.3.1",