Skip to content

Commit

Permalink
Autofix subset of eslint errors (adobecom#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
hparra authored and narcis-radu committed Sep 6, 2023
1 parent b503287 commit 5e19b81
Show file tree
Hide file tree
Showing 58 changed files with 246 additions and 259 deletions.
8 changes: 6 additions & 2 deletions build/htm-preact-debug.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'preact/debug';
import { h, Component, createContext, createRef, render } from 'preact';
import { signal } from '@preact/signals';
import { useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId } from 'preact/hooks';
import {
useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId,
} from 'preact/hooks';
import htm from 'htm';

const html = htm.bind(h);

export { h, html, signal, render, Component, createContext, createRef, useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId };
export {
h, html, signal, render, Component, createContext, createRef, useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId,
};
8 changes: 6 additions & 2 deletions build/htm-preact.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import { h, Component, createContext, createRef, render } from 'preact';
import { signal } from '@preact/signals';
import { useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId } from 'preact/hooks';
import {
useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId,
} from 'preact/hooks';
import htm from 'htm';

const html = htm.bind(h);

export { h, html, signal, render, Component, createContext, createRef, useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId };
export {
h, html, signal, render, Component, createContext, createRef, useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue, useErrorBoundary, useId,
};
22 changes: 10 additions & 12 deletions libs/blocks/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function setSEO(questions) {
function toggleMedia(con, trig, status) {
if (status === 'open') {
trig.setAttribute('hidden', '');
trig.setAttribute('aria-expanded', 'false');
trig.setAttribute('aria-expanded', 'false');
con.setAttribute('hidden', '');
con.setAttribute('aria-expanded', 'false');
} else {
Expand Down Expand Up @@ -43,8 +43,8 @@ function displayMedia(displayArea, el, dd, i, expanded) {
if (expanded) {
toggleMedia(dd, el, 'open');
displayArea.childNodes[i - 1]?.classList.remove('expanded');
}
}
}
},
);
}

Expand Down Expand Up @@ -94,7 +94,7 @@ function createItem(accordion, id, heading, num, edit) {
if (edit) {
const ogMedia = mediaCollection[id][num - 1];
const mediaCopy = ogMedia.cloneNode(true);
dm.append(mediaCopy)
dm.append(mediaCopy);
dd.prepend(dm);
}

Expand All @@ -117,23 +117,21 @@ function populateMedia(accordion, id, num, collection) {
export default function init(el) {
const id = getUniqueId(el);
const accordion = createTag('dl', { class: 'accordion', id: `accordion-${id}`, role: 'presentation' });
const accordionMedia = createTag('div', { class: 'accordion-media', id: `accordion-media-${id}`});
const accordionMedia = createTag('div', { class: 'accordion-media', id: `accordion-media-${id}` });
const isSeo = el.classList.contains('seo');
const isEditorial = el.classList.contains('editorial');
decorateButtons(el);

if (isEditorial) {
const editorialMedia = el.querySelectorAll(':scope > div:nth-child(3n)');
[...editorialMedia].map(
(media, idx, collection) =>
populateMedia(accordionMedia, id, idx, collection)
(media, idx, collection) => populateMedia(accordionMedia, id, idx, collection),
);
};
}

const headings = el.querySelectorAll(':scope > div:nth-child(odd)');
const items = [...headings].map(
(heading, idx) =>
createItem(accordion, id, heading, idx + 1, isEditorial, accordionMedia)
(heading, idx) => createItem(accordion, id, heading, idx + 1, isEditorial, accordionMedia),
);

if (isSeo) { setSEO(items); }
Expand All @@ -145,9 +143,9 @@ export default function init(el) {
accordion.classList.add('foreground');
decorateBlockAnalytics(el);
decorateLinkAnalytics(accordion, headings);
el.append(accordion)
el.append(accordion);
if (isEditorial) {
el.append(accordionMedia);
defalutOpen(el);
};
}
}
2 changes: 1 addition & 1 deletion libs/blocks/aside/aside.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getBlockData(el) {
function decorateStaticLinks(el) {
if (!el.classList.contains('notification')) return;
const textLinks = el.querySelectorAll('a:not([class])');
textLinks.forEach((link) => { link.classList.add('static') });
textLinks.forEach((link) => { link.classList.add('static'); });
}

function decorateLayout(el) {
Expand Down
8 changes: 3 additions & 5 deletions libs/blocks/bulk-publish/bulk-publish-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ const siteIsSupported = async (url) => {
}
};

export const getUrls = (element) => {
return element.current?.value.split('\n')
.filter((url) => url.length > 0)
.map((e) => e.trim());
};
export const getUrls = (element) => element.current?.value.split('\n')
.filter((url) => url.length > 0)
.map((e) => e.trim());

export const getActionName = (action, useGerund) => {
let name;
Expand Down
4 changes: 3 additions & 1 deletion libs/blocks/bulk-publish/bulk-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ function StatusCompletion({ completion }) {
}

// eslint-disable-next-line max-len
function Status({ valid, urlNumber, bulkTriggered, submittedAction, result, resultsElt, completion }) {
function Status({
valid, urlNumber, bulkTriggered, submittedAction, result, resultsElt, completion,
}) {
return valid && html`
<div class="bulk-status">
<div class="bulk-status-info">
Expand Down
33 changes: 15 additions & 18 deletions libs/blocks/caas-config/caas-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getHashConfig = () => {

const encodedConfig = hash.startsWith('#') ? hash.substring(1) : hash;
return parseEncodedConfig(encodedConfig);
}
};

const caasFilesLoaded = loadCaasFiles();

Expand All @@ -64,7 +64,7 @@ const defaultOptions = {
'double-wide': 'Double Width Card',
product: 'Product Card',
'text-card': 'Text Card',
'custom-card': 'Custom Card'
'custom-card': 'Custom Card',
},
collectionBtnStyle: {
primary: 'Primary',
Expand All @@ -80,8 +80,8 @@ const defaultOptions = {
carousel: 'Carousel',
},
ctaActions: {
'_blank': 'New Tab',
'_self': 'Same Tab',
_blank: 'New Tab',
_self: 'Same Tab',
},
draftDb: {
false: 'Live',
Expand Down Expand Up @@ -193,11 +193,10 @@ const defaultOptions = {
},
};

const getTagList = (root) =>
Object.entries(root).reduce((options, [, tag]) => {
options[tag.tagID] = tag.title;
return options;
}, {});
const getTagList = (root) => Object.entries(root).reduce((options, [, tag]) => {
options[tag.tagID] = tag.title;
return options;
}, {});

const getTagTree = (root) => {
const options = Object.entries(root).reduce((opts, [, tag]) => {
Expand Down Expand Up @@ -238,7 +237,7 @@ const Select = ({ label, options, prop, sort = false }) => {
`;
};

const Input = ({ label, type = 'text', prop, defaultValue = '', title}) => {
const Input = ({ label, type = 'text', prop, defaultValue = '', title }) => {
const context = useContext(ConfiguratorContext);

const onInputChange = (val, e) => {
Expand Down Expand Up @@ -514,7 +513,7 @@ const FilterPanel = ({ tagsData }) => {
<${Select} label="Event Filter" prop="filterEvent" options=${defaultOptions.filterEvent} />
<${Select} label="Automatic or Custom Panel" prop="filterBuildPanel" options=${defaultOptions.filterBuildPanel} />
`;

const FilterBuildPanel = html`
<${FilterOptions}>
<${MultiField}
Expand Down Expand Up @@ -608,15 +607,13 @@ const PaginationPanel = () => {
`;
};

const TargetPanel = () =>
html`
const TargetPanel = () => html`
<${Input} label="Target Enabled" prop="targetEnabled" type="checkbox" />
<${Input} label="Last Viewed Session" prop="lastViewedSession" type="checkbox" />
<${Input} label="Target Activity" prop="targetActivity" type="text" />
`;

const AnalyticsPanel = () =>
html`<${Input} label="Track Impression" prop="analyticsTrackImpression" type="checkbox" />
const AnalyticsPanel = () => html`<${Input} label="Track Impression" prop="analyticsTrackImpression" type="checkbox" />
<${Input} label="Collection Name" prop="analyticsCollectionName" type="text" />`;

const AdvancedPanel = () => {
Expand Down Expand Up @@ -687,7 +684,7 @@ const getInitialState = () => {
// /* c8 ignore next 2 */
if (!state) {
const lsState = localStorage.getItem(LS_KEY);
// For backwards compatibilty: Check that localStorage state exists
// For backwards compatibilty: Check that localStorage state exists
// and it contains the new filtersCustom attribute before using it
if (lsState?.includes('filtersCustom')) {
try {
Expand Down Expand Up @@ -776,8 +773,8 @@ const CopyBtn = () => {
return html` <textarea class=${`copy-text ${(!navigator?.clipboard) ? '' : 'hide'}`}>${configUrl}</textarea>
<button
class="copy-config ${isError === true ? 'is-error' : ''} ${isSuccess === true
? 'is-success'
: ''}"
? 'is-success'
: ''}"
onClick=${copyConfig}
>
${btnText}
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/caas-config/caas-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -8118,7 +8118,7 @@ const caasTags = {
id: 'caas:events',
title: 'Events',
},
path: '/content/cq:tags/caas/events/eml',
path: '/content/cq:tags/caas/events/eml',
tagID: 'caas:events/eml',
name: 'eml',
tagImage: '',
Expand Down
4 changes: 2 additions & 2 deletions libs/blocks/card/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const addWrapper = (el, section, cardType) => {
let upClass = getUpFromSectionMetadata(section);
// Authored w/ a typed out number reference... 'two-up' vs. '2-up'
const list = ['two-up', 'three-up', 'four-up', 'five-up'];
const ixd = list.findIndex(i => i.includes(upClass));
const ixd = list.findIndex((i) => i.includes(upClass));
if (ixd > -1) {
upClass = `${ixd+2}-up`;
upClass = `${ixd + 2}-up`;
section.classList.remove(list[ixd]);
}
const up = upClass?.replace('-', '') || '3up';
Expand Down
4 changes: 3 additions & 1 deletion libs/blocks/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ const setDonutListeners = (chart, source, seriesData, units = []) => {
chart.on('legendselectchanged', ({ selected }) => { mouseOutValue = handleDonutSelect(sourceData, selected, chart, units?.[0], title); });
};

const initChart = ({ chartWrapper, chartType, data, series, size, ...rest }) => {
const initChart = ({
chartWrapper, chartType, data, series, size, ...rest
}) => {
const themeName = getTheme(size);
const options = { chartType, processedData: data, series, size, ...rest };
const chartOptions = getChartOptions(options);
Expand Down
5 changes: 2 additions & 3 deletions libs/blocks/commerce/commerce.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTag, getConfig, loadScript } from '../../utils/utils.js';
import { getTacocatEnv, runTacocat, buildCheckoutButton, getCheckoutContext, omitNullValues } from '../merch/merch.js';
import { debounce } from "../../utils/action.js";
import { debounce } from '../../utils/action.js';

window.tacocat.loadPromise = new Promise((resolve) => {
const { env, locale } = getConfig();
Expand Down Expand Up @@ -141,8 +141,7 @@ export const handleSearch = async (event, el) => {
window.tacocat.wcs.resolveOfferSelector(osi).then(([offerDetails]) => {
decorateOfferDetails(el, offerDetails, url.searchParams);
}).catch(displaySearchError);
}
catch (e) {
} catch (e) {
displaySearchError();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../utilities/utilities.js';
import { replaceKeyArray } from '../../../../features/placeholders.js';
import { getConfig } from '../../../../utils/utils.js';
import { debounce } from "../../../../utils/action.js";
import { debounce } from '../../../../utils/action.js';

const CONFIG = {
suggestions: {
Expand Down
4 changes: 2 additions & 2 deletions libs/blocks/icon-block/icon-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function decorateContent(el) {
const variant = [...variants].filter((v) => el.classList.contains(v))?.[0] ?? 'fullwidth';
decorateBlockText(el, iconBlocks[size][variant]);
if (el.classList.contains('inline')) {
const textContent = el.querySelectorAll('.text-content > :not(.icon-area)');
const secondColumn = createTag('div', {class:'second-column'});
const textContent = el.querySelectorAll('.text-content > :not(.icon-area)');
const secondColumn = createTag('div', { class: 'second-column' });
textContent.forEach((el) => {
secondColumn.append(el);
});
Expand Down
9 changes: 6 additions & 3 deletions libs/blocks/marketo/marketo.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ export default function init(el) {
fragment.append(formWrapper);
el.replaceChildren(fragment);

createIntersectionObserver({ el, callback: (el) => {
loadMarketo(el, formData);
}});
createIntersectionObserver({
el,
callback: (el) => {
loadMarketo(el, formData);
},
});
}
2 changes: 1 addition & 1 deletion libs/blocks/marquee/marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const decorateBlockBg = (block, node) => {

const pic = child.querySelector('picture');
if (pic && (child.childElementCount == 2 || child.textContent)) {
const { handleFocalpoint } = await import ('../section-metadata/section-metadata.js');
const { handleFocalpoint } = await import('../section-metadata/section-metadata.js');
handleFocalpoint(pic, child, true);
}
});
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/recommended-articles/recommended-articles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTag, getMetadata, getConfig } from '../../utils/utils.js';
import fetchTaxonomy from '../../scripts/taxonomy.js';
import { replaceKey } from '../../features/placeholders.js'
import { replaceKey } from '../../features/placeholders.js';

async function getArticleDetails(article) {
const path = new URL(article.href).pathname;
Expand Down
8 changes: 5 additions & 3 deletions libs/blocks/review/components/helixReview/HelixReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ const HelixReview = ({
setTotalReviews(localData.totalReviews);
localDataTotalReviews = localData.totalReviews;
}
if (onReviewLoad)
if (onReviewLoad) {
onReviewLoad({
hasRated: !!localData,
rating: localData ? localData.rating : undefined,
});
}

// eslint-disable-next-line no-use-before-define
getHelixData(localDataTotalReviews, !!localData);
Expand Down Expand Up @@ -73,12 +74,13 @@ const HelixReview = ({
if (total > localDataTotalReviews) setTotalReviews(total);
setDisplayRatingSummary(true);
setDisplayReviewComp(true);
if (!hasLocalData)
if (!hasLocalData) {
setInitialRating(
initialValue !== undefined
? initialValue
: Math.round(average)
: Math.round(average),
);
}

if (productJson) {
setJsonLdProductInfo(productJson, average, total);
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/review/components/review/Comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Comments({

const charCountElement = html`
<span class="comment-counter">${charCount}/${maxLength}</span>
`
`;
return html`
<fieldset className=${commentsClass}>
<label htmlFor="rating-comments" />
Expand Down
Loading

0 comments on commit 5e19b81

Please sign in to comment.