Set ESLint 'curly' rule in 'multi-line + consistent' mode

eslint-config-openstack enables curly rule in "all" mode, which
may be incovenient for one-line ifs and cycles.

Change-Id: Ic94681ec5dc971070fb57f9310dbc24b0298b409
Implements: blueprint converge-to-eslint-config-openstack
This commit is contained in:
Vitaly Kramskikh 2016-01-27 22:44:59 +03:00
parent e4347fe089
commit 28c5b6ba90
15 changed files with 159 additions and 120 deletions

View File

@ -5,12 +5,14 @@
# disabled rules from openstack config
no-empty: 0 # we use empty blocks with try-catch
no-extra-parens: 0 # extra parens are preferred with JSX
curly: 0 # we're ok with one-line if
operator-linebreak: 0 # disabled due to heavy use of ternary operator in JSX
no-warning-comments: 0 # we're ok with FIXMEs
no-undefined: 0 # we're ok with using undefined
no-process-env: 0 # we use it in a few places and are ok with it
# overridden rules from openstack config
curly: [2, multi-line, consistent] # openstack config uses 'all' mode, but we're ok with braceless one-liners
# extra rules
no-unexpected-multiline: 2
dot-location: [2, property]

View File

@ -38,8 +38,9 @@ export function dispatcherMixin(events, callback) {
export var unsavedChangesMixin = {
onBeforeunloadEvent() {
if (this.hasChanges()) return _.result(this, 'getStayMessage') ||
i18n('dialog.dismiss_settings.default_message');
if (this.hasChanges()) {
return _.result(this, 'getStayMessage') || i18n('dialog.dismiss_settings.default_message');
}
},
componentWillMount() {
this.eventName = _.uniqueId('unsavedchanges');

View File

@ -805,11 +805,12 @@ models.Volume = BaseModel.extend({
getMinimalSize(minimum) {
var currentDisk = this.collection.disk;
var groupAllocatedSpace = 0;
if (currentDisk && currentDisk.collection)
if (currentDisk && currentDisk.collection) {
groupAllocatedSpace = currentDisk.collection.reduce((sum, disk) => {
return disk.id === currentDisk.id ? sum : sum +
disk.get('volumes').findWhere({name: this.get('name')}).get('size');
}, 0);
}
return minimum - groupAllocatedSpace;
},
getMaxSize() {

View File

@ -52,12 +52,13 @@ define([
})
.findAllByCssSelector('div.confirm-deletion-form input[type=text]')
.then(function(confirmInputs) {
if (confirmInputs.length)
if (confirmInputs.length) {
return confirmInputs[0]
.type(clusterName)
.then(function() {
return self.modal.clickFooterButton('Delete');
});
}
})
.end()
.then(function() {
@ -126,12 +127,13 @@ define([
})
.findAllByCssSelector('div.confirm-reset-form input[type=text]')
.then(function(confirmationInputs) {
if (confirmationInputs.length)
if (confirmationInputs.length) {
return confirmationInputs[0]
.type(clusterName)
.then(function() {
return self.modal.clickFooterButton('Reset');
});
}
})
.end()
.then(function() {

View File

@ -142,8 +142,9 @@ define([
.getVisibleText()
.then(function(name) {
name = _.trim(name);
if (!_.contains(ifcsNames, name))
if (!_.contains(ifcsNames, name)) {
throw new Error('Unexpected name in bond: ' + name);
}
});
});
});

View File

@ -53,14 +53,16 @@ define([
return buttons.reduce(function(result, button) {
return button.getVisibleText()
.then(function(buttonTitle) {
if (buttonTitle === buttonText)
if (buttonTitle === buttonText) {
return button.isEnabled()
.then(function(isEnabled) {
if (isEnabled) {
return button.click();
} else
} else {
throw Error('Unable to click disabled button "' + buttonText + '"');
}
});
}
return result;
});
}, null);

View File

@ -131,12 +131,14 @@ var DashboardLinks = React.createClass({
<div className='dashboard-block links-block clearfix'>
<div className='col-xs-12'>
{links.map((link, index) => {
if (index % 2 === 0) return (
<div className='row' key={link.url}>
{this.renderLink(link)}
{index + 1 < links.length && this.renderLink(links[index + 1])}
</div>
);
if (index % 2 === 0) {
return (
<div className='row' key={link.url}>
{this.renderLink(link)}
{index + 1 < links.length && this.renderLink(links[index + 1])}
</div>
);
}
}, this)}
</div>
</div>

View File

@ -138,13 +138,15 @@ var ScreenTransitionWrapper = React.createClass({
$(ReactDOM.findDOMNode(this)).fadeOut('fast', cb);
},
render() {
if (this.props.loading) return (
<div className='row'>
<div className='col-xs-12' style={{paddingTop: '40px'}}>
<ProgressBar />
if (this.props.loading) {
return (
<div className='row'>
<div className='col-xs-12' style={{paddingTop: '40px'}}>
<ProgressBar />
</div>
</div>
</div>
);
);
}
return <div>{this.props.children}</div>;
}
});

View File

@ -486,22 +486,24 @@ var EditNodeInterfacesScreen = React.createClass({
<div className='ifc-list col-xs-12'>
{interfaces.map((ifc, index) => {
var ifcName = ifc.get('name');
if (!_.contains(slaveInterfaceNames, ifcName)) return (
<NodeInterfaceDropTarget {...this.props}
key={'interface-' + ifcName}
interface={ifc}
locked={locked}
bondingAvailable={bondingAvailable}
configurationTemplateExists={configurationTemplateExists}
errors={this.state.interfaceErrors[ifcName]}
validate={this.validate}
removeInterfaceFromBond={this.removeInterfaceFromBond}
bondingProperties={this.props.bondingConfig.properties}
bondType={this.getBondType()}
interfaceSpeeds={interfaceSpeeds[index]}
interfaceNames={interfaceNames[index]}
/>
);
if (!_.contains(slaveInterfaceNames, ifcName)) {
return (
<NodeInterfaceDropTarget {...this.props}
key={'interface-' + ifcName}
interface={ifc}
locked={locked}
bondingAvailable={bondingAvailable}
configurationTemplateExists={configurationTemplateExists}
errors={this.state.interfaceErrors[ifcName]}
validate={this.validate}
removeInterfaceFromBond={this.removeInterfaceFromBond}
bondingProperties={this.props.bondingConfig.properties}
bondType={this.getBondType()}
interfaceSpeeds={interfaceSpeeds[index]}
interfaceNames={interfaceNames[index]}
/>
);
}
})}
</div>
<div className='col-xs-12 page-buttons content-elements'>

View File

@ -144,20 +144,22 @@ var Node = React.createClass({
this.setState(states);
},
renderNameControl() {
if (this.state.isRenaming) return (
<Input
ref='name'
type='text'
name='node-name'
defaultValue={this.props.node.get('name')}
inputClassName='form-control node-name-input'
disabled={this.state.actionInProgress}
onKeyDown={this.onNodeNameInputKeydown}
maxLength='100'
selectOnFocus
autoFocus
/>
);
if (this.state.isRenaming) {
return (
<Input
ref='name'
type='text'
name='node-name'
defaultValue={this.props.node.get('name')}
inputClassName='form-control node-name-input'
disabled={this.state.actionInProgress}
onKeyDown={this.onNodeNameInputKeydown}
maxLength='100'
selectOnFocus
autoFocus
/>
);
}
return (
<Tooltip text={i18n('cluster_page.nodes_tab.node.edit_name')}>
<p onClick={!this.state.actionInProgress && this.startRenaming}>

View File

@ -1696,18 +1696,20 @@ RolePanel = React.createClass({
assignRoles() {
var roles = this.props.cluster.get('roles');
this.props.nodes.each((node) => {
if (this.props.selectedNodeIds[node.id]) roles.each((role) => {
var roleName = role.get('name');
if (!node.hasRole(roleName, true)) {
var nodeRoles = node.get('pending_roles');
if (_.contains(this.props.selectedRoles, roleName)) {
nodeRoles = _.union(nodeRoles, [roleName]);
} else if (!_.contains(this.props.indeterminateRoles, roleName)) {
nodeRoles = _.without(nodeRoles, roleName);
if (this.props.selectedNodeIds[node.id]) {
roles.each((role) => {
var roleName = role.get('name');
if (!node.hasRole(roleName, true)) {
var nodeRoles = node.get('pending_roles');
if (_.contains(this.props.selectedRoles, roleName)) {
nodeRoles = _.union(nodeRoles, [roleName]);
} else if (!_.contains(this.props.indeterminateRoles, roleName)) {
nodeRoles = _.without(nodeRoles, roleName);
}
node.set({pending_roles: nodeRoles}, {assign: true});
}
node.set({pending_roles: nodeRoles}, {assign: true});
}
});
});
}
});
},
processRestrictions(role, models) {
@ -1909,10 +1911,13 @@ NodeList = React.createClass({
var roles1 = node1.sortedRoles(preferredRolesOrder);
var roles2 = node2.sortedRoles(preferredRolesOrder);
var order;
if (!roles1.length && !roles2.length) result = 0;
else if (!roles1.length) result = 1;
else if (!roles2.length) result = -1;
else {
if (!roles1.length && !roles2.length) {
result = 0;
} else if (!roles1.length) {
result = 1;
} else if (!roles2.length) {
result = -1;
} else {
while (!order && roles1.length && roles2.length) {
order = _.indexOf(preferredRolesOrder, roles1.shift()) -
_.indexOf(preferredRolesOrder, roles2.shift());

View File

@ -256,16 +256,18 @@ var SettingSection = React.createClass({
})
.compact()
.value();
if (setting.type === 'radio') return (
<RadioGroup {...this.props}
key={settingKey}
name={settingName}
label={setting.label}
values={values}
error={error}
tooltipText={showSettingWarning && settingWarning}
/>
);
if (setting.type === 'radio') {
return (
<RadioGroup {...this.props}
key={settingKey}
name={settingName}
label={setting.label}
values={values}
error={error}
tooltipText={showSettingWarning && settingWarning}
/>
);
}
},
renderInput(options) {
var {setting, settingKey, error, isSettingDisabled, showSettingWarning, settingWarning,

View File

@ -331,10 +331,12 @@ export var DiscardNodeChangesDialog = React.createClass({
discardNodeChanges() {
this.setState({actionInProgress: true});
var nodes = new models.Nodes(this.props.nodes.map((node) => {
if (node.get('pending_deletion')) return {
id: node.id,
pending_deletion: false
};
if (node.get('pending_deletion')) {
return {
id: node.id,
pending_deletion: false
};
}
return {
id: node.id,
cluster_id: null,
@ -756,8 +758,10 @@ export var ShowNodeInfoDialog = React.createClass({
summary = _.map(_.keys(sizes).sort(), (size) => sizes[size] + ' x ' + size).join(', ');
summary += ', ' + utils.showMemorySize(meta.memory.total) + ' ' +
i18n('dialog.show_node.total');
} else summary = utils.showMemorySize(meta.memory.total) + ' ' +
i18n('dialog.show_node.total');
} else {
summary = utils.showMemorySize(meta.memory.total) + ' ' +
i18n('dialog.show_node.total');
}
break;
case 'disks':
summary = meta.disks.length + ' ';
@ -1274,10 +1278,12 @@ export var DeleteNodesDialog = React.createClass({
this.setState({actionInProgress: true});
var nodes = new models.Nodes(this.props.nodes.map((node) => {
// mark deployed node as pending deletion
if (node.get('status') === 'ready') return {
id: node.id,
pending_deletion: true
};
if (node.get('status') === 'ready') {
return {
id: node.id,
pending_deletion: true
};
}
// remove not deployed node from cluster
return {
id: node.id,
@ -1583,16 +1589,18 @@ export var RegistrationDialog = React.createClass({
{i18n('common.cancel_button')}
</button>
];
if (!this.state.loading) buttons.push(
<button
key='apply'
className='btn btn-success'
disabled={this.state.actionInProgress || this.state.connectionError}
onClick={this.validateRegistrationForm}
>
{i18n('welcome_page.register.create_account')}
</button>
);
if (!this.state.loading) {
buttons.push(
<button
key='apply'
className='btn btn-success'
disabled={this.state.actionInProgress || this.state.connectionError}
onClick={this.validateRegistrationForm}
>
{i18n('welcome_page.register.create_account')}
</button>
);
}
return buttons;
}
});
@ -1692,26 +1700,30 @@ export var RetrievePasswordDialog = React.createClass({
);
},
renderFooter() {
if (this.state.passwordSent) return [
<button key='close' className='btn btn-default' onClick={this.close}>
{i18n('common.close_button')}
</button>
];
if (this.state.passwordSent) {
return [
<button key='close' className='btn btn-default' onClick={this.close}>
{i18n('common.close_button')}
</button>
];
}
var buttons = [
<button key='cancel' className='btn btn-default' onClick={this.close}>
{i18n('common.cancel_button')}
</button>
];
if (!this.state.loading) buttons.push(
<button
key='apply'
className='btn btn-success'
disabled={this.state.actionInProgress || this.state.connectionError}
onClick={this.retrievePassword}
>
{i18n('dialog.retrieve_password.send_new_password')}
</button>
);
if (!this.state.loading) {
buttons.push(
<button
key='apply'
className='btn btn-success'
disabled={this.state.actionInProgress || this.state.connectionError}
onClick={this.retrievePassword}
>
{i18n('dialog.retrieve_password.send_new_password')}
</button>
);
}
return buttons;
}
});

View File

@ -88,15 +88,17 @@ var PluginsPage = React.createClass({
</div>
{_.map(this.props.details, (attribute) => {
var data = this.processPluginData(plugin, attribute);
if (data.length) return (
<div className='row' key={attribute}>
<div className='col-xs-2 detail-title text-right'>
{i18n('plugins_page.' + attribute)}:
if (data.length) {
return (
<div className='row' key={attribute}>
<div className='col-xs-2 detail-title text-right'>
{i18n('plugins_page.' + attribute)}:
</div>
<div className='col-xs-10'>{data}</div>
</div>
<div className='col-xs-10'>{data}</div>
</div>
);
}, this)}
);
}
})}
</div>
);
},

View File

@ -136,7 +136,7 @@ var RegistrationInfo = React.createClass({
backboneMixin('tracking', 'change invalid')
],
render() {
if (this.state.isConnected)
if (this.state.isConnected) {
return (
<SupportPageElement
className='img-register-fuel'
@ -170,6 +170,7 @@ var RegistrationInfo = React.createClass({
</p>
</SupportPageElement>
);
}
return (
<SupportPageElement
className='img-register-fuel'