Skip to content

Commit

Permalink
fix lint (#1804)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip authored Feb 2, 2021
1 parent 8997b7f commit fbba865
Show file tree
Hide file tree
Showing 69 changed files with 561 additions and 172 deletions.
4 changes: 4 additions & 0 deletions packages/xarc-app-dev/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { eslintRcNodeTypeScript } = require("@xarc/module-dev");
module.exports = {
extends: eslintRcNodeTypeScript
};
1 change: 1 addition & 0 deletions packages/xarc-app-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": "xrun -s compile user/moveDist",
"test": "xrun xarc/test-only",
"coverage": "xrun xarc/test-cov",
"check": "xrun xarc/check",
"format": "prettier --write --print-width 100 *.{js,jsx} `find . -type d -d 1 -exec echo '{}/**/*.{js,jsx}' \\; | egrep -v '(/node_modules/|/dist/|/coverage/)'`",
"prepublishOnly": "xrun [[build, docs], xarc/check]",
"docs": "xrun xarc/docs",
Expand Down
1 change: 1 addition & 0 deletions packages/xarc-app-dev/scripts/l10n/flatten-messages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";

/* eslint-disable no-process-exit, no-console */
Expand Down
1 change: 1 addition & 0 deletions packages/xarc-app-dev/scripts/map-isomorphic-cdn.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";

/* eslint-disable max-statements, no-process-exit */
Expand Down
3 changes: 1 addition & 2 deletions packages/xarc-app-dev/scripts/merge-isomorphic-assets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable */
"use strict";

/* eslint-disable no-process-exit */

const Fs = require("fs");
const filterScanDir = require("filter-scan-dir");
const Path = require("path");
Expand Down
20 changes: 10 additions & 10 deletions packages/xarc-app-dev/src/config/archetype.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires, max-statements, no-console */

import { XarcOptions } from "./opt2/xarc-options";
import { XarcInternalOptions, XarcOptions } from "./opt2/xarc-options";
import { getDevArchetypeLegacy } from "./options";
import _ from "lodash";
import { getEnvProxy } from "./env-proxy";
Expand All @@ -11,10 +11,10 @@ let cachedArchetype = null;
/**
* Get development options
*
* @param user - user options
* @param userOptions - user options
* @returns options - final options with defaults and env applied
*/
export function getDevOptions(userOptions: XarcOptions = null) {
export function getDevOptions(userOptions: XarcOptions = null): XarcInternalOptions {
if (!userOptions && cachedArchetype) {
// if cached is already running
cachedArchetype._fromCache = true;
Expand All @@ -39,10 +39,10 @@ export function getDevOptions(userOptions: XarcOptions = null) {
cwd: undefined // we know what this is already
};

userOptions = _.merge({}, xarcOptions, userOptions);
const finalOptions = _.merge({}, xarcOptions, userOptions);

// checking for cwd from options or from env
const cwd = userOptions.cwd || process.env.XARC_CWD || process.cwd();
const cwd = finalOptions.cwd || process.env.XARC_CWD || process.cwd();
process.env.XARC_CWD = cwd;

const proxy = getEnvProxy();
Expand All @@ -51,14 +51,14 @@ export function getDevOptions(userOptions: XarcOptions = null) {
_.merge(legacy, proxy);

// merge user.webpackOptions into legacy.webpack
_.merge(legacy.webpack, userOptions.webpackOptions);
_.merge(legacy.webpack, finalOptions.webpackOptions);
// merge user.babelOptions into legacy.babel
_.merge(legacy.babel, userOptions.babelOptions);
_.merge(legacy.babel, finalOptions.babelOptions);
// merge user.addOnFeatures into legacy.options
_.merge(legacy.options, userOptions.addOnFeatures);
_.merge(legacy.options, finalOptions.addOnFeatures);
// merge the rest into top level
_.merge(legacy, {
...userOptions,
...finalOptions,
cwd,
webpackOptions: undefined,
babelOptions: undefined,
Expand All @@ -67,7 +67,7 @@ export function getDevOptions(userOptions: XarcOptions = null) {

// if user's options exist, it means this is invoked by user passing in options
// the first time, so save it.
if (userOptions) {
if (finalOptions) {
saveXarcOptions(legacy);
}

Expand Down
12 changes: 7 additions & 5 deletions packages/xarc-app-dev/src/config/babel/babelrc-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable @typescript-eslint/no-var-requires, no-console, @typescript-eslint/ban-ts-ignore */
/* eslint-disable @typescript-eslint/no-var-requires, no-console, @typescript-eslint/ban-ts-comment */

const optionalRequire = require("optional-require")(require);
const optFlow = optionalRequire("electrode-archetype-opt-flow");
import makeOptionalRequire from "optional-require";
import { getPluginFrom, loadXarcOptions } from "./common";
import _ from "lodash";

const optionalRequire = makeOptionalRequire(require);
const optFlow = optionalRequire("electrode-archetype-opt-flow");
const xOptions = loadXarcOptions(process.env.XARC_CWD);
const _ = require("lodash");

const {
enableTypeScript,
Expand Down Expand Up @@ -80,7 +82,7 @@ const { BABEL_ENV, NODE_ENV, ENABLE_KARMA_COV } = process.env;
const enableCssModule = Boolean(_.get(xOptions, "webpack.cssModuleSupport"));
const enableKarmaCov = ENABLE_KARMA_COV === "true";
const isProduction = (BABEL_ENV || NODE_ENV) === "production";
const isTest = (BABEL_ENV || NODE_ENV) === "test";
// const isTest = (BABEL_ENV || NODE_ENV) === "test";

// @ts-ignore
const plugins = basePlugins.concat(
Expand Down
24 changes: 16 additions & 8 deletions packages/xarc-app-dev/src/config/babel/babelrc.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* eslint-disable @typescript-eslint/no-var-requires, no-console, @typescript-eslint/ban-ts-ignore */
/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */

/*
* A single babel RC for all transpiling, including client and server code.
* When transpiling for node.js, env XARC_BABEL_TARGET should be set to "node"
* and this file will set preset-env targets accordingly.
*/
const ck = require("chalker");
const optionalRequire = require("optional-require")(require);
const optFlow = optionalRequire("electrode-archetype-opt-flow");
import ck from "chalker";
import makeOptionalRequire from "optional-require";
import _ from "lodash";
import { getPluginFrom, loadXarcOptions, detectCSSModule } from "./common";
const _ = require("lodash");

const optionalRequire = makeOptionalRequire(require);

const optFlow = optionalRequire("electrode-archetype-opt-flow");

const xOptions = loadXarcOptions(process.env.XARC_CWD);

Expand All @@ -35,7 +38,7 @@ const { BABEL_ENV, NODE_ENV, XARC_BABEL_TARGET, ENABLE_KARMA_COV } = process.env
const enableCssModule = detectCSSModule(xOptions);
const enableKarmaCov = ENABLE_KARMA_COV === "true";
const isProduction = (BABEL_ENV || NODE_ENV) === "production";
const isTest = (BABEL_ENV || NODE_ENV) === "test";
// const isTest = (BABEL_ENV || NODE_ENV) === "test";
const isNodeTarget = XARC_BABEL_TARGET === "node";

/**
Expand All @@ -50,8 +53,10 @@ const isNodeTarget = XARC_BABEL_TARGET === "node";
* https://github.com/gajus/babel-plugin-react-css-modules/issues/291
*
* Resolution: TBD
*
* @returns null or settings for babel-plugin-react-css-modules
*/
const getReactCssModulePlugin = () => {
const getReactCssModulePlugin = (): any => {
if (!enableCssModule) {
return null;
}
Expand Down Expand Up @@ -170,7 +175,10 @@ if (!isJest) {

const useBuiltIns =
!isNodeTarget && hasMultiTargets
? { useBuiltIns: "entry", corejs: require("core-js/package.json").version.split(".")[0] }
? {
useBuiltIns: "entry",
corejs: require("core-js/package.json").version.split(".")[0] // eslint-disable-line
}
: {};

const presets = [
Expand Down
16 changes: 10 additions & 6 deletions packages/xarc-app-dev/src/config/babel/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import requireAt from "require-at";

//
// Resolve full path of a plugin that's the dependency of host npm package
//
export function getPluginFrom(host, pluginName) {
let err;
for (const pkg of [].concat(host)) {
/**
* Resolve full path of a plugin that's the dependency of another npm package
*
* @param depPkg - pkg that depends on the plugin
* @param pluginName - name of plugin to look for
* @returns full path to a plugin as dep of another package
*/
export function getPluginFrom(depPkg: string | string[], pluginName: string): string {
let err: Error;
for (const pkg of [].concat(depPkg)) {
try {
return requireAt(require.resolve(`${pkg}/package.json`)).resolve(pluginName);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/xarc-app-dev/src/config/babel/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*
* @returns electrode's babel config
*/
export = function electrodeBabelRcAsPreset() {
export = function electrodeBabelRcAsPreset(): any {
return require("./babelrc"); // eslint-disable-line
};
27 changes: 21 additions & 6 deletions packages/xarc-app-dev/src/config/dev-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires, max-statements, no-console, prefer-const */
/* eslint-disable max-statements, no-console, prefer-const, no-magic-numbers */

import { getDevAdminPortFromEnv, isValidPort } from "../lib/utils";

Expand All @@ -10,21 +10,28 @@ import Fs from "fs";

// note: used by subapp-server/lib/util

export function getDevProxy() {
/**
* Get information to run the dev proxy
*
* @returns info for dev proxy
*/
export function getDevProxy(): any {
const xarcCwd = process.env.XARC_CWD || process.cwd();

const envWebpack = getEnvWebpack();
const envApp = getEnvApp();
const envProxy = getEnvProxy();

/*
/**
* Look in app's dependencies and devDependencies for a module with a name that starts with ssl-certs,
* load it, and try to get dev SSL key/cert file from the functions devKeyFile and devCertFile.
*
* If they exist and return strings, then use them as the path to the SSL key/cert file
* for the dev proxy.
*
* @returns `undefined` or `{key, cert }`
*/
function searchSSLCertsModule() {
function searchSSLCertsModule(): any {
let sslCertsMod;

try {
Expand All @@ -35,7 +42,7 @@ export function getDevProxy() {
Object.keys(appPkg.devDependencies || {}).find(matchModName);

if (sslCertsMod) {
const sslCerts = require(sslCertsMod);
const sslCerts = require(sslCertsMod); // eslint-disable-line
const key = sslCerts.devKeyFile();
const cert = sslCerts.devCertFile();
Fs.accessSync(key);
Expand All @@ -58,7 +65,12 @@ export function getDevProxy() {
return undefined;
}

function searchSSLCerts() {
/**
* search for dev SSL certs under app's directory
*
* @returns SSL cert file paths
*/
function searchSSLCerts(): any {
const fromModule = searchSSLCertsModule();

if (fromModule) {
Expand Down Expand Up @@ -156,4 +168,7 @@ export function getDevProxy() {
};
}

/**
* Default information for dev proxy
*/
export const devProxy = getDevProxy();
11 changes: 8 additions & 3 deletions packages/xarc-app-dev/src/config/env-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export function getEnvApp() {
const xenvConfig = require("xenv-config");
const { merge } = require("lodash");
import xenvConfig from "xenv-config";
import { merge } from "lodash";

/**
* Get app settings from env
*
* @returns app settings
*/
export function getEnvApp(): any {
const appConfigSpec = {
host: { env: ["HOST"], default: "localhost" },
port: { env: ["PORT"], default: 3000 },
Expand Down
7 changes: 6 additions & 1 deletion packages/xarc-app-dev/src/config/env-babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { merge } from "lodash";

import { getUserConfig } from "./user-config";

export function getEnvBabel() {
/**
* Get babel settings from env (deprecated)
*
* @returns babel settings
*/
export function getEnvBabel(): any {
const userConfig = getUserConfig();
const { options } = userConfig;

Expand Down
15 changes: 10 additions & 5 deletions packages/xarc-app-dev/src/config/env-karma.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
export function getEnvKarma() {
const xenvConfig = require("xenv-config");
const { merge } = require("lodash");
const userConfig = require("./user-config");
import xenvConfig from "xenv-config";
import { merge } from "lodash";
import { getUserConfig } from "./user-config";

/**
* Get karma settings from env (deprecated)
*
* @returns karma settings from env
*/
export function getEnvKarma(): any {
const karmaConfigSpec = {
browser: { env: "KARMA_BROWSER", default: "chrome" }
};
return xenvConfig(karmaConfigSpec, userConfig.karma, { merge });
return xenvConfig(karmaConfigSpec, getUserConfig().karma, { merge });
}
8 changes: 7 additions & 1 deletion packages/xarc-app-dev/src/config/env-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { isValidPort } from "../lib/utils";

import { merge } from "lodash";

export function getEnvProxy() {
/**
* Get proxy settings from env (deprecated)
*
* @returns proxy settings from env
*/
export function getEnvProxy(): any {
const proxyConfigSpec = {
httpsPort: {
env: [
Expand All @@ -24,5 +29,6 @@ export function getEnvProxy() {
},
elevated: { env: ["ELECTRODE_DEV_ELEVATED"], default: false }
};

return xenvConfig(proxyConfigSpec, {}, { merge });
}
7 changes: 6 additions & 1 deletion packages/xarc-app-dev/src/config/env-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import xenvConfig from "xenv-config";
import { merge } from "lodash";
import { getUserConfig } from "./user-config";

export function getEnvWebpack() {
/**
* Get webpack settings from env (deprecated)
*
* @returns webpack settings from env
*/
export function getEnvWebpack(): any {
const userConfig = getUserConfig();

const webpackConfigSpec = {
Expand Down
1 change: 1 addition & 0 deletions packages/xarc-app-dev/src/config/eslint/js/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";

const optEslintRequire = require("./opt-eslint-require");
Expand Down
1 change: 1 addition & 0 deletions packages/xarc-app-dev/src/config/eslint/js/es5-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";
const optEslintRequire = require("./opt-eslint-require");
module.exports = optEslintRequire("eslint-config-walmart/configurations/es5-node");
1 change: 1 addition & 0 deletions packages/xarc-app-dev/src/config/eslint/js/es6-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";
const optEslintRequire = require("./opt-eslint-require");
module.exports = optEslintRequire("eslint-config-walmart/configurations/es6-node");
1 change: 1 addition & 0 deletions packages/xarc-app-dev/src/config/eslint/js/es6-react.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";
const optEslintRequire = require("./opt-eslint-require");
module.exports = optEslintRequire("eslint-config-walmart/configurations/es6-react");
1 change: 1 addition & 0 deletions packages/xarc-app-dev/src/config/eslint/js/es6-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";
const optEslintRequire = require("./opt-eslint-require");
module.exports = optEslintRequire("eslint-config-walmart/configurations/es6-test");
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
"use strict";

try {
Expand Down
Loading

0 comments on commit fbba865

Please sign in to comment.