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

chore: fix linting errors in /static/js/libs and formatting errors #4790

Merged
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
19 changes: 15 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
parser: "@babel/eslint-parser",
plugins: ["jest", "react"],
plugins: ["jest", "react", "prettier"],
globals: {},
env: {
browser: true,
Expand All @@ -23,10 +23,21 @@ module.exports = {
"linebreak-style": ["error", "unix"],
semi: ["error", "always"],
"object-curly-spacing": ["error", "always"],
"prettier/prettier": "error",
"react/react-in-jsx-scope": "off",
"react/no-unescaped-entities": "off",
},
settings: {
react: {
version: "detect"
}
}
version: "detect",
},
},
overrides: [
{
files: ["*.ts", "*.tsx"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["plugin:@typescript-eslint/recommended"],
},
],
};
55 changes: 28 additions & 27 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,40 @@ jobs:
if: ${{ steps.filter.outputs.scss == 'true' }}
run: yarn lint-scss

lint-js:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
js:
- '**/*.js'
ts:
- '**/*.ts'
jsx:
- '**/*.jsx'
tsx:
- '**/*.tsx'

- name: Install JS dependencies
if: ${{ steps.filter.outputs.js == 'true' || steps.filter.outputs.ts == 'true' || steps.filter.outputs.jsx == 'true' || steps.filter.outputs.tsx == 'true' }}
run: yarn install --immutable

- name: Lint JS
if: ${{ steps.filter.outputs.js == 'true' || steps.filter.outputs.ts == 'true' || steps.filter.outputs.jsx == 'true' || steps.filter.outputs.tsx == 'true' }}
run: yarn lint-js
# Temprarily disable it for PRs for fixing the existing linting errors
# lint-js:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4

# - uses: dorny/paths-filter@v3
# id: filter
# with:
# filters: |
# js:
# - '**/*.js'
# ts:
# - '**/*.ts'
# jsx:
# - '**/*.jsx'
# tsx:
# - '**/*.tsx'

# - name: Install JS dependencies
# if: ${{ steps.filter.outputs.js == 'true' || steps.filter.outputs.ts == 'true' || steps.filter.outputs.jsx == 'true' || steps.filter.outputs.tsx == 'true' }}
# run: yarn install --immutable

# - name: Lint JS
# if: ${{ steps.filter.outputs.js == 'true' || steps.filter.outputs.ts == 'true' || steps.filter.outputs.jsx == 'true' || steps.filter.outputs.tsx == 'true' }}
# run: yarn lint-js

test-python:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: dorny/paths-filter@v3
id: filter
with:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"lint-js": "eslint static/js",
"lint-js": "eslint static/js --ext .js,.jsx,.ts,.tsx --fix",
"lint-scss": "stylelint static/**/*.scss",
"lint-python": "flake8 webapp tests && black --diff --check --line-length 79 webapp tests",
"test": "yarn run test-python && yarn run test-js-all && yarn run lint-scss",
Expand Down Expand Up @@ -111,6 +111,8 @@
"@types/d3": "7.4.3",
"@types/markdown-it": "14.1.1",
"@types/uuid": "10.0.0",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"babel-jest": "29.7.0",
"concurrently": "8.2.2",
"eslint": "8.56.0",
Expand Down
4 changes: 2 additions & 2 deletions static/js/base/contactForm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const contactFormTriggers = document.querySelectorAll(
"[data-js='contact-form-trigger']"
"[data-js='contact-form-trigger']",
) as NodeListOf<Element>;

const modal = document.getElementById("contact-form-modal") as HTMLElement;
Expand All @@ -19,7 +19,7 @@ function handleClick(event: Event): void {
const args = target.dataset;

const formEl = document.getElementById(
"contactFormTemplate"
"contactFormTemplate",
) as HTMLFormElement;

let formTemplate = formEl.innerText;
Expand Down
16 changes: 8 additions & 8 deletions static/js/base/dropdown-menu-toggle.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(function () {
function toggleDropdown(toggle: HTMLElement, open: boolean) {
var parentElement = toggle.parentNode as HTMLElement;
var dropdownElId = toggle.getAttribute("aria-controls") as string;
const parentElement = toggle.parentNode as HTMLElement;
const dropdownElId = toggle.getAttribute("aria-controls") as string;

var dropdown = document.getElementById(dropdownElId) as HTMLElement;
const dropdown = document.getElementById(dropdownElId) as HTMLElement;

const openMenu = !open;

Expand All @@ -26,10 +26,10 @@

function handleClickOutside(
toggles: Array<HTMLElement>,
containerClass: string
containerClass: string,
) {
document.addEventListener("click", function (event) {
var target = event.target as HTMLElement;
const target = event.target as HTMLElement;

if (target.closest) {
if (!target.closest(containerClass)) {
Expand All @@ -40,8 +40,8 @@
}

function initNavDropdowns(containerClass: string) {
var toggles = [].slice.call(
document.querySelectorAll(containerClass + " [aria-controls]")
const toggles = [].slice.call(
document.querySelectorAll(containerClass + " [aria-controls]"),
);

handleClickOutside(toggles, containerClass);
Expand All @@ -50,7 +50,7 @@
toggle.addEventListener("click", function (e) {
e.preventDefault();

var parentElement = toggle.parentNode as HTMLElement;
const parentElement = toggle.parentNode as HTMLElement;
if (parentElement.classList.contains("is-active")) {
toggleDropdown(toggle, false);
} else {
Expand Down
4 changes: 2 additions & 2 deletions static/js/base/ga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function triggerEvent(
category: string,
from: string,
to: string,
label: string
label: string,
): void {
if (window.dataLayer) {
window.dataLayer.push({
Expand Down Expand Up @@ -70,7 +70,7 @@ if (typeof window.dataLayer !== "undefined") {
return;
}

for (let key in events) {
for (const key in events) {
if (target.matches(key)) {
// This prevents subsequent matches triggering
// So the order the events are added is important!
Expand Down
20 changes: 10 additions & 10 deletions static/js/base/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Login
var navAccountContainer = document.querySelector(
".js-nav-account"
const navAccountContainer = document.querySelector(
".js-nav-account",
) as HTMLElement;

if (navAccountContainer) {
var notAuthenticatedMenu = navAccountContainer.querySelector(
".js-nav-account--notauthenticated"
const notAuthenticatedMenu = navAccountContainer.querySelector(
".js-nav-account--notauthenticated",
) as HTMLElement;
var authenticatedMenu = navAccountContainer.querySelector(
".js-nav-account--authenticated"
const authenticatedMenu = navAccountContainer.querySelector(
".js-nav-account--authenticated",
) as HTMLElement;

fetch("/account.json")
.then((response) => response.json())
.then((data: { publisher: { fullname: string; has_stores: boolean } }) => {
if (data.publisher) {
var displayName = navAccountContainer.querySelector(
".js-account--name"
const displayName = navAccountContainer.querySelector(
".js-account--name",
) as HTMLElement;

notAuthenticatedMenu.classList.add("u-hide");
Expand All @@ -25,13 +25,13 @@ if (navAccountContainer) {
if (window.sessionStorage) {
window.sessionStorage.setItem(
"displayName",
data.publisher["fullname"]
data.publisher["fullname"],
);
}

if (data.publisher.has_stores) {
const storesMenu = authenticatedMenu.querySelector(
".js-nav-account--stores"
".js-nav-account--stores",
) as HTMLElement;
storesMenu.classList.remove("u-hide");
}
Expand Down
2 changes: 1 addition & 1 deletion static/js/brand-store/brand-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ root.render(
<RecoilRoot>
<App />
</RecoilRoot>
</Provider>
</Provider>,
);
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function AccountDetails(): ReactNode {

useEffect(() => {
setSubscribeToNewsletter(
publisher?.subscriptions ? publisher?.subscriptions?.newsletter : false
publisher?.subscriptions ? publisher?.subscriptions?.newsletter : false,
);
}, [publisher]);

Expand Down Expand Up @@ -171,11 +171,11 @@ function AccountDetails(): ReactNode {
onChange={(
e: SyntheticEvent<HTMLInputElement> & {
target: HTMLInputElement;
}
},
) => {
setSubscribeToNewsletter(e.target.checked);
setSubscriptionPreferencesChanged(
hasChanged(e.target.checked)
hasChanged(e.target.checked),
);
}}
/>
Expand Down Expand Up @@ -213,22 +213,22 @@ function AccountDetails(): ReactNode {
data.set("email", publisher?.email || "");
data.set(
"newsletter",
subscribeToNewsletter ? "on" : ""
subscribeToNewsletter ? "on" : "",
);

const response: Response = await fetch(
"/account/publisher",
{
method: "POST",
body: data,
}
},
);

if (!response.ok) {
setShowErrorMessage(true);
setIsSaving(false);
throw new Error(
"There has been a problem saving newsletter preferences"
"There has been a problem saving newsletter preferences",
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const renderComponent = ({ event, state }: { event: Function; state: any }) => {
</QueryClientProvider>
</Provider>
</BrowserRouter>
</RecoilRoot>
</RecoilRoot>,
);
};

Expand Down
2 changes: 1 addition & 1 deletion static/js/brand-store/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { StoresList, StoresSlice } from "../../types/shared";

function App(): ReactNode {
const isLoading = useSelector(
(state: StoresSlice) => state.brandStores.loading
(state: StoresSlice) => state.brandStores.loading,
);
const brandStoresList: StoresList = useSelector(brandStoresListSelector);
const dispatch = useDispatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function AppPagination({ keyword, items, setItemsToShow }: Props): ReactNode {
const [currentPage, setCurrentPage] = useState<number>(1);
const [visibleItemsCount, setVisibleItemsCount] = useState<number>(0);
const [totalPages, setTotalPages] = useState<number>(
Math.ceil(items.length / pageSize)
Math.ceil(items.length / pageSize),
);

useEffect(() => {
Expand All @@ -49,7 +49,7 @@ function AppPagination({ keyword, items, setItemsToShow }: Props): ReactNode {
const multiplier = currentPage - 1;
const itemsToShow = items.slice(
pageSize * multiplier,
pageSize * multiplier + pageSize
pageSize * multiplier + pageSize,
);

setItemsToShow(itemsToShow);
Expand Down Expand Up @@ -86,7 +86,7 @@ function AppPagination({ keyword, items, setItemsToShow }: Props): ReactNode {
labelClassName="u-off-screen u-off-screen--top"
onChange={(e) => {
setCurrentPage(
Math.min(totalPages, Math.max(1, parseInt(e.target.value)))
Math.min(totalPages, Math.max(1, parseInt(e.target.value))),
);
}}
/>{" "}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const renderComponent = (filterQuery?: string) => {
/>
</QueryClientProvider>
</BrowserRouter>
</RecoilRoot>
</RecoilRoot>,
);
};

Expand Down
6 changes: 3 additions & 3 deletions static/js/brand-store/components/Members/InvitesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ function InvitesTable({

useEffect(() => {
setPendingInvites(
invites.filter((invite: Invite) => invite.status === "Pending")
invites.filter((invite: Invite) => invite.status === "Pending"),
);
setExpiredInvites(
invites.filter((invite: Invite) => invite.status === "Expired")
invites.filter((invite: Invite) => invite.status === "Expired"),
);
setRevokedInvites(
invites.filter((invite: Invite) => invite.status === "Revoked")
invites.filter((invite: Invite) => invite.status === "Revoked"),
);
}, [invites]);

Expand Down
Loading
Loading