Skip to content

Commit

Permalink
feat: ✨ switch to eslint (#35)
Browse files Browse the repository at this point in the history
* feat: ✨ switch to eslint

* chore: 🔧 fix lint issues

* chore: 🔧 remove comments
  • Loading branch information
apotdevin authored May 6, 2020
1 parent f6bd54b commit 933ead8
Show file tree
Hide file tree
Showing 33 changed files with 634 additions and 375 deletions.
39 changes: 39 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": { "jsx": true }
},
"settings": {
"react": {
"createClass": "createReactClass",
"pragma": "React",
"version": "detect",
"flowVersion": "0.53"
},
"propWrapperFunctions": [
"forbidExtraProps",
{"property": "freeze", "object": "Object"},
{"property": "myFavoriteWrapper"}
],
"linkComponents": [
"Hyperlink",
{"name": "Link", "linkAttribute": "to"}
]
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:jsx-a11y/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"rules": {
"camelcase": "off",
"@typescript-eslint/camelcase": "off",
"prettier/prettier": ["error", {}, { "usePrettierrc": true }],
"react/prop-types": "off"
}
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"editor.formatOnSave": true
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "cross-env NODE_OPTIONS='--insecure-http-parser' next",
"build": "next build",
"start": "cross-env NODE_OPTIONS='--insecure-http-parser' next start",
"tslint": "tslint -p . -c tslint.json",
"lint": "eslint */**/*.{js,ts,tsx} --quiet --fix",
"prettier": "prettier --write **/*.{ts,tsx,js,css,html}",
"release": "standard-version",
"release:push": "standard-version && git push --follow-tags origin master",
Expand Down Expand Up @@ -86,21 +86,26 @@
"@testing-library/react": "^10.0.4",
"@types/node": "^13.13.4",
"@types/react": "^16.9.34",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"babel-jest": "^25.5.1",
"babel-loader": "^8.1.0",
"babel-plugin-inline-react-svg": "^1.1.1",
"babel-plugin-styled-components": "^1.10.7",
"babel-preset-react-app": "^9.1.2",
"cross-env": "^7.0.2",
"devmoji": "^2.1.9",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^4.0.0",
"husky": "^4.2.5",
"jest": "^25.5.4",
"lint-staged": "^10.2.2",
"prettier": "^2.0.5",
"standard-version": "^7.1.0",
"tslint": "^6.1.2",
"tslint-config-airbnb": "^5.11.2",
"tslint-react-hooks": "^2.2.2",
"typescript": "^3.8.3"
},
"husky": {
Expand All @@ -114,7 +119,7 @@
"*.+(ts|tsx)": [
"prettier --write",
"jest --bail --findRelatedTests",
"tslint"
"eslint --fix"
]
}
}
1 change: 1 addition & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import Document, {
DocumentContext,
Html,
Expand Down
54 changes: 27 additions & 27 deletions pages/balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,33 @@ const BalanceView = () => {
}
};

const renderChannels = (isOutgoing?: boolean) => {
const channels = sortBy(data.getChannels, [
(channel: any) =>
getPercent(channel.remote_balance, channel.local_balance),
]);

const finalChannels = isOutgoing ? channels : channels.reverse();

return finalChannels.map((channel: any, index: number) => {
if (!isOutgoing && outgoing && outgoing.id === channel.id) {
return null;
}

const callback = isOutgoing
? !outgoing && { callback: () => setOutgoing(channel) }
: outgoing && !incoming && { callback: () => setIncoming(channel) };

return (
<BalanceCard
key={`${index}-${channel.id}`}
{...{ index, channel, withArrow: true }}
{...callback}
/>
);
});
};

const renderIncoming = () => {
if (!outgoing) return null;

Expand Down Expand Up @@ -129,33 +156,6 @@ const BalanceView = () => {
);
};

const renderChannels = (isOutgoing?: boolean) => {
const channels = sortBy(data.getChannels, [
(channel: any) =>
getPercent(channel.remote_balance, channel.local_balance),
]);

const finalChannels = isOutgoing ? channels : channels.reverse();

return finalChannels.map((channel: any, index: number) => {
if (!isOutgoing && outgoing && outgoing.id === channel.id) {
return null;
}

const callback = isOutgoing
? !outgoing && { callback: () => setOutgoing(channel) }
: outgoing && !incoming && { callback: () => setIncoming(channel) };

return (
<BalanceCard
key={`${index}-${channel.id}`}
{...{ index, channel, withArrow: true }}
{...callback}
/>
);
});
};

return (
<CardWithTitle>
<SingleLine>
Expand Down
1 change: 0 additions & 1 deletion pages/trading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const TradingView = () => {

const { data, loading, fetchMore, error } = useGetOffersQuery({
variables: { filter: JSON.stringify(queryObject) },
onError: () => {},
});

if (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/helpers/hodlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export const getHodlParams = (params: any): string => {
let paramString = '?';

for (const key in params) {
if (params.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(params, key)) {
const element = params[key];

for (const subKey in element) {
if (element.hasOwnProperty(subKey)) {
if (Object.prototype.hasOwnProperty.call(element, subKey)) {
const subElement = element[subKey];
paramString = `${paramString}&${key}[${subKey}]=${subElement}`;
}
Expand Down
10 changes: 4 additions & 6 deletions src/api/schemas/query/channels/channelReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ export const getChannelReport = {
return;
}

const maxOutgoing = Math.max.apply(
Math,
channels.channels.map(o => {
const maxOutgoing = Math.max(
...channels.channels.map(o => {
return o.local_balance;
})
);

const maxIncoming = Math.max.apply(
Math,
channels.channels.map(o => {
const maxIncoming = Math.max(
...channels.channels.map(o => {
return o.remote_balance;
})
);
Expand Down
4 changes: 3 additions & 1 deletion src/api/schemas/query/hodlhodl/getOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const getOffers = {
if (params.filter) {
try {
queryParams = JSON.parse(params.filter);
} catch (error) {}
} catch (error) {
queryParams = defaultQuery;
}
}

try {
Expand Down
8 changes: 4 additions & 4 deletions src/api/schemas/query/report/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { InOutListProps, InOutProps } from '../flow/getInOut.interface';
export const reduceForwardArray = (list: ListProps) => {
const reducedOrder = [];
for (const key in list) {
if (list.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(list, key)) {
const element: ForwardProps[] = list[key];
const reducedArray: ReduceObjectProps = reduce(
element,
Expand All @@ -34,7 +34,7 @@ export const reduceForwardArray = (list: ListProps) => {
export const reduceInOutArray = (list: InOutListProps) => {
const reducedOrder = [];
for (const key in list) {
if (list.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(list, key)) {
const element: InOutProps[] = list[key];
const reducedArray: InOutProps = reduce(
element,
Expand All @@ -58,7 +58,7 @@ export const countArray = (list: ForwardProps[], type: boolean) => {

const channelInfo = [];
for (const key in grouped) {
if (grouped.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(grouped, key)) {
const element = grouped[key];

const fee = element
Expand Down Expand Up @@ -86,7 +86,7 @@ export const countRoutes = (list: ForwardProps[]) => {

const channelInfo = [];
for (const key in grouped) {
if (grouped.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(grouped, key)) {
const element = grouped[key];

const fee = element
Expand Down
16 changes: 8 additions & 8 deletions src/api/schemas/types/QueryType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,6 @@ export const GetResumeType = new GraphQLObjectType({
}),
});

export const GetMessagesType = new GraphQLObjectType({
name: 'getMessagesType',
fields: () => ({
token: { type: GraphQLString },
messages: { type: new GraphQLList(MessagesType) },
}),
});

export const MessagesType = new GraphQLObjectType({
name: 'messagesType',
fields: () => ({
Expand All @@ -328,3 +320,11 @@ export const MessagesType = new GraphQLObjectType({
tokens: { type: GraphQLInt },
}),
});

export const GetMessagesType = new GraphQLObjectType({
name: 'getMessagesType',
fields: () => ({
token: { type: GraphQLString },
messages: { type: new GraphQLList(MessagesType) },
}),
});
70 changes: 37 additions & 33 deletions src/components/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ import { useChatDispatch } from '../../context/ChatContext';

const PasswordInput = dynamic(() => import('./views/Password'), {
ssr: false,
loading: () => <LoadingCard noCard={true} />,
loading: function Loading() {
return <LoadingCard noCard={true} />;
},
});

const QRLogin = dynamic(() => import('./views/QRLogin'), {
ssr: false,
loading: () => <LoadingCard noCard={true} />,
loading: function Loading() {
return <LoadingCard noCard={true} />;
},
});

type AuthProps = {
Expand All @@ -47,6 +51,37 @@ export const Auth = ({ type, status, callback, setStatus }: AuthProps) => {

const [adminChecked, setAdminChecked] = useState(false);

const quickSave = ({
name = 'Unknown',
host,
admin,
viewOnly,
cert,
}: {
name?: string;
host?: string;
admin?: string;
viewOnly?: string;
cert?: string;
}) => {
saveUserAuth({
name,
host: host || '',
admin,
viewOnly,
cert,
accounts,
});

const id = getAccountId(host, viewOnly, admin, cert);

dispatch({ type: 'disconnected' });
dispatchChat({ type: 'disconnected' });
changeAccount(id);

push(appendBasePath('/'));
};

const handleSet = ({
host,
admin,
Expand Down Expand Up @@ -87,37 +122,6 @@ export const Auth = ({ type, status, callback, setStatus }: AuthProps) => {
}
};

const quickSave = ({
name = 'Unknown',
host,
admin,
viewOnly,
cert,
}: {
name?: string;
host?: string;
admin?: string;
viewOnly?: string;
cert?: string;
}) => {
saveUserAuth({
name,
host: host || '',
admin,
viewOnly,
cert,
accounts,
});

const id = getAccountId(host, viewOnly, admin, cert);

dispatch({ type: 'disconnected' });
dispatchChat({ type: 'disconnected' });
changeAccount(id);

push(appendBasePath('/'));
};

const handleSave = () => {
if (!host) {
toast.error('A host url is needed to connect.');
Expand Down
4 changes: 1 addition & 3 deletions src/components/auth/views/Checkboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export const RiskCheckboxAndConfirm = ({
<>
<Checkbox checked={checked} onChange={onChange}>
<CheckboxText>
I'm feeling reckless. Lightning, LND and ThunderHub are under constant
development and I understand that there is always a risk of losing
funds.
{`I'm feeling reckless. Lightning, LND and ThunderHub are under constant development and I understand that there is always a risk of losing funds.`}
</CheckboxText>
</Checkbox>
<ColorButton
Expand Down
Loading

0 comments on commit 933ead8

Please sign in to comment.