added eslint configuration files and scripts

This commit is contained in:
Akinwale Ariwodola 2018-01-19 12:20:07 +01:00
parent aac0ea9972
commit 7a5d25d3d9
9 changed files with 90 additions and 31 deletions

30
.eslintrc.json Normal file
View file

@ -0,0 +1,30 @@
{
"plugins": ["flowtype"],
"extends": [
"airbnb",
"plugin:import/electron",
"plugin:flowtype/recommended",
"plugin:prettier/recommended"
],
"settings": {
"import/resolver": {
"webpack": {
"config": "webpack.config.js"
}
}
},
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"globals": {
"__": true
},
"rules": {
"import/no-commonjs": "warn",
"import/no-amd": "warn",
"import/prefer-default-export": "ignore",
"func-names": ["warn", "as-needed"]
}
}

12
.lintstagedrc Normal file
View file

@ -0,0 +1,12 @@
{
"linters": {
"src/**/*.{js}": [
"prettier --write",
"git add"
],
"src/**/*.{js}": [
"eslint --fix",
"git add"
]
}
}

5
.prettierrc.json Normal file
View file

@ -0,0 +1,5 @@
{
"trailingComma": "es5",
"printWidth": 100,
"singleQuote": true
}

View file

@ -17,6 +17,7 @@
"main": "build/index.js",
"scripts": {
"build": "webpack",
"precommit": "lint-staged",
"lint": "eslint 'src/**/*.{js,jsx}' --fix",
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write"
},

View file

@ -1,20 +1,30 @@
// common
import Lbry from 'lbry';
import Lbryuri from 'lbryuri';
export { Lbry, Lbryuri };
// actions
export { doOpenModal, doCloseModal, doShowSnackBar } from 'redux/actions/app';
export { doFetchClaimListMine, doAbandonClaim, doResolveUris, doResolveUri } from 'redux/actions/claims';
export {
doFetchClaimListMine,
doAbandonClaim,
doResolveUris,
doResolveUri,
} from 'redux/actions/claims';
export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
export { doFetchFileInfo, doFileList, doFetchFileInfosAndPublishedClaims } from 'redux/actions/file_info';
export {
doFetchFileInfo,
doFileList,
doFetchFileInfosAndPublishedClaims,
} from 'redux/actions/file_info';
export {
doNavigate,
doAuthNavigate,
doHistoryTraverse,
doHistoryBack,
doHistoryForward,
doRecordScroll
doRecordScroll,
} from 'redux/actions/navigation';
export { doSearch } from 'redux/actions/search';
export {
@ -27,7 +37,7 @@ export {
doSendDraftTransaction,
doSetDraftTransactionAmount,
doSetDraftTransactionAddress,
doSendSupport
doSendSupport,
} from 'redux/actions/wallet';
// utils
@ -35,7 +45,7 @@ export { batchActions } from 'util/batchActions';
export { parseQueryParams, toQueryString } from 'util/query_params';
// reducers
export { claimsReducer } from 'redux/reducers/claims';
export { claimsReducer } from 'redux/reducers/claims';
export { costInfoReducer } from 'redux/reducers/cost_info';
export { fileInfoReducer } from 'redux/reducers/file_info';
export { searchReducer } from 'redux/reducers/search';
@ -66,15 +76,15 @@ export {
selectMyClaimsOutpoints,
selectFetchingMyChannels,
selectMyChannelClaims,
selectResolvingUris
selectResolvingUris,
} from 'redux/selectors/claims';
export {
makeSelectFetchingCostInfoForUri,
makeSelectCostInfoForUri,
selectAllCostInfoByUri,
selectCostForCurrentPageUri,
selectFetchingCostInfo
makeSelectFetchingCostInfoForUri,
makeSelectCostInfoForUri,
selectAllCostInfoByUri,
selectCostForCurrentPageUri,
selectFetchingCostInfo,
} from 'redux/selectors/cost_info';
export {
@ -88,7 +98,7 @@ export {
selectUrisLoading,
selectFileInfosDownloaded,
selectDownloadingFileInfos,
selectTotalDownloadProgress
selectTotalDownloadProgress,
} from 'redux/selectors/file_info';
export {
@ -104,7 +114,7 @@ export {
selectIsForwardDisabled,
selectHistoryIndex,
selectHistoryStack,
selectActiveHistoryEntry
selectActiveHistoryEntry,
} from 'redux/selectors/navigation';
export {
@ -113,7 +123,7 @@ export {
selectIsSearching,
selectSearchUrisByQuery,
selectWunderBarAddress,
selectWunderBarIcon
selectWunderBarIcon,
} from 'redux/selectors/search';
export {
@ -131,5 +141,5 @@ export {
selectDraftTransactionAmount,
selectDraftTransactionAddress,
selectDraftTransactionError,
selectBlocks
selectBlocks,
} from 'redux/selectors/wallet';

View file

@ -103,6 +103,7 @@ Lbry.connect = () => {
// Check every half second to see if the daemon is accepting connections
function checkDaemonStarted() {
tryNum += 1;
// eslint-disable-next-line no-use-before-define
lbryProxy
.status()
.then(resolve)
@ -146,6 +147,7 @@ Lbry.publishDeprecated = (params, fileListedCallback, publishedCallback, errorCa
{ once: true }
);
// eslint-disable-next-line no-use-before-define
lbryProxy.publish(params).then(
result => {
if (returnPendingTimeout) clearTimeout(returnPendingTimeout);

View file

@ -1,7 +1,6 @@
import Lbry from 'lbry';
import querystring from 'querystring';
const LbryApi = {
const Lbryapi = {
enabled: true,
exchangePromise: null,
exchangeLastFetched: null,
@ -13,27 +12,26 @@ const CONNECTION_STRING = process.env.LBRY_APP_API_URL
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
LbryApi.getExchangeRates = () => {
Lbryapi.getExchangeRates = () => {
if (
!LbryApi.exchangeLastFetched ||
Date.now() - LbryApi.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT
!Lbryapi.exchangeLastFetched ||
Date.now() - Lbryapi.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT
) {
LbryApi.exchangePromise = new Promise((resolve, reject) => {
LbryApi.call('lbc', 'exchange_rate', {}, 'get', true)
Lbryapi.exchangePromise = new Promise((resolve, reject) => {
Lbryapi.call('lbc', 'exchange_rate', {}, 'get', true)
.then(({ lbc_usd: LBC_USD, lbc_btc: LBC_BTC, btc_usd: BTC_USD }) => {
const rates = { LBC_USD, LBC_BTC, BTC_USD };
resolve(rates);
})
.catch(reject);
});
LbryApi.exchangeLastFetched = Date.now();
Lbryapi.exchangeLastFetched = Date.now();
}
return LbryApi.exchangePromise;
return Lbryapi.exchangePromise;
};
LbryApi.call = (resource, action, params = {}, method = 'get') => {
if (!LbryApi.enabled) {
console.log(__('Internal API disabled'));
Lbryapi.call = (resource, action, params = {}, method = 'get') => {
if (!Lbryapi.enabled) {
return Promise.reject(new Error(__('LBRY internal API is disabled')));
}
@ -83,4 +81,4 @@ LbryApi.call = (resource, action, params = {}, method = 'get') => {
return makeRequest(url, options).then(response => response.data);
};
export default LbryApi;
export default Lbryapi;

View file

@ -1,7 +1,9 @@
import * as ACTIONS from 'constants/action_types';
import * as MODALS from 'constants/modal_types';
import Lbry from 'lbry';
import Lbryuri from 'lbryuri';
import { selectResolvingUris } from 'redux/selectors/claims';
import { doOpenModal } from 'redux/actions/app';
import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims';
export function doResolveUris(uris) {
return (dispatch, getState) => {
@ -104,4 +106,4 @@ export function doAbandonClaim(txid, nout) {
nout,
}).then(successCallback, errorCallback);
};
}
}

View file

@ -179,4 +179,3 @@ export const makeSelectIsUriResolving = uri =>
selectResolvingUris,
resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1
);