Eslint rule for block curlies (#3955)

* Add curly rule

* Fix pre-existing issues with new rule
This commit is contained in:
Jaco Greeff 2016-12-23 16:43:13 +01:00 committed by Gav Wood
parent 466f84f485
commit 714298aa9a
20 changed files with 306 additions and 121 deletions

View File

@ -11,11 +11,12 @@
"FileReader": true
},
"rules": {
"object-curly-spacing": ["error", "always"],
"no-debugger": "error",
"no-alert": "error",
"curly": ["error", "all"],
"jsx-quotes": ["error", "prefer-single"],
"react/jsx-curly-spacing": ["error", "always"],
"object-property-newline": 0
"no-alert": "error",
"no-debugger": "error",
"object-curly-spacing": ["error", "always"],
"object-property-newline": 0,
"react/jsx-curly-spacing": ["error", "always"]
}
}

View File

@ -32,7 +32,8 @@ export default class BadgeReg {
}
certifierCount () {
return this._registry.getContract('badgereg')
return this._registry
.getContract('badgereg')
.then((badgeReg) => {
return badgeReg.instance.badgeCount.call({}, [])
.then((count) => count.valueOf());
@ -43,7 +44,9 @@ export default class BadgeReg {
if (this.certifiers[id]) {
return Promise.resolve(this.certifiers[id]);
}
return this._registry.getContract('badgereg')
return this._registry
.getContract('badgereg')
.then((badgeReg) => {
return badgeReg.instance.badge.call({}, [ id ]);
})
@ -56,6 +59,7 @@ export default class BadgeReg {
name = name === ZERO32
? null
: hex2Ascii(name);
return this.fetchMeta(id)
.then(({ title, icon }) => {
const data = { address, id, name, title, icon };
@ -66,7 +70,8 @@ export default class BadgeReg {
}
fetchMeta (id) {
return this._registry.getContract('badgereg')
return this._registry
.getContract('badgereg')
.then((badgeReg) => {
return Promise.all([
badgeReg.instance.meta.call({}, [id, 'TITLE']),
@ -76,7 +81,11 @@ export default class BadgeReg {
.then(([ title, icon ]) => {
title = bytesToHex(title);
title = title === ZERO32 ? null : hex2Ascii(title);
if (bytesToHex(icon) === ZERO32) icon = null;
if (bytesToHex(icon) === ZERO32) {
icon = null;
}
return { title, icon };
});
}
@ -85,6 +94,7 @@ export default class BadgeReg {
if (!this.contracts[certifier]) {
this.contracts[certifier] = this._api.newContract(ABI, certifier);
}
const contract = this.contracts[certifier];
return contract.instance.certified.call({}, [address]);

View File

@ -25,7 +25,11 @@ export const event = (name, event) => ({ type: 'events event', name, event });
export const subscribe = (name, from = 0, to = 'pending') =>
(dispatch, getState) => {
const { contract } = getState();
if (!contract) return;
if (!contract) {
return;
}
const opt = { fromBlock: from, toBlock: to, limit: 50 };
dispatch(start(name, from, to));
@ -70,9 +74,16 @@ export const subscribe = (name, from = 0, to = 'pending') =>
export const unsubscribe = (name) =>
(dispatch, getState) => {
const state = getState();
if (!state.contract) return;
if (!state.contract) {
return;
}
const subscriptions = state.events.subscriptions;
if (!(name in subscriptions) || subscriptions[name] === null) return;
if (!(name in subscriptions) || subscriptions[name] === null) {
return;
}
state.contract
.unsubscribe(subscriptions[name])

View File

@ -29,10 +29,18 @@ const initialState = {
};
const sortEvents = (a, b) => {
if (a.state === 'pending' && b.state !== 'pending') return -1;
if (a.state !== 'pending' && b.state === 'pending') return 1;
if (a.state === 'pending' && b.state !== 'pending') {
return -1;
} else if (a.state !== 'pending' && b.state === 'pending') {
return 1;
}
const d = b.block.minus(a.block).toFixed(0);
if (d === 0) return b.index.minus(a.index).toFixed(0);
if (d === 0) {
return b.index.minus(a.index).toFixed(0);
}
return d;
};

View File

@ -26,7 +26,11 @@ export const fail = () => ({ type: 'lookup error' });
export const lookup = (name, key) => (dispatch, getState) => {
const { contract } = getState();
if (!contract) return;
if (!contract) {
return;
}
const getAddress = contract.functions
.find((f) => f.name === 'getAddress');
@ -36,7 +40,11 @@ export const lookup = (name, key) => (dispatch, getState) => {
.then((address) => dispatch(success(address)))
.catch((err) => {
console.error(`could not lookup ${key} for ${name}`);
if (err) console.error(err.stack);
if (err) {
console.error(err.stack);
}
dispatch(fail());
});
};

View File

@ -31,8 +31,14 @@ export const reserve = (name) => (dispatch, getState) => {
const contract = state.contract;
const fee = state.fee;
if (!contract || !account) return;
if (alreadyQueued(state.names.queue, 'reserve', name)) return;
if (!contract || !account) {
return;
}
if (alreadyQueued(state.names.queue, 'reserve', name)) {
return;
}
const reserve = contract.functions.find((f) => f.name === 'reserve');
name = name.toLowerCase();
@ -61,7 +67,11 @@ export const reserve = (name) => (dispatch, getState) => {
}
console.error(`could not reserve ${name}`);
if (err) console.error(err.stack);
if (err) {
console.error(err.stack);
}
dispatch(reserveFail(name));
});
};
@ -76,8 +86,15 @@ export const drop = (name) => (dispatch, getState) => {
const state = getState();
const account = state.accounts.selected;
const contract = state.contract;
if (!contract || !account) return;
if (alreadyQueued(state.names.queue, 'drop', name)) return;
if (!contract || !account) {
return;
}
if (alreadyQueued(state.names.queue, 'drop', name)) {
return;
}
const drop = contract.functions.find((f) => f.name === 'drop');
name = name.toLowerCase();
@ -102,7 +119,11 @@ export const drop = (name) => (dispatch, getState) => {
}
console.error(`could not drop ${name}`);
if (err) console.error(err.stack);
if (err) {
console.error(err.stack);
}
dispatch(reserveFail(name));
});
};

View File

@ -32,7 +32,11 @@ export const update = (name, key, value) => (dispatch, getState) => {
dispatch(success());
}).catch((err) => {
console.error(`could not update ${key} record of ${name}`);
if (err) console.error(err.stack);
if (err) {
console.error(err.stack);
}
dispatch(fail());
});
};

View File

@ -38,19 +38,29 @@ export const fetchContract = () => (dispatch) =>
})
.catch((err) => {
console.error('could not fetch contract');
if (err) console.error(err.stack);
if (err) {
console.error(err.stack);
}
});
export const setFee = (fee) => ({ type: 'set fee', fee });
const fetchFee = () => (dispatch, getState) => {
const { contract } = getState();
if (!contract) return;
if (!contract) {
return;
}
contract.instance.fee.call()
.then((fee) => dispatch(setFee(fee)))
.catch((err) => {
console.error('could not fetch fee');
if (err) console.error(err.stack);
if (err) {
console.error(err.stack);
}
});
};
@ -58,11 +68,18 @@ export const setOwner = (owner) => ({ type: 'set owner', owner });
export const fetchOwner = () => (dispatch, getState) => {
const { contract } = getState();
if (!contract) return;
if (!contract) {
return;
}
contract.instance.owner.call()
.then((owner) => dispatch(setOwner(owner)))
.catch((err) => {
console.error('could not fetch owner');
if (err) console.error(err.stack);
if (err) {
console.error(err.stack);
}
});
};

View File

@ -173,20 +173,26 @@ export default class QueryAction extends Component {
onQueryKeyChange = (event, index, queryKey) => {
this.setState({
queryKey,
form: { valid: false, value: '' }
form: {
valid: false,
value: ''
}
});
}
onChange = (valid, value) => {
this.setState({
form: {
valid, value
valid,
value
}
});
}
onQuery = () => {
if (!this.state.form.valid) return;
if (!this.state.form.valid) {
return;
}
const { queryKey, form } = this.state;

View File

@ -128,8 +128,12 @@ export default class RegisterAction extends Component {
renderContent () {
const { error, complete } = this.props;
if (error) return this.renderError();
if (complete) return this.renderComplete();
if (error) {
return this.renderError();
} else if (complete) {
return this.renderComplete();
}
return this.renderForm();
}

View File

@ -57,7 +57,9 @@ export default class CustomChip extends Component {
}
renderIcon (isAddress, address) {
if (!isAddress) return;
if (!isAddress) {
return;
}
return (
<IdentityIcon

View File

@ -73,7 +73,9 @@ export default class InputText extends Component {
}
renderLoading () {
if (!this.state.loading) return;
if (!this.state.loading) {
return;
}
return (
<div className={ styles['input-loading'] }>
@ -83,7 +85,9 @@ export default class InputText extends Component {
}
renderIsValid () {
if (this.state.loading || !this.state.valid) return;
if (this.state.loading || !this.state.valid) {
return;
}
return (
<div className={ styles['input-icon'] }>
@ -120,8 +124,13 @@ export default class InputText extends Component {
}
onKeyDown = (event) => {
if (!this.props.onEnter) return;
if (event.keyCode !== 13) return;
if (!this.props.onEnter) {
return;
}
if (event.keyCode !== 13) {
return;
}
this.props.onEnter();
}

View File

@ -71,9 +71,14 @@ const validateAddress = (address) => {
const validateTokenAddress = (address, contract, simple) => {
const addressValidation = validateAddress(address);
if (!addressValidation.valid) return addressValidation;
if (simple) return addressValidation;
if (!addressValidation.valid) {
return addressValidation;
}
if (simple) {
return addressValidation;
}
return getTokenTotalSupply(address)
.then(balance => {
@ -96,7 +101,10 @@ const validateTokenAddress = (address, contract, simple) => {
});
})
.then((result) => {
if (result) return result;
if (result) {
return result;
}
return addressValidation;
});
};
@ -130,7 +138,10 @@ const validateTLA = (tla, contract, simple) => {
}
})
.then((result) => {
if (result) return result;
if (result) {
return result;
}
return {
value: fTLA,
error: null,
@ -215,16 +226,28 @@ const validateURL = (string) => {
};
export const validate = (value, type, contract) => {
if (type === ADDRESS_TYPE) return validateAddress(value);
if (type === TOKEN_ADDRESS_TYPE) return validateTokenAddress(value, contract);
if (type === SIMPLE_TOKEN_ADDRESS_TYPE) return validateTokenAddress(value, contract, true);
if (type === TLA_TYPE) return validateTLA(value, contract);
if (type === SIMPLE_TLA_TYPE) return validateTLA(value, contract, true);
if (type === UINT_TYPE) return validateUint(value);
if (type === DECIMAL_TYPE) return validateDecimal(value);
if (type === STRING_TYPE) return validateString(value);
if (type === HEX_TYPE) return validateHex(value);
if (type === URL_TYPE) return validateURL(value);
switch (type) {
case ADDRESS_TYPE:
return validateAddress(value);
case TOKEN_ADDRESS_TYPE:
return validateTokenAddress(value, contract);
case SIMPLE_TOKEN_ADDRESS_TYPE:
return validateTokenAddress(value, contract, true);
case TLA_TYPE:
return validateTLA(value, contract);
case SIMPLE_TLA_TYPE:
return validateTLA(value, contract, true);
case UINT_TYPE:
return validateUint(value);
case DECIMAL_TYPE:
return validateDecimal(value);
case STRING_TYPE:
return validateString(value);
case HEX_TYPE:
return validateHex(value);
case URL_TYPE:
return validateURL(value);
default:
return { valid: true, error: null };
}
};

View File

@ -119,7 +119,9 @@ export const subscribeEvents = () => (dispatch, getState) => {
return;
}
if (!logs || logs.length === 0) return;
if (!logs || logs.length === 0) {
return;
}
logs.forEach(log => {
const event = log.event;

View File

@ -46,7 +46,9 @@ export default class AddMeta extends Component {
state = initState;
render () {
if (!this.props.isTokenOwner) return null;
if (!this.props.isTokenOwner) {
return null;
}
return (<div className={ styles['add-meta'] }>
<RaisedButton
@ -98,7 +100,10 @@ export default class AddMeta extends Component {
renderContent () {
const { complete } = this.state;
if (complete) return this.renderComplete();
if (complete) {
return this.renderComplete();
}
return this.renderForm();
}

View File

@ -162,7 +162,10 @@ export default class Token extends Component {
}
renderBase (base) {
if (!base || base < 0) return null;
if (!base || base < 0) {
return null;
}
return (
<Chip
value={ Math.log10(base).toString() }
@ -171,7 +174,10 @@ export default class Token extends Component {
}
renderAddress (address) {
if (!address) return null;
if (!address) {
return null;
}
return (
<Chip
isAddress
@ -191,7 +197,9 @@ export default class Token extends Component {
}
renderOwner (owner) {
if (!owner) return null;
if (!owner) {
return null;
}
const ownerInfo = this.props.ownerAccountInfo;
@ -258,29 +266,36 @@ export default class Token extends Component {
}
if (isMetaLoading) {
return (<div>
return (
<div>
<Loading size={ 0.5 } />
</div>);
</div>
);
}
if (!meta) return;
if (!meta) {
return null;
}
const metaData = metaDataKeys.find(m => m.value === meta.query);
if (!meta.value) {
return (<div>
return (
<div>
<p className={ styles['meta-query'] }>
No <span className={ styles['meta-key'] }>
{ metaData.label.toLowerCase() }
</span> meta-data...
</p>
</div>);
</div>
);
}
if (meta.query === 'IMG') {
const imageHash = meta.value.replace(/^0x/, '');
return (<div>
return (
<div>
<p className={ styles['meta-query'] }>
<span className={ styles['meta-key'] }>
{ metaData.label }
@ -289,13 +304,15 @@ export default class Token extends Component {
<div className={ styles['meta-image'] }>
<img src={ `${parityNode}/api/content/${imageHash}/` } />
</div>
</div>);
</div>
);
}
if (meta.query === 'A') {
const address = meta.value.slice(0, 42);
return (<div>
return (
<div>
<p className={ styles['meta-query'] }>
<span className={ styles['meta-key'] }>
{ metaData.label }
@ -304,39 +321,52 @@ export default class Token extends Component {
<p className={ styles['meta-value'] }>
{ api.util.toChecksumAddress(address) }
</p>
</div>);
</div>
);
}
return (<div>
return (
<div>
<p className={ styles['meta-query'] }>
<span className={ styles['meta-key'] }>
{ metaData.label }
</span> meta-data:
</p>
<p className={ styles['meta-value'] }>{ meta.value }</p>
</div>);
</div>
);
}
renderMetaPending () {
const isMetaPending = this.props.metaPending;
if (!isMetaPending) return;
return (<div>
if (!isMetaPending) {
return null;
}
return (
<div>
<p className={ styles['meta-info'] }>
Meta-Data pending...
</p>
</div>);
</div>
);
}
renderMetaMined () {
const isMetaMined = this.props.metaMined;
if (!isMetaMined) return;
return (<div>
if (!isMetaMined) {
return null;
}
return (
<div>
<p className={ styles['meta-info'] }>
Meta-Data saved on the blockchain!
</p>
</div>);
</div>
);
}
onUnregister = () => {

View File

@ -113,7 +113,10 @@ export default class VerificationStore {
@action setCode = (code) => {
const { contract, account } = this;
if (!contract || !account || code.length === 0) return;
if (!contract || !account || code.length === 0) {
return;
}
const confirm = contract.functions.find((fn) => fn.name === 'confirm');
const options = { from: account };

View File

@ -94,8 +94,12 @@ export default class CertificationsMiddleware {
console.error('Failed to fetch new certifier events:', err);
});
}, 10 * 1000, true);
api.subscribe('eth_blockNumber', (err) => {
if (err) return;
if (err) {
return;
}
fetchChanges();
});

View File

@ -134,16 +134,24 @@ class List extends Component {
const balanceA = balances[accountA.address];
const balanceB = balances[accountB.address];
if (!balanceA && !balanceB) return 0;
if (balanceA && !balanceB) return -1;
if (!balanceA && balanceB) return 1;
if (!balanceA && !balanceB) {
return 0;
} else if (balanceA && !balanceB) {
return -1;
} else if (!balanceA && balanceB) {
return 1;
}
const ethA = balanceA.tokens.find(token => token.token.tag.toLowerCase() === 'eth');
const ethB = balanceB.tokens.find(token => token.token.tag.toLowerCase() === 'eth');
if (!ethA && !ethB) return 0;
if (ethA && !ethB) return -1;
if (!ethA && ethB) return 1;
if (!ethA && !ethB) {
return 0;
} else if (ethA && !ethB) {
return -1;
} else if (!ethA && ethB) {
return 1;
}
return -1 * ethA.value.comparedTo(ethB.value);
}
@ -159,9 +167,13 @@ class List extends Component {
.sort()
.join('');
if (!tagsA && !tagsB) return 0;
if (tagsA && !tagsB) return -1;
if (!tagsA && tagsB) return 1;
if (!tagsA && !tagsB) {
return 0;
} else if (tagsA && !tagsB) {
return -1;
} else if (!tagsA && tagsB) {
return 1;
}
return tagsA.localeCompare(tagsB);
}

View File

@ -95,7 +95,10 @@ export default class InputQuery extends Component {
return (<LinearProgress mode='indeterminate' />);
}
if (!results || results.length < 1) return null;
if (!results || results.length < 1) {
return null;
}
return outputs
.map((out, index) => ({
name: out.name,
@ -181,7 +184,9 @@ export default class InputQuery extends Component {
}
renderValue (value) {
if (!value) return 'no data';
if (!value) {
return 'no data';
}
const { api } = this.context;