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 "FileReader": true
}, },
"rules": { "rules": {
"object-curly-spacing": ["error", "always"], "curly": ["error", "all"],
"no-debugger": "error",
"no-alert": "error",
"jsx-quotes": ["error", "prefer-single"], "jsx-quotes": ["error", "prefer-single"],
"react/jsx-curly-spacing": ["error", "always"], "no-alert": "error",
"object-property-newline": 0 "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 () { certifierCount () {
return this._registry.getContract('badgereg') return this._registry
.getContract('badgereg')
.then((badgeReg) => { .then((badgeReg) => {
return badgeReg.instance.badgeCount.call({}, []) return badgeReg.instance.badgeCount.call({}, [])
.then((count) => count.valueOf()); .then((count) => count.valueOf());
@ -43,7 +44,9 @@ export default class BadgeReg {
if (this.certifiers[id]) { if (this.certifiers[id]) {
return Promise.resolve(this.certifiers[id]); return Promise.resolve(this.certifiers[id]);
} }
return this._registry.getContract('badgereg')
return this._registry
.getContract('badgereg')
.then((badgeReg) => { .then((badgeReg) => {
return badgeReg.instance.badge.call({}, [ id ]); return badgeReg.instance.badge.call({}, [ id ]);
}) })
@ -56,6 +59,7 @@ export default class BadgeReg {
name = name === ZERO32 name = name === ZERO32
? null ? null
: hex2Ascii(name); : hex2Ascii(name);
return this.fetchMeta(id) return this.fetchMeta(id)
.then(({ title, icon }) => { .then(({ title, icon }) => {
const data = { address, id, name, title, icon }; const data = { address, id, name, title, icon };
@ -66,7 +70,8 @@ export default class BadgeReg {
} }
fetchMeta (id) { fetchMeta (id) {
return this._registry.getContract('badgereg') return this._registry
.getContract('badgereg')
.then((badgeReg) => { .then((badgeReg) => {
return Promise.all([ return Promise.all([
badgeReg.instance.meta.call({}, [id, 'TITLE']), badgeReg.instance.meta.call({}, [id, 'TITLE']),
@ -76,7 +81,11 @@ export default class BadgeReg {
.then(([ title, icon ]) => { .then(([ title, icon ]) => {
title = bytesToHex(title); title = bytesToHex(title);
title = title === ZERO32 ? null : hex2Ascii(title); title = title === ZERO32 ? null : hex2Ascii(title);
if (bytesToHex(icon) === ZERO32) icon = null;
if (bytesToHex(icon) === ZERO32) {
icon = null;
}
return { title, icon }; return { title, icon };
}); });
} }
@ -85,6 +94,7 @@ export default class BadgeReg {
if (!this.contracts[certifier]) { if (!this.contracts[certifier]) {
this.contracts[certifier] = this._api.newContract(ABI, certifier); this.contracts[certifier] = this._api.newContract(ABI, certifier);
} }
const contract = this.contracts[certifier]; const contract = this.contracts[certifier];
return contract.instance.certified.call({}, [address]); 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') => export const subscribe = (name, from = 0, to = 'pending') =>
(dispatch, getState) => { (dispatch, getState) => {
const { contract } = getState(); const { contract } = getState();
if (!contract) return;
if (!contract) {
return;
}
const opt = { fromBlock: from, toBlock: to, limit: 50 }; const opt = { fromBlock: from, toBlock: to, limit: 50 };
dispatch(start(name, from, to)); dispatch(start(name, from, to));
@ -70,9 +74,16 @@ export const subscribe = (name, from = 0, to = 'pending') =>
export const unsubscribe = (name) => export const unsubscribe = (name) =>
(dispatch, getState) => { (dispatch, getState) => {
const state = getState(); const state = getState();
if (!state.contract) return;
if (!state.contract) {
return;
}
const subscriptions = state.events.subscriptions; const subscriptions = state.events.subscriptions;
if (!(name in subscriptions) || subscriptions[name] === null) return;
if (!(name in subscriptions) || subscriptions[name] === null) {
return;
}
state.contract state.contract
.unsubscribe(subscriptions[name]) .unsubscribe(subscriptions[name])

View File

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

View File

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

View File

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

View File

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

View File

@ -38,19 +38,29 @@ export const fetchContract = () => (dispatch) =>
}) })
.catch((err) => { .catch((err) => {
console.error('could not fetch contract'); 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 }); export const setFee = (fee) => ({ type: 'set fee', fee });
const fetchFee = () => (dispatch, getState) => { const fetchFee = () => (dispatch, getState) => {
const { contract } = getState(); const { contract } = getState();
if (!contract) return;
if (!contract) {
return;
}
contract.instance.fee.call() contract.instance.fee.call()
.then((fee) => dispatch(setFee(fee))) .then((fee) => dispatch(setFee(fee)))
.catch((err) => { .catch((err) => {
console.error('could not fetch fee'); 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) => { export const fetchOwner = () => (dispatch, getState) => {
const { contract } = getState(); const { contract } = getState();
if (!contract) return;
if (!contract) {
return;
}
contract.instance.owner.call() contract.instance.owner.call()
.then((owner) => dispatch(setOwner(owner))) .then((owner) => dispatch(setOwner(owner)))
.catch((err) => { .catch((err) => {
console.error('could not fetch owner'); 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) => { onQueryKeyChange = (event, index, queryKey) => {
this.setState({ this.setState({
queryKey, queryKey,
form: { valid: false, value: '' } form: {
valid: false,
value: ''
}
}); });
} }
onChange = (valid, value) => { onChange = (valid, value) => {
this.setState({ this.setState({
form: { form: {
valid, value valid,
value
} }
}); });
} }
onQuery = () => { onQuery = () => {
if (!this.state.form.valid) return; if (!this.state.form.valid) {
return;
}
const { queryKey, form } = this.state; const { queryKey, form } = this.state;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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