Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
refactor(packages): manual lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PixnBits committed Sep 18, 2023
1 parent 8a76818 commit bfe8366
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 27 deletions.
1 change: 1 addition & 0 deletions lernaDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

const { exec } = require('child_process');
// This regex was obtained from https://semver.org/ test it out here https://regex101.com/r/vkijKf/1/
/* eslint-disable-next-line unicorn/no-unsafe-regex */
const regex = /^chore\(release\): (0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/gm;
const commitMessage = process.argv[2]; // This is the commit message
if (commitMessage != null && regex.test(commitMessage)) {
Expand Down
6 changes: 5 additions & 1 deletion packages/holocron-module-route/__tests__/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "amex/test"
"extends": "amex/test",
"rules": {
// a number of arguments are functions and need to be set up in the specifications
"unicorn/consistent-function-scoping": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import React from 'react';
import { loadModule } from 'holocron'; // eslint-disable-line import/no-unresolved,import/extensions
import ModuleRoute from '../src/ModuleRoute';
import {
addToRouteProps as addToRouteProperties,
passChildrenProps as passChildrenProperties,
addToRouteProperties,
passChildrenProperties,
getRouteIndex,
createModuleRoute,
createModuleRouteFromElement,
Expand Down
18 changes: 9 additions & 9 deletions packages/holocron-module-route/src/ModuleRouteUtils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ import { createRoutes } from '@americanexpress/one-app-router';
// holocron is a peer dependency
import { loadModule } from 'holocron'; // eslint-disable-line import/no-unresolved,import/extensions

export const addToRouteProps = (route, newProperties) => ({
export const addToRouteProperties = (route, newProperties) => ({
...route,
props: {
...route.props,
...newProperties,
},
});

export const passChildrenProps = (givenRoutes = [], newProperties) => {
export const passChildrenProperties = (givenRoutes = [], newProperties) => {
const routes = typeof givenRoutes === 'function' ? givenRoutes(newProperties.store) : givenRoutes;
return Array.isArray(routes) ? routes.map((route) => addToRouteProps(route, newProperties))
: [addToRouteProps(routes, newProperties)];
return Array.isArray(routes) ? routes.map((route) => addToRouteProperties(route, newProperties))
: [addToRouteProperties(routes, newProperties)];
};

export const getRouteIndex = (
routes, properties
) => routes && createRoutes(passChildrenProps(routes, properties))[0].indexRoute;
) => routes && createRoutes(passChildrenProperties(routes, properties))[0].indexRoute;

const capitalizePath = (path) => path[0].toUpperCase() + path.slice(1).toLowerCase();

export const createModuleRoute = (defaultProps, properties) => {
const { moduleName, store } = properties;

const capitalizePath = (path) => path[0].toUpperCase() + path.slice(1).toLowerCase();

let moduleRoute = {
...defaultProps,
...properties,
Expand All @@ -58,7 +58,7 @@ export const createModuleRoute = (defaultProps, properties) => {
getChildRoutes(location, callback) {
store.dispatch(loadModule(moduleName))
.then(
({ childRoutes }) => callback(null, passChildrenProps(childRoutes, { store }))
({ childRoutes }) => callback(null, passChildrenProperties(childRoutes, { store }))
)
.catch(callback);
},
Expand Down Expand Up @@ -100,7 +100,7 @@ export function createModuleRouteFromElement({ type, props }) {
const route = createModuleRoute(type.defaultProps, props);
if (route.children) {
const { store } = props;
const children = passChildrenProps(route.children, { store });
const children = passChildrenProperties(route.children, { store });
const childRoutes = createRoutesFromReactChildren(children, route);

if (childRoutes.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { match } from '@americanexpress/one-app-router';
import { composeModules } from 'holocron';

function matchPromisified(options) {
return new Promise((res, rej) => {
return new Promise((resolve, reject) => {
match(options, (error, redirectLocation, renderProperties) => {
if (error) {
return rej(error);
return reject(error);
}
return res({ renderProps: renderProperties, redirectLocation });
return resolve({ renderProps: renderProperties, redirectLocation });
});
});
}
Expand Down
6 changes: 5 additions & 1 deletion packages/holocron/__tests__/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "amex/test"
"extends": "amex/test",
"rules": {
// a number of arguments are functions and need to be set up in the specifications
"unicorn/consistent-function-scoping": 0
}
}
10 changes: 8 additions & 2 deletions packages/holocron/__tests__/holocronModule.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ describe('holocronModule', () => {
holocronModule({
name: 'mock-module',
load,
shouldModuleReload: (currentProperties, nextProperties) => currentProperties.someParam !== nextProperties.someParam,
shouldModuleReload: (
currentProperties,
nextProperties
) => currentProperties.someParam !== nextProperties.someParam,
})(() => <div>Mock Module</div>)
);
const mockStore = createStore(
Expand Down Expand Up @@ -326,7 +329,10 @@ describe('holocronModule', () => {
holocronModule({
name: 'mock-module',
load,
shouldModuleReload: (currentProperties, nextProperties) => currentProperties.someParam !== nextProperties.someParam,
shouldModuleReload: (
currentProperties,
nextProperties
) => currentProperties.someParam !== nextProperties.someParam,
})(() => <div>Mock Module</div>)
);
const mockStore = createStore(
Expand Down
4 changes: 2 additions & 2 deletions packages/holocron/__tests__/loadModule.web.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const createElementSpy = jest
.spyOn(document, 'createElement')
.mockImplementation(() => mockElement);
jest
.spyOn(document, 'getElementsByTagName')
.mockImplementation(() => [{ appendChild: () => null }]);
.spyOn(document, 'querySelectorAll')
.mockImplementation(() => [{ append: () => null }]);
// eslint-disable-next-line no-underscore-dangle
window.__holocron_module_bundle_type__ = 'browser';

Expand Down
2 changes: 1 addition & 1 deletion packages/holocron/__tests__/updateModuleRegistry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jest.mock('../src/loadModule.node', () => {
resolveWith,
time
) => new Promise(
(res) => setTimeout(() => res(resolveWith), time)
(resolve) => setTimeout(() => resolve(resolveWith), time)
);

const makeUpdatedModule = (moduleName, moduleVersion) => function UpdatedModule() {
Expand Down
6 changes: 5 additions & 1 deletion packages/holocron/src/holocronModule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ export default function holocronModule({
frozenProps: frozenProperties,
currentLoadCount,
componentName: getModuleName(WrappedComponent, name),
hocInstance: { mounted: isMounted.current, loadCount: loadCountReference.current, setStatus },
hocInstance: {
mounted: isMounted.current,
loadCount: loadCountReference.current,
setStatus,
},
});

if (
Expand Down
9 changes: 7 additions & 2 deletions packages/holocron/src/updateModuleRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export default async function updateModuleRegistry({
const modulesToUpdate = batchModulesToUpdate(
getModulesToUpdate(currentModuleMap.modules || {}, nextModuleMap.modules)
);
const flatModulesToUpdate = modulesToUpdate.reduce((accumulator, batch) => [...accumulator, ...batch], []);
const flatModulesToUpdate = modulesToUpdate.reduce(
(accumulator, batch) => [...accumulator, ...batch],
[]
);
const rejectedModules = {};
let successfullyLoadedModules = await modulesToUpdate.reduce(async (accumulator, moduleBatch) => {
const previouslyResolvedModules = await accumulator;
Expand Down Expand Up @@ -82,7 +85,9 @@ export default async function updateModuleRegistry({
return [...previouslyResolvedModules, ...fulfilledModules];
}, []);
const rejectedModuleNames = Object.keys(rejectedModules);
const updatedFlatMap = flatModulesToUpdate.filter((module_) => !rejectedModuleNames.includes(module_));
const updatedFlatMap = flatModulesToUpdate.filter(
(module_) => !rejectedModuleNames.includes(module_)
);
successfullyLoadedModules = successfullyLoadedModules.reduce(
(accumulator, module, i) => ({
...accumulator,
Expand Down
6 changes: 5 additions & 1 deletion packages/iguazu-holocron/__tests__/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "amex/test"
"extends": "amex/test",
"rules": {
// a number of arguments are functions and need to be set up in the specifications
"unicorn/consistent-function-scoping": 0
}
}
7 changes: 5 additions & 2 deletions scripts/check-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function parseVersion(raw) {
return raw;
}

const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/.exec(raw.trim());
const [versionCore, ...prereleaseParts] = raw.trim().split('-');
const prerelease = prereleaseParts.join('-') || undefined;

const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(versionCore);
if (!match) {
return null;
}
Expand All @@ -43,7 +46,7 @@ function parseVersion(raw) {
major: Number.parseInt(match[1], 10),
minor: Number.parseInt(match[2], 10),
patch: Number.parseInt(match[3], 10),
prerelease: match[4],
prerelease,
};
}

Expand Down

0 comments on commit bfe8366

Please sign in to comment.