Skip to content

Commit

Permalink
Impose 'brace-style' 'default-case' and 'ident' rules
Browse files Browse the repository at this point in the history
part of `airbnb` style
  • Loading branch information
AlexKVal committed Aug 27, 2015
1 parent 886054d commit 9dbf33b
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 159 deletions.
3 changes: 0 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
"babel"
],
"rules": {
"brace-style": 0,
"constructor-super": 2,
"comma-dangle": 0,
"comma-spacing": 2,
"comma-style": [2, "last"],
"default-case": 0,
"func-names": 0,
"guard-for-in": 0,
"indent": 0,
"one-var": [2, { "initialized": "never" }],
"padded-blocks": 0,
"prefer-const": 0,
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/ButtonInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const ButtonInputExample = React.createClass({
let length = this.refs.input.getValue().length;
let style = 'danger';

if (length > 10) { style = 'success'; }
else if (length > 5) { style = 'warning'; }
if (length > 10) style = 'success';
else if (length > 5) style = 'warning';

let disabled = style !== 'success';

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const ExampleInput = React.createClass({

validationState() {
let length = this.state.value.length;
if (length > 10) { return 'success'; }
else if (length > 5) { return 'warning'; }
else if (length > 0) { return 'error'; }
if (length > 10) return 'success';
else if (length > 5) return 'warning';
else if (length > 0) return 'error';
},

handleChange() {
Expand Down
44 changes: 22 additions & 22 deletions docs/src/PropTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,28 @@ const PropTable = React.createClass({
let doclets = prop.doclets || {};

switch (name) {
case 'object':
return name;
case 'union':
return type.value.reduce((current, val, i, list) => {
let item = this.getType({ type: val });
if (React.isValidElement(item)) {
item = React.cloneElement(item, {key: i});
}
current = current.concat(item);

return i === (list.length - 1) ? current : current.concat(' | ');
}, []);
case 'array':
let child = this.getType({ type: type.value });

return <span>{'array<'}{ child }{'>'}</span>;
case 'enum':
return this.renderEnum(type);
case 'custom':
return cleanDocletValue(doclets.type || name);
default:
return name;
case 'object':
return name;
case 'union':
return type.value.reduce((current, val, i, list) => {
let item = this.getType({ type: val });
if (React.isValidElement(item)) {
item = React.cloneElement(item, {key: i});
}
current = current.concat(item);

return i === (list.length - 1) ? current : current.concat(' | ');
}, []);
case 'array':
let child = this.getType({ type: type.value });

return <span>{'array<'}{ child }{'>'}</span>;
case 'enum':
return this.renderEnum(type);
case 'custom':
return cleanDocletValue(doclets.type || name);
default:
return name;
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/AffixMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const AffixMixin = {

checkPosition() {
let DOMNode, scrollHeight, scrollTop, position, offsetTop, offsetBottom,
affix, affixType, affixPositionTop;
affix, affixType, affixPositionTop;

// TODO: or not visible
if (!this.isMounted()) {
Expand Down
24 changes: 12 additions & 12 deletions src/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,18 @@ const Carousel = React.createClass({
this.state.previousActiveIndex === index && this.props.slide;

return cloneElement(
child,
{
active: isActive,
ref: child.ref,
key: child.key ? child.key : index,
index,
animateOut: isPreviousActive,
animateIn: isActive && this.state.previousActiveIndex != null && this.props.slide,
direction: this.state.direction,
onAnimateOutEnd: isPreviousActive ? this.handleItemAnimateOutEnd : null
}
);
child,
{
active: isActive,
ref: child.ref,
key: child.key ? child.key : index,
index,
animateOut: isPreviousActive,
animateIn: isActive && this.state.previousActiveIndex != null && this.props.slide,
direction: this.state.direction,
onAnimateOutEnd: isPreviousActive ? this.handleItemAnimateOutEnd : null
}
);
},

handleSelect(index, direction) {
Expand Down
33 changes: 16 additions & 17 deletions src/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ class Dropdown extends React.Component {
};

switch(event.keyCode) {
case keycode.codes.down:
if (!this.props.open) {
this.toggleOpen();
}
else {
focusNext();
}
event.preventDefault();
break;
case keycode.codes.esc:
case keycode.codes.tab:
if (this.props.open) {
this.handleClose(event);
}
break;
case keycode.codes.down:
if (!this.props.open) {
this.toggleOpen();
} else {
focusNext();
}
event.preventDefault();
break;
case keycode.codes.esc:
case keycode.codes.tab:
if (this.props.open) {
this.handleClose(event);
}
break;
default:
}
}

Expand All @@ -133,8 +133,7 @@ class Dropdown extends React.Component {
// to the next focusable input
if (event && event.keyCode === keycode.codes.tab){
setTimeout(this.toggleOpen);
}
else {
} else {
this.toggleOpen();
}

Expand Down
25 changes: 13 additions & 12 deletions src/DropdownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ class DropdownMenu extends React.Component {
handleKeyDown(event) {

switch(event.keyCode) {
case keycode.codes.down:
this.focusNext();
event.preventDefault();
break;
case keycode.codes.up:
this.focusPrevious();
event.preventDefault();
break;
case keycode.codes.esc:
case keycode.codes.tab:
this.props.onClose(event);
break;
case keycode.codes.down:
this.focusNext();
event.preventDefault();
break;
case keycode.codes.up:
this.focusPrevious();
event.preventDefault();
break;
case keycode.codes.esc:
case keycode.codes.tab:
this.props.onClose(event);
break;
default:
}
}

Expand Down
47 changes: 24 additions & 23 deletions src/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ class InputBase extends React.Component {

let inputGroupClassName;
switch (this.props.bsSize) {
case 'small': inputGroupClassName = 'input-group-sm'; break;
case 'large': inputGroupClassName = 'input-group-lg'; break;
case 'small': inputGroupClassName = 'input-group-sm'; break;
case 'large': inputGroupClassName = 'input-group-lg'; break;
default:
}

return addonBefore || addonAfter || buttonBefore || buttonAfter ? (
Expand All @@ -98,10 +99,10 @@ class InputBase extends React.Component {
}

switch (this.props.bsStyle) {
case 'success': return <Glyphicon formControlFeedback glyph="ok" key="icon" />;
case 'warning': return <Glyphicon formControlFeedback glyph="warning-sign" key="icon" />;
case 'error': return <Glyphicon formControlFeedback glyph="remove" key="icon" />;
default: return <span className="form-control-feedback" key="icon" />;
case 'success': return <Glyphicon formControlFeedback glyph="ok" key="icon" />;
case 'warning': return <Glyphicon formControlFeedback glyph="warning-sign" key="icon" />;
case 'error': return <Glyphicon formControlFeedback glyph="remove" key="icon" />;
default: return <span className="form-control-feedback" key="icon" />;
}
} else {
return null;
Expand Down Expand Up @@ -157,24 +158,24 @@ class InputBase extends React.Component {
}

switch (this.props.type) {
case 'select':
return (
<select {...this.props} className={classNames(this.props.className, 'form-control')} ref="input" key="input">
{this.props.children}
</select>
);
case 'textarea':
return <textarea {...this.props} className={classNames(this.props.className, 'form-control')} ref="input" key="input" />;
case 'static':
return (
<p {...this.props} className={classNames(this.props.className, 'form-control-static')} ref="input" key="input">
{this.props.value}
</p>
);
case 'select':
return (
<select {...this.props} className={classNames(this.props.className, 'form-control')} ref="input" key="input">
{this.props.children}
</select>
);
case 'textarea':
return <textarea {...this.props} className={classNames(this.props.className, 'form-control')} ref="input" key="input" />;
case 'static':
return (
<p {...this.props} className={classNames(this.props.className, 'form-control-static')} ref="input" key="input">
{this.props.value}
</p>
);
default:
const className = this.isCheckboxOrRadio() || this.isFile() ? '' : 'form-control';
return <input {...this.props} className={classNames(this.props.className, className)} ref="input" key="input" />;
}

let className = this.isCheckboxOrRadio() || this.isFile() ? '' : 'form-control';
return <input {...this.props} className={classNames(this.props.className, className)} ref="input" key="input" />;
}

renderFormGroup(children) {
Expand Down
20 changes: 10 additions & 10 deletions src/NavItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ const NavItem = React.createClass({
'aria-controls': ariaControls,
...props } = this.props;
let classes = {
active,
disabled
};
active,
disabled
};
let linkProps = {
role,
href,
title,
target,
id: linkId,
onClick: this.handleClick
};
role,
href,
title,
target,
id: linkId,
onClick: this.handleClick
};

if (!role && href === '#') {
linkProps.role = 'button';
Expand Down
2 changes: 1 addition & 1 deletion src/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const Navbar = React.createClass({
<span className="icon-bar" key={1}></span>,
<span className="icon-bar" key={2}></span>,
<span className="icon-bar" key={3}></span>
];
];

return (
<button className="navbar-toggle" type="button" onClick={this.handleToggle}>
Expand Down
4 changes: 2 additions & 2 deletions src/Overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Overlay.propTypes = {
* Use animation
*/
animation: React.PropTypes.oneOfType([
React.PropTypes.bool,
CustomPropTypes.elementType
React.PropTypes.bool,
CustomPropTypes.elementType
]),

/**
Expand Down
2 changes: 1 addition & 1 deletion src/SplitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SplitButton extends React.Component {
bsStyle, // eslint-disable-line
...props } = this.props;

let { disabled } = props;
let { disabled } = props;

let button = (
<Button
Expand Down
20 changes: 10 additions & 10 deletions src/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ const Tabs = React.createClass({
let paneIsAlreadyActive = previousActiveKey != null && child.props.eventKey === previousActiveKey;

return cloneElement(
child,
{
active: shouldPaneBeSetActive && (thereIsNoActivePane || !this.props.animation),
id: paneId(this.props, child),
'aria-labelledby': tabId(this.props, child),
key: child.key ? child.key : index,
animation: this.props.animation,
onAnimateOutEnd: paneIsAlreadyActive ? this.handlePaneAnimateOutEnd : null
}
);
child,
{
active: shouldPaneBeSetActive && (thereIsNoActivePane || !this.props.animation),
id: paneId(this.props, child),
'aria-labelledby': tabId(this.props, child),
key: child.key ? child.key : index,
animation: this.props.animation,
onAnimateOutEnd: paneIsAlreadyActive ? this.handlePaneAnimateOutEnd : null
}
);
},

renderTab(child) {
Expand Down
6 changes: 2 additions & 4 deletions src/Thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const Thumbnail = React.createClass({
<img src={this.props.src} alt={this.props.alt} />
</SafeAnchor>
);
}
else {
} else {
if(this.props.children) {
return (
<div {...this.props} className={classSet(this.props.className, classes)}>
Expand All @@ -38,8 +37,7 @@ const Thumbnail = React.createClass({
</div>
</div>
);
}
else {
} else {
return (
<div {...this.props} className={classSet(this.props.className, classes)}>
<img src={this.props.src} alt={this.props.alt} />
Expand Down
4 changes: 1 addition & 3 deletions src/utils/deprecationWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ function deprecationWarning(oldname, newname, link) {

if (typeof oldname === 'object'){
message = oldname.message;
}
else {
} else {
message = `${oldname} is deprecated. Use ${newname} instead.`;

if (link) {
Expand Down Expand Up @@ -38,4 +37,3 @@ deprecationWarning.wrapper = function(Component, ...args){
};

export default deprecationWarning;

Loading

0 comments on commit 9dbf33b

Please sign in to comment.