Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Manual lint fixes #294

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
plugins: ['react', 'prettier'],
rules: {
'react/prop-types': 'off', // Disable prop-types rule as this is used selectively in this repo
'no-console': 'warn', // Warn on console statements
'no-console': 'off', // Do not warn on console statements: they are expected on this application
'react/react-in-jsx-scope': 'off', // React 17 specific jsx-runtime enabled, so React import is not required
'prettier/prettier': 'error', // Add Prettier errors as ESLint errors
'arrow-parens': ['error', 'as-needed'],
Expand Down Expand Up @@ -50,6 +50,7 @@ module.exports = {
vars: 'all',
args: 'after-used',
varsIgnorePattern: '^_', // Allow variables starting with _ to be unused
argsIgnorePattern: '^_', // Allow parameters starting with _ to be unused
},
],
'no-underscore-dangle': 0,
Expand All @@ -68,6 +69,9 @@ module.exports = {
'jest/no-disabled-tests': 'off', // It's useful to have skipped tests on our suites

camelcase: 'off', // Conflicts with variables obtained directly from the fullnode endpoints
'import/no-named-as-default-member': 'off', // This will require a more complex refactor to fix
'react/no-string-refs': 'off', // This rule will be enforced only when the screens are refactored as functional components
'class-methods-use-this': 'off', // This rule will be enforced only when the screens are refactored as functional components
},
settings: {
react: {
Expand Down
3 changes: 3 additions & 0 deletions src/api/addressApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const addressApi = {
if (res && res.data) {
return res.data;
}
return undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return undefined;
return;

Would this also work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't: removing the explicit undefined raises an error about an unnecessary return on the last line of the function, and removing the return breaks the consistent-return lint rule that I intended to fix in the first time.

Maybe we can find a better solution at another time, but for now I'd rather not play with code logic.

});
},

Expand All @@ -37,6 +38,7 @@ const addressApi = {
if (res && res.data) {
return res.data;
}
return undefined;
});
},

Expand Down Expand Up @@ -66,6 +68,7 @@ const addressApi = {
if (res && res.data) {
return res.data;
}
return undefined;
});
},
};
Expand Down
6 changes: 4 additions & 2 deletions src/api/addressApiLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const addressApi = {
if (res && res.data) {
return res.data;
}
return undefined;
})
.catch(error => {
.catch(_error => {
// something wrong with request
});
},
Expand Down Expand Up @@ -46,8 +47,9 @@ const addressApi = {
if (res && res.data) {
return res.data;
}
return undefined;
})
.catch(error => {
.catch(_error => {
// something wrong with request
});
},
Expand Down
2 changes: 1 addition & 1 deletion src/api/axiosInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import axios from 'axios';
import { EXPLORER_SERVICE_BASE_URL } from '../constants.js';
import { EXPLORER_SERVICE_BASE_URL } from '../constants';

const errorHandler = error => {
console.log('ERROR RESPONSE', error);
Expand Down
3 changes: 1 addition & 2 deletions src/api/customAxiosInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import hathorLib from '@hathor/wallet-lib';
* Create an axios instance to be used when sending requests
*
* @param {callback} resolve Callback to be stored and used in case of a retry after a fail
* @param {number} timeout Timeout in milliseconds for the request
*/
const createRequestInstance = (resolve, timeout) => {
const createRequestInstance = resolve => {
// Will override lib axios instance increasing the default request timeout
const instance = hathorLib.axios.defaultCreateRequestInstance(resolve, 30000);
return instance;
Expand Down
3 changes: 2 additions & 1 deletion src/api/metadataApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const metadataApi = {
if (res && id in res.data) {
return res.data[id];
}
return undefined;
})
.catch(error => {
.catch(_error => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you do:

Suggested change
.catch(_error => {
.catch(() => {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep the variable, so that we feel more inclined to properly handle these errors in the future

// something wrong with request
});
},
Expand Down
46 changes: 15 additions & 31 deletions src/components/DagComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DagComponent extends React.Component {
const newLinks = [];
for (const parent of parents) {
// Validate if parent is in the data, otherwise no need to add a link
if (this.graph.hasOwnProperty(parent)) {
if (this.graph[parent]) {
// Creating link for each parent
const linkData = {
source: {
Expand Down Expand Up @@ -161,7 +161,7 @@ class DagComponent extends React.Component {
const newLinks = [];
for (const parent of parents) {
// Validate if parent is in the data, otherwise no need to add a link
if (this.graph.hasOwnProperty(parent)) {
if (this.graph[parent]) {
// Creating link for each parent
const linkData = {
source: {
Expand Down Expand Up @@ -228,18 +228,10 @@ class DagComponent extends React.Component {
.append('g')
.attr('class', 'link')
.append('line')
.attr('x1', function(d) {
return d.source.x;
})
.attr('y1', function(d) {
return d.source.y;
})
.attr('x2', function(d) {
return d.target.x;
})
.attr('y2', function(d) {
return d.target.y;
});
.attr('x1', d => d.source.x)
.attr('y1', d => d.source.y)
.attr('x2', d => d.target.x)
.attr('y2', d => d.target.y);

this.link = this.gLinks.selectAll('line');
}
Expand All @@ -252,9 +244,7 @@ class DagComponent extends React.Component {
.selectAll()
.data(txs)
.enter()
.filter(function(d) {
return !d.isBlock;
})
.filter(d => !d.isBlock)
.append('g')
.attr('class', 'tx');

Expand Down Expand Up @@ -294,9 +284,7 @@ class DagComponent extends React.Component {
.attr('y', d => {
return d.y;
})
.text(function(d) {
return d.id.substring(0, 4);
});
.text(d => d.id.substring(0, 4));

this.tx = this.gTxs.selectAll('circle');
}
Expand All @@ -309,9 +297,7 @@ class DagComponent extends React.Component {
.selectAll()
.data(blocks)
.enter()
.filter(function(d) {
return d.isBlock;
})
.filter(d => d.isBlock)
.append('g')
.attr('class', 'block');

Expand Down Expand Up @@ -344,9 +330,7 @@ class DagComponent extends React.Component {

// Add text to show block info
block
.filter(function(d) {
return d.isBlock;
})
.filter(d => d.isBlock)
.append('text')
.append('tspan')
.attr('class', 'block-text')
Expand All @@ -358,9 +342,7 @@ class DagComponent extends React.Component {
.attr('y', d => {
return d.y + this.blockHeight / 2;
})
.text(function(d) {
return d.id.substring(0, 4);
});
.text(d => d.id.substring(0, 4));

this.block = this.gBlocks.selectAll('rect');
}
Expand Down Expand Up @@ -435,15 +417,15 @@ class DagComponent extends React.Component {
/** Data from the tx being hovered */
const d = mouseEvent.currentTarget.__data__;
if (this.tx) {
this.tx.style('stroke-opacity', function(o) {
this.tx.style('stroke-opacity', function changeStrokeOpacity(o) {
const thisOpacity = d.links.indexOf(o.id) > -1 || d.id === o.id ? 1 : opacity;
this.setAttribute('fill-opacity', thisOpacity);
return thisOpacity;
});
}

if (this.block) {
this.block.style('stroke-opacity', function(o) {
this.block.style('stroke-opacity', function changeStrokeOpacity(o) {
const thisOpacity = d.links.indexOf(o.id) > -1 || d.id === o.id ? 1 : opacity;
this.setAttribute('fill-opacity', thisOpacity);
return thisOpacity;
Expand All @@ -463,9 +445,11 @@ class DagComponent extends React.Component {
// TODO
// I am blocking zoom in right now because I was having a bug to auto translate when zoomed in
if (event.transform.k > 1) {
/* eslint-disable no-param-reassign */
event.transform.x = this.lastZoomX;
event.transform.y = this.lastZoomY;
event.transform.k = this.lastZoomScale;
/* eslint-enable no-param-reassign */
return;
}
this.gDraw.attr('transform', event.transform);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Network extends React.Component {
this.setState({ peers }, () => {
let peerId = peers.find(target => target === params.peerId);
if (!peerId) {
peerId = peers[0];
[peerId] = peers;
}
this.onPeerChange(peerId);
});
Expand Down Expand Up @@ -289,7 +289,7 @@ class Network extends React.Component {
};

const loadTableBody = () => {
return this.state.known_peers.map((peer, idx) => {
return this.state.known_peers.map((peer, _idx) => {
const conn = this.getConnection(peer);
const isConnected = !!conn;
if (isConnected) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import React from 'react';
import { VERSION } from '../constants';

const Version = props => {
function Version() {
return (
<div className="d-flex flex-column version-wrapper align-items-center">
<span>Version</span>
<span>{VERSION}</span>
</div>
);
};
}

export default Version;
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import FlagProvider from '@unleash/proxy-client-react';
import { Provider } from 'react-redux';
import App from './App';

import 'bootstrap';
Expand All @@ -17,7 +18,6 @@ import 'highlight.js/styles/github.css';
import './index.css';

import store from './store/index';
import { Provider } from 'react-redux';
import { UNLEASH_CONFIG } from './constants';

const container = document.getElementById('root');
Expand Down
14 changes: 6 additions & 8 deletions src/screens/FeatureList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import React from 'react';
import Features from '../components/feature_activation/Features';

class FeatureList extends React.Component {
render() {
return (
<div className="content-wrapper">
<Features title={<h1>Feature Activation</h1>} />
</div>
);
}
function FeatureList() {
return (
<div className="content-wrapper">
<Features title={<h1>Feature Activation</h1>} />
</div>
);
}

export default FeatureList;
17 changes: 9 additions & 8 deletions src/utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ const dateFormatter = {
},

uptimeFormat(uptime) {
uptime = Math.floor(uptime);
const days = Math.floor(uptime / 3600 / 24);
uptime %= 3600 * 24;
const hours = Math.floor(uptime / 3600);
uptime %= 3600;
const minutes = Math.floor(uptime / 60);
uptime %= 60;
const seconds = uptime;
let tmpUptime = uptime;
tmpUptime = Math.floor(tmpUptime);
const days = Math.floor(tmpUptime / 3600 / 24);
tmpUptime %= 3600 * 24;
const hours = Math.floor(tmpUptime / 3600);
tmpUptime %= 3600;
const minutes = Math.floor(tmpUptime / 60);
tmpUptime %= 60;
const seconds = tmpUptime;
const pad = n => (Math.abs(n) >= 10 ? n : `0${n}`);
const uptime_str = `${days} days, ${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
return uptime_str;
Expand Down
7 changes: 4 additions & 3 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ const helpers = {
* @inner
*/
divideValueIntoPrefix(value) {
let tmpValue = value;
let divisions = 0;
while (value / 1000 > 1) {
value /= 1000;
while (tmpValue / 1000 > 1) {
tmpValue /= 1000;
divisions += 1;
}

return { value: value.toFixed(2), divisions };
return { value: tmpValue.toFixed(2), divisions };
},

/**
Expand Down