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

Update eslint-config-expensify #6174

Merged
merged 25 commits into from
Nov 8, 2021
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
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module.exports = {
extends: 'expensify',
parser: 'babel-eslint',
ignorePatterns: ['!.*', 'src/vendor', '.github/actions/**/index.js'],
rules: {
'react/jsx-filename-extension': [1, {extensions: ['.js']}],
'comma-dangle': ['error', 'always-multiline'],
},
plugins: ['detox'],
env: {
jest: true,
Expand Down
6 changes: 4 additions & 2 deletions .github/actions/bumpVersion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ exports.updateiOSVersion = function updateiOSVersion(version) {
/***/ }),

/***/ 7:
/***/ ((module) => {
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const _ = __nccwpck_require__(571);

const SEMANTIC_VERSION_LEVELS = {
MAJOR: 'MAJOR',
Expand All @@ -199,7 +201,7 @@ const MAX_INCREMENTS = 99;
*/
const getVersionNumberFromString = (versionString) => {
const [version, build] = versionString.split('-');
const [major, minor, patch] = version.split('.').map(n => Number(n));
const [major, minor, patch] = _.map(version.split('.'), n => Number(n));

return [major, minor, patch, Number.isInteger(Number(build)) ? Number(build) : 0];
};
Expand Down
12 changes: 7 additions & 5 deletions .github/actions/isPullRequestMergeable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ const run = function () {
pull_number: pullRequestNumber,
})
.then(({data}) => {
if (!_.isNull(data.mergeable)) {
console.log('Pull request mergeability is not yet resolved...');
retryCount++;
mergeabilityResolved = true;
isMergeable = data.mergeable;
if (_.isNull(data.mergeable)) {
return;
}

console.log('Pull request mergeability is not yet resolved...');
retryCount++;
mergeabilityResolved = true;
isMergeable = data.mergeable;
})
.catch((githubError) => {
mergeabilityResolved = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ const run = function () {
pull_number: pullRequestNumber,
})
.then(({data}) => {
if (!_.isNull(data.mergeable)) {
console.log('Pull request mergeability is not yet resolved...');
retryCount++;
mergeabilityResolved = true;
isMergeable = data.mergeable;
if (_.isNull(data.mergeable)) {
return;
}

console.log('Pull request mergeability is not yet resolved...');
retryCount++;
mergeabilityResolved = true;
isMergeable = data.mergeable;
})
.catch((githubError) => {
mergeabilityResolved = true;
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/markPullRequestsAsDeployed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const run = function () {
.then((actor) => {
// Create comment on each pull request (one after another to avoid throttling issues)
const deployMessage = getDeployMessage(actor, 'Deployed');
prList.reduce((promise, pr) => promise.then(() => commentPR(pr, deployMessage)), Promise.resolve());
_.reduce(prList, (promise, pr) => promise.then(() => commentPR(pr, deployMessage)), Promise.resolve());
});
}

Expand All @@ -117,7 +117,7 @@ const run = function () {
})
.then(({data}) => {
const isCP = /Merge pull request #\d+ from Expensify\/.*-?cherry-pick-staging-\d+/.test(data.message);
prList.reduce((promise, PR) => promise
_.reduce(prList, (promise, PR) => promise

// Then, for each PR, find out who merged it and determine the deployer
.then(() => GithubUtils.octokit.pulls.get({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const run = function () {
.then((actor) => {
// Create comment on each pull request (one after another to avoid throttling issues)
const deployMessage = getDeployMessage(actor, 'Deployed');
prList.reduce((promise, pr) => promise.then(() => commentPR(pr, deployMessage)), Promise.resolve());
_.reduce(prList, (promise, pr) => promise.then(() => commentPR(pr, deployMessage)), Promise.resolve());
});
}

Expand All @@ -107,7 +107,7 @@ const run = function () {
})
.then(({data}) => {
const isCP = /Merge pull request #\d+ from Expensify\/.*-?cherry-pick-staging-\d+/.test(data.message);
prList.reduce((promise, PR) => promise
_.reduce(prList, (promise, PR) => promise

// Then, for each PR, find out who merged it and determine the deployer
.then(() => GithubUtils.octokit.pulls.get({
Expand Down
4 changes: 3 additions & 1 deletion .github/libs/versionUpdater.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const _ = require('underscore');

const SEMANTIC_VERSION_LEVELS = {
MAJOR: 'MAJOR',
MINOR: 'MINOR',
Expand All @@ -14,7 +16,7 @@ const MAX_INCREMENTS = 99;
*/
const getVersionNumberFromString = (versionString) => {
const [version, build] = versionString.split('-');
const [major, minor, patch] = version.split('.').map(n => Number(n));
const [major, minor, patch] = _.map(version.split('.'), n => Number(n));

return [major, minor, patch, Number.isInteger(Number(build)) ? Number(build) : 0];
};
Expand Down
7 changes: 4 additions & 3 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable no-param-reassign */
const path = require('path');
const dotenv = require('dotenv');
const _ = require('underscore');
const custom = require('../config/webpack/webpack.common');

const env = dotenv.config({path: path.resolve(__dirname, '../.env.staging')}).parsed;
Expand All @@ -14,16 +15,16 @@ module.exports = ({config}) => {
};

// Necessary to overwrite the values in the existing DefinePlugin hardcoded to the Config staging values
const definePluginIndex = config.plugins.findIndex(plugin => plugin.constructor.name === 'DefinePlugin');
const definePluginIndex = _.findIndex(config.plugins, plugin => plugin.constructor.name === 'DefinePlugin');
config.plugins[definePluginIndex].definitions.__REACT_WEB_CONFIG__ = JSON.stringify(env);
config.resolve.extensions.push('.web.js', '.website.js');

const babelRulesIndex = custom.module.rules.findIndex(rule => rule.loader === 'babel-loader');
const babelRulesIndex = _.findIndex(custom.module.rules, rule => rule.loader === 'babel-loader');
const babelRule = custom.module.rules[babelRulesIndex];
config.module.rules.push(babelRule);

// Allows loading SVG - more context here https://github.com/storybookjs/storybook/issues/6188
const fileLoaderRule = config.module.rules.find(rule => rule.test && rule.test.test('.svg'));
const fileLoaderRule = _.find(config.module.rules, rule => rule.test && rule.test.test('.svg'));
fileLoaderRule.exclude = /\.svg$/;
config.module.rules.push({
test: /\.svg$/,
Expand Down
14 changes: 8 additions & 6 deletions config/checkMetroBundlerPort.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ const {isPackagerRunning} = require('@react-native-community/cli-tools');
* - `unrecognized`: one other process is running on the port we expect the packager to be running.
*/
isPackagerRunning().then((result) => {
if (result === 'unrecognized') {
console.error(
'The port 8081 is currently in use.',
'You can run `lsof -i :8081` to see which program is using it.\n',
);
process.exit(1);
if (result !== 'unrecognized') {
return;
}

console.error(
'The port 8081 is currently in use.',
'You can run `lsof -i :8081` to see which program is using it.\n',
);
process.exit(1);
});
3 changes: 2 additions & 1 deletion config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('underscore');
const path = require('path');
const {IgnorePlugin} = require('webpack');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
Expand All @@ -7,7 +8,7 @@ const CustomVersionFilePlugin = require('./CustomVersionFilePlugin');

// Check for a --platform command line argument (default to 'web')
// If it is 'web', we want to ignore .desktop.js files, and if it is 'desktop', we want to ignore .website.js files.
const platformIndex = process.argv.findIndex(arg => arg === '--platform');
const platformIndex = _.findIndex(process.argv, arg => arg === '--platform');
const platform = (platformIndex > 0) ? process.argv[platformIndex + 1] : 'web';
const platformExclude = platform === 'web' ? new RegExp(/\.desktop\.js$/) : new RegExp(/\.website\.js$/);

Expand Down
2 changes: 1 addition & 1 deletion config/webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const webpack = require('webpack');
const {merge} = require('webpack-merge');
const dotenv = require('dotenv');
const common = require('./webpack.common.js');
const common = require('./webpack.common');

const env = dotenv.config({path: path.resolve(__dirname, '../../.env')}).parsed;

Expand Down
2 changes: 1 addition & 1 deletion config/webpack/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const {merge} = require('webpack-merge');
const dotenv = require('dotenv');
const common = require('./webpack.common.js');
const common = require('./webpack.common');
const getProductionConfig = require('./productionConfig');

const env = dotenv.config({path: path.resolve(__dirname, '../../.env.production')}).parsed;
Expand Down
2 changes: 1 addition & 1 deletion config/webpack/webpack.staging.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const {merge} = require('webpack-merge');
const dotenv = require('dotenv');
const common = require('./webpack.common.js');
const common = require('./webpack.common');
const getProductionConfig = require('./productionConfig');

const env = dotenv.config({path: path.resolve(__dirname, '../../.env.staging')}).parsed;
Expand Down
29 changes: 18 additions & 11 deletions desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
shell,
ipcMain,
} = require('electron');
const _ = require('underscore');
const serve = require('electron-serve');
const contextMenu = require('electron-context-menu');
const {autoUpdater} = require('electron-updater');
Expand Down Expand Up @@ -41,7 +42,7 @@ autoUpdater.logger.transports.file.level = 'info';

// Send all Console logs to a log file: ~/Library/Logs/new.expensify/main.log
// See https://www.npmjs.com/package/electron-log
Object.assign(console, log.functions);
_.assign(console, log.functions);

// setup Hot reload
if (isDev) {
Expand Down Expand Up @@ -155,18 +156,18 @@ const mainWindow = (() => {
}],
}));

const appMenu = systemMenu.items.find(item => item.role === 'appmenu');
const appMenu = _.find(systemMenu.items, item => item.role === 'appmenu');
appMenu.submenu.insert(1, updateAppMenuItem);

// On mac, pressing cmd++ actually sends a cmd+=. cmd++ is generally the zoom in shortcut, but this is
// not properly listened for by electron. Adding in an invisible cmd+= listener fixes this.
const viewWindow = systemMenu.items.find(item => item.role === 'viewmenu');
const viewWindow = _.find(systemMenu.items, item => item.role === 'viewmenu');
viewWindow.submenu.append(new MenuItem({
role: 'zoomin',
accelerator: 'CommandOrControl+=',
visible: false,
}));
const windowMenu = systemMenu.items.find(item => item.role === 'windowmenu');
const windowMenu = _.find(systemMenu.items, item => item.role === 'windowmenu');
windowMenu.submenu.append(new MenuItem({type: 'separator'}));
windowMenu.submenu.append(new MenuItem({
label: 'New Expensify',
Expand All @@ -193,10 +194,12 @@ const mainWindow = (() => {

// Closing the chat window should just hide it (vs. fully quitting the application)
browserWindow.on('close', (evt) => {
if (!quitting && !hasUpdate) {
evt.preventDefault();
browserWindow.hide();
if (quitting || hasUpdate) {
return;
}

evt.preventDefault();
browserWindow.hide();
});

// Initiating a browser-back or browser-forward with mouse buttons should navigate history.
Expand All @@ -211,9 +214,11 @@ const mainWindow = (() => {

app.on('before-quit', () => quitting = true);
app.on('activate', () => {
if (!expectedUpdateVersion || app.getVersion() === expectedUpdateVersion) {
browserWindow.show();
if (expectedUpdateVersion && app.getVersion() !== expectedUpdateVersion) {
return;
}

browserWindow.show();
});

// Hide the app if we expected to upgrade to a new version but never did.
Expand Down Expand Up @@ -259,9 +264,11 @@ const mainWindow = (() => {

// Start checking for JS updates
.then((browserWindow) => {
if (!isDev) {
checkForUpdates(electronUpdater(browserWindow));
if (isDev) {
return;
}

checkForUpdates(electronUpdater(browserWindow));
});
});

Expand Down
3 changes: 2 additions & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*/

const {getDefaultConfig} = require('metro-config');
const _ = require('underscore');

/* eslint arrow-body-style: 0 */
module.exports = (() => {
return getDefaultConfig()
.then((config) => {
return {
resolver: {
assetExts: config.resolver.assetExts.filter(ext => ext !== 'svg'),
assetExts: _.filter(config.resolver.assetExts, ext => ext !== 'svg'),
sourceExts: ['jsx', 'js', 'ts', 'tsx', 'json', 'svg'],
},
transformer: {
Expand Down
Loading