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: integrate eslint-plugin-jsx-a11y into the existing ESLint setup #4764

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a6d8260
chore: installeslint-plugin-jsx-a11y as a development dependency
chillkang Jul 16, 2024
c1c94b9
chore: update ESLint configuration
chillkang Jul 16, 2024
75434a4
chore: add jsx-ally plugin to jslintrc configuration file
chillkang Jul 22, 2024
f02c0c2
Merge branch 'main' into WD-12366-integrate-eslint-plugin-jsx-ally-in…
chillkang Jul 22, 2024
15bb560
chore: add eslint plugin and parser for typescript in ESLint configur…
chillkang Jul 22, 2024
720e1b9
Merge branch 'WD-12366-integrate-eslint-plugin-jsx-ally-into-js-lint-…
chillkang Jul 22, 2024
0258131
chore: add jsx-a11y linter configuration file and a script to package…
chillkang Jul 23, 2024
dac395b
chore: add lint-a11y job to github actions workflow
chillkang Jul 23, 2024
6e5574b
chore: add lint-a11y job to the github actions workflow
chillkang Jul 23, 2024
ef81cb8
chore: add file extensions to lint-js script
chillkang Jul 25, 2024
45e5808
chore: add typescript parser and plugin in the ESLint configuration file
chillkang Jul 25, 2024
76a1fa8
chore: add typescript eslint
chillkang Jul 25, 2024
b1c11d4
chore: add typescript parser
chillkang Jul 25, 2024
6bdcd0d
chore: add fix option to lint-js script
chillkang Jul 25, 2024
46c4f04
chore: add prettier to the configuration and react/react-in-jsx-scope…
chillkang Jul 25, 2024
adffda3
chore: disable no-unescapted entities
chillkang Jul 26, 2024
40a6121
chore: update js test assertions
chillkang Aug 8, 2024
b593d14
chore: add typescript eslint
chillkang Jul 25, 2024
53a4dde
chore: fix the existing formatting errors
chillkang Aug 1, 2024
369ce4d
chore: fix linting errors in debouce.test.ts
chillkang Aug 1, 2024
f9c16f1
chore: fix linting errors in throttle.test.ts
chillkang Aug 1, 2024
42d2174
chore: fix linting errors in debounce.ts
chillkang Aug 1, 2024
ec7cf3b
chore: fix linting errors in iframeSize.test.ts
chillkang Aug 1, 2024
7d51520
chore: add continue-on-error temporarily to fix the existing linting …
chillkang Aug 8, 2024
8d3bb1b
chore: temporarily disable lint-js check until fixing the existing li…
chillkang Aug 8, 2024
4e7064a
chore: enable lint-js pr check
chillkang Aug 9, 2024
5ca7357
chore: enable lint-js check
chillkang Aug 9, 2024
85ccf3c
chore: fix lint errors in first-snap-flow.ts
chillkang Aug 12, 2024
49086ce
chore: fix lint errors in map.ts
chillkang Aug 12, 2024
6e82cf0
chore: fix lint errors in blog-posts.ts
chillkang Aug 13, 2024
c19f503
chore: fix lint errors in channelMap.ts
chillkang Aug 14, 2024
5f8383e
Merge pull request #2 from chillkang/WD-13826-fix-lint-errors-in-js-p…
chillkang Aug 15, 2024
adf2446
chore: fix lint errors in statis/js/brandstore
chillkang Oct 7, 2024
5f5c7df
chore: fix python-test errors
chillkang Oct 8, 2024
51b2b75
chore: add explicit type for Model
chillkang Oct 11, 2024
c742780
Merge pull request #3 from chillkang/WD-13828-fix-lint-errors-in-bran…
chillkang Oct 11, 2024
c59f3f5
chore: fix remaining lint errors in brandstore
chillkang Oct 15, 2024
b8954ea
chore: fix webpack compile errors
chillkang Oct 16, 2024
8aeac9f
Merge pull request #4 from chillkang/WD-15836-fix-remaining-lint-erro…
chillkang Oct 16, 2024
1419871
chore: fix remaining lint errors in static/js/libs
chillkang Oct 17, 2024
c87138f
chore: fix lint errors in global.d.ts
chillkang Oct 17, 2024
e430f34
chore: fix compile errors
chillkang Oct 22, 2024
2ee446f
Merge pull request #5 from chillkang/WD-15837-fix-remaining-lint-erro…
chillkang Oct 22, 2024
b78e426
chore: empty commit for triggering CI
chillkang Oct 22, 2024
b97d912
chore: empty commit for triggering CI
chillkang Oct 22, 2024
54e2d35
Merge branch 'WD-13579-fix-exisiting-js-linting-issues' into WD-12366…
chillkang Oct 24, 2024
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
20 changes: 16 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 @@ -18,15 +18,27 @@ module.exports = {
ecmaFeatures: {
jsx: true,
},
requireConfigFile: false,
},
rules: {
"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"],
},
],
};
29 changes: 28 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,39 @@ jobs:
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

lint-a11y:
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 for Accessibility
if: ${{ steps.filter.outputs.js == 'true' || steps.filter.outputs.ts == 'true' || steps.filter.outputs.jsx == 'true' || steps.filter.outputs.tsx == 'true' }}
run: yarn lint-a11y

test-python:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: dorny/paths-filter@v3
id: filter
with:
Expand Down
30 changes: 30 additions & 0 deletions eslint-a11y.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
parser: "@babel/eslint-parser",
plugins: ["jsx-a11y"],
env: {
browser: true,
es6: true,
node: true,
},
extends: [
"plugin:jsx-a11y/recommended",
],
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
requireConfigFile: false,
},
overrides: [
{
files: ["*.ts", "*.tsx"],
parser: "@typescript-eslint/parser",
plugins: ["jsx-a11y"],
extends: [
"plugin:jsx-a11y/recommended",
],
},
],
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"scripts": {
"lint-js": "eslint static/js",
"lint-js": "eslint static/js --ext .js,.jsx,.ts,.tsx",
"lint-a11y": "eslint -c eslint-a11y.config.js static/js --ext .js,.jsx,.ts,.tsx",
"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,11 +112,14 @@
"@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",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-jest": "27.6.1",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-react": "7.33.2",
"identity-obj-proxy": "3.0.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 @@ -2,7 +2,7 @@ import { screen, render, waitFor } from "@testing-library/react";
import "@testing-library/jest-dom";
import { Provider } from "react-redux";
import { BrowserRouter } from "react-router-dom";
import { MutableSnapshot, RecoilRoot } from "recoil";
import { MutableSnapshot, RecoilRoot, RecoilValue } from "recoil";
import { useEffect } from "react";
import { QueryClient, QueryClientProvider } from "react-query";
import { useRecoilValue } from "recoil";
Expand All @@ -12,7 +12,28 @@ import { publisherState } from "../../../atoms";

const queryClient = new QueryClient();

const RecoilObserver = ({ node, event }: { node: any; event: Function }) => {
type PublisherState = {
email: string;
fullname: string;
has_stores?: boolean;
identity_url: string;
image: string | null;
is_canonical: boolean;
nickname: string;
subscriptions: {
newsletter: boolean;
} | null;
};

type EventFunction<T> = (value: T) => void;

const RecoilObserver = <T,>({
node,
event,
}: {
node: RecoilValue<T>;
event: EventFunction<T>;
}) => {
const value = useRecoilValue(node);

useEffect(() => {
Expand All @@ -22,7 +43,13 @@ const RecoilObserver = ({ node, event }: { node: any; event: Function }) => {
return null;
};

const renderComponent = ({ event, state }: { event: Function; state: any }) => {
const renderComponent = ({
event,
state,
}: {
event: EventFunction<PublisherState | null>;
state: RecoilValue<PublisherState | null>;
}) => {
render(
<RecoilRoot
initializeState={(snapshot: MutableSnapshot) => {
Expand All @@ -48,7 +75,7 @@ const renderComponent = ({ event, state }: { event: Function; state: any }) => {
</QueryClientProvider>
</Provider>
</BrowserRouter>
</RecoilRoot>
</RecoilRoot>,
);
};

Expand Down
3 changes: 2 additions & 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 All @@ -44,6 +44,7 @@ function App(): ReactNode {
const setRecoilBrandStores = useSetRecoilState(brandStoresState);

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dispatch(fetchStores() as any);
}, []);

Expand Down
Loading