Lint '/extras/*' #7252

Closed
infinite-persistence wants to merge 3 commits from x.lint.extras into master
3 changed files with 24 additions and 24 deletions
Showing only changes of commit 673e35a88d - Show all commits

View file

@ -1,8 +1,10 @@
{ {
"linters": { "linters": {
"ui/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"], "ui/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"],
"extras/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"],
"web/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"], "web/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"],
"ui/**/*.{js,jsx}": ["eslint", "flow focus-check --color always", "git add"], "ui/**/*.{js,jsx}": ["eslint", "flow focus-check --color always", "git add"],
"extras/**/*.{js,jsx}": ["eslint", "flow focus-check --color always", "git add"],
"web/**/*.{js,jsx}": ["eslint", "git add"] "web/**/*.{js,jsx}": ["eslint", "git add"]
}, },
"ignore": ["node_modules", "web/dist/**/*", "dist/**/*", "package-lock.json"] "ignore": ["node_modules", "web/dist/**/*", "dist/**/*", "package-lock.json"]

View file

@ -14,7 +14,7 @@ const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
const INTERNAL_APIS_DOWN = 'internal_apis_down'; const INTERNAL_APIS_DOWN = 'internal_apis_down';
// We can't use env's because they aren't passed into node_modules // We can't use env's because they aren't passed into node_modules
Lbryio.setLocalApi = endpoint => { Lbryio.setLocalApi = (endpoint) => {
Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end; Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
}; };
@ -36,8 +36,8 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
return Promise.reject(INTERNAL_APIS_DOWN); return Promise.reject(INTERNAL_APIS_DOWN);
} }
if (response) if (response) {
return response.json().then(json => { return response.json().then((json) => {
let error; let error;
if (json.error) { if (json.error) {
error = new Error(json.error); error = new Error(json.error);
@ -47,15 +47,16 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
error.response = response; // This is primarily a hack used in actions/user.js error.response = response; // This is primarily a hack used in actions/user.js
return Promise.reject(error); return Promise.reject(error);
}); });
}
} }
function makeRequest(url, options) { function makeRequest(url, options) {
return fetch(url, options).then(checkAndParse); return fetch(url, options).then(checkAndParse);
} }
return Lbryio.getAuthToken().then(token => { return Lbryio.getAuthToken().then((token) => {
const fullParams = { auth_token: token, ...params }; const fullParams = { auth_token: token, ...params };
Object.keys(fullParams).forEach(key => { Object.keys(fullParams).forEach((key) => {
const value = fullParams[key]; const value = fullParams[key];
if (typeof value === 'object') { if (typeof value === 'object') {
fullParams[key] = JSON.stringify(value); fullParams[key] = JSON.stringify(value);
@ -80,18 +81,18 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
url = `${Lbryio.CONNECTION_STRING}${resource}/${action}`; url = `${Lbryio.CONNECTION_STRING}${resource}/${action}`;
} }
return makeRequest(url, options).then(response => response.data); return makeRequest(url, options).then((response) => response.data);
}); });
}; };
Lbryio.authToken = null; Lbryio.authToken = null;
Lbryio.getAuthToken = () => Lbryio.getAuthToken = () =>
new Promise(resolve => { new Promise((resolve) => {
if (Lbryio.authToken) { if (Lbryio.authToken) {
resolve(Lbryio.authToken); resolve(Lbryio.authToken);
} else if (Lbryio.overrides.getAuthToken) { } else if (Lbryio.overrides.getAuthToken) {
Lbryio.overrides.getAuthToken().then(token => { Lbryio.overrides.getAuthToken().then((token) => {
resolve(token); resolve(token);
}); });
} else if (typeof window !== 'undefined') { } else if (typeof window !== 'undefined') {
@ -122,7 +123,7 @@ Lbryio.authenticate = (domain, language) => {
language: language || 'en', language: language || 'en',
}; };
return new Promise(resolve => { return new Promise((resolve) => {
resolve(params); resolve(params);
}); });
} }
@ -130,15 +131,15 @@ Lbryio.authenticate = (domain, language) => {
if (Lbryio.authenticationPromise === null) { if (Lbryio.authenticationPromise === null) {
Lbryio.authenticationPromise = new Promise((resolve, reject) => { Lbryio.authenticationPromise = new Promise((resolve, reject) => {
Lbryio.getAuthToken() Lbryio.getAuthToken()
.then(token => { .then((token) => {
if (!token || token.length > 60) { if (!token || token.length > 60) {
return false; return false;
} }
// check that token works // check that token works
return Lbryio.getCurrentUser() return Lbryio.getCurrentUser()
.then(user => user) .then((user) => user)
.catch(error => { .catch((error) => {
if (error === INTERNAL_APIS_DOWN) { if (error === INTERNAL_APIS_DOWN) {
throw new Error('Internal APIS down'); throw new Error('Internal APIS down');
} }
@ -146,14 +147,14 @@ Lbryio.authenticate = (domain, language) => {
return false; return false;
}); });
}) })
.then(user => { .then((user) => {
if (user) { if (user) {
return user; return user;
} }
return Lbry.status() return Lbry.status()
.then( .then(
status => (status) =>
new Promise((res, rej) => { new Promise((res, rej) => {
const appId = const appId =
domain && domain !== 'lbry.tv' domain && domain !== 'lbry.tv'
@ -169,7 +170,7 @@ Lbryio.authenticate = (domain, language) => {
}, },
'post' 'post'
) )
.then(response => { .then((response) => {
if (!response.auth_token) { if (!response.auth_token) {
throw new Error('auth_token was not set in the response'); throw new Error('auth_token was not set in the response');
} }
@ -188,10 +189,10 @@ Lbryio.authenticate = (domain, language) => {
Lbryio.authToken = response.auth_token; Lbryio.authToken = response.auth_token;
return res(response); return res(response);
}) })
.catch(error => rej(error)); .catch((error) => rej(error));
}) })
) )
.then(newUser => { .then((newUser) => {
if (!newUser) { if (!newUser) {
return Lbryio.getCurrentUser(); return Lbryio.getCurrentUser();
} }
@ -211,10 +212,7 @@ Lbryio.getStripeToken = () =>
: 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO'; : 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO';
Lbryio.getExchangeRates = () => { Lbryio.getExchangeRates = () => {
if ( if (!Lbryio.exchangeLastFetched || Date.now() - Lbryio.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT) {
!Lbryio.exchangeLastFetched ||
Date.now() - Lbryio.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT
) {
Lbryio.exchangePromise = new Promise((resolve, reject) => { Lbryio.exchangePromise = new Promise((resolve, reject) => {
Lbryio.call('lbc', 'exchange_rate', {}, 'get', true) Lbryio.call('lbc', 'exchange_rate', {}, 'get', true)
.then(({ lbc_usd: LBC_USD, lbc_btc: LBC_BTC, btc_usd: BTC_USD }) => { .then(({ lbc_usd: LBC_USD, lbc_btc: LBC_BTC, btc_usd: BTC_USD }) => {

View file

@ -38,12 +38,12 @@
"build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null", "build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null",
"crossenv": "./node_modules/cross-env/dist/bin/cross-env", "crossenv": "./node_modules/cross-env/dist/bin/cross-env",
"flow": "flow", "flow": "flow",
"lint": "eslint 'ui/**/*.{js,jsx}' && eslint 'web/**/*.{js,jsx}' && eslint 'electron/**/*.js' && flow", "lint": "eslint 'ui/**/*.{js,jsx}' && eslint 'extras/**/*.{js,jsx}' && eslint 'web/**/*.{js,jsx}' && eslint 'electron/**/*.js' && flow",
"lint-fix": "eslint --fix --quiet 'ui/**/*.{js,jsx}' && eslint --fix --quiet 'web/**/*.{js,jsx}' && eslint --fix --quiet 'electron/**/*.js'", "lint-fix": "eslint --fix --quiet 'ui/**/*.{js,jsx}' && eslint --fix --quiet 'extras/**/*.{js,jsx}' && eslint --fix --quiet 'web/**/*.{js,jsx}' && eslint --fix --quiet 'electron/**/*.js'",
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write", "format": "prettier 'src/**/*.{js,jsx,scss,json}' --write",
"flow-defs": "flow-typed install", "flow-defs": "flow-typed install",
"precommit": "lint-staged", "precommit": "lint-staged",
"preinstall": "yarn cache clean lbry-redux && yarn cache clean lbryinc", "preinstall": "",
"postinstall": "cd web && yarn && cd .. && if-env NODE_ENV=production && yarn postinstall:warning || if-env APP_ENV=web && echo 'Done installing deps' || yarn postinstall:electron", "postinstall": "cd web && yarn && cd .. && if-env NODE_ENV=production && yarn postinstall:warning || if-env APP_ENV=web && echo 'Done installing deps' || yarn postinstall:electron",
"postinstall:electron": "electron-builder install-app-deps && node ./build/downloadDaemon.js && node ./build/downloadLBRYFirst.js", "postinstall:electron": "electron-builder install-app-deps && node ./build/downloadDaemon.js && node ./build/downloadLBRYFirst.js",
"postinstall:warning": "echo '\n\nWARNING\n\nNot all node modules were installed because NODE_ENV is set to \"production\".\nThis should only be set after installing dependencies with \"yarn\". The app will not work.\n\n'" "postinstall:warning": "echo '\n\nWARNING\n\nNot all node modules were installed because NODE_ENV is set to \"production\".\nThis should only be set after installing dependencies with \"yarn\". The app will not work.\n\n'"