Skip to content

Commit

Permalink
starts automated accessibility steps: loads @axe-core/react on `nex…
Browse files Browse the repository at this point in the history
…t dev`, enables `eslint-plugin-jsx-a11y` on `strict` (#245)

This PR does a couple of things:

1. installs and enables `eslint-plugin-jsx-a11y`, and turns it on with `strict` mode
    * this triggers on the navbar improperly using the `<label>` element, which is a valid concern. reworking it involves changing the DOM structure of the navbar, which in turn breaks the CSS - I'd like to table fixing this until we rework the navbar
    * this also triggers on next's `<Link><a></a></Link>` pattern, which is realistically a false-positive. Unfortunately, there's no great solution to this, and as such I've temporarily disabled the rule for `<Link>`; see the comments in the eslint config for more info
2. installs and enables `@axe-core/react`, which logs accessibility issues to the console in dev
    * there are **a ton** of issues to resolve. so, I'll scope that out for another PR instead. 

Something that's still left to be desired is to get aXe's level of accessibility specificity, but getting it as a CI action (like `eslint-plugin-jsx-a11y`) - will figure that out soon!

Part of #218.
  • Loading branch information
mattxwang authored Aug 20, 2021
1 parent 354a8a4 commit 25775b3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
16 changes: 15 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'eslint:recommended',
'plugin:react/recommended',
'plugin:@next/next/recommended',
'plugin:jsx-a11y/strict',
],
parserOptions: {
ecmaFeatures: {
Expand All @@ -16,7 +17,11 @@ module.exports = {
sourceType: 'module',
},
ignorePatterns: ['/build/*'],
plugins: ['react', 'import'],
plugins: [
'react',
'import',
'jsx-a11y',
],
settings: {
react: {
version: 'detect',
Expand Down Expand Up @@ -106,5 +111,14 @@ module.exports = {

// Are you sure | is not a typo for || ?
'no-bitwise': ['error'],

// bandaid fix; see the following github issues
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/402
// https://github.com/vercel/next.js/issues/5533
'jsx-a11y/anchor-is-valid': [ 'error', {
components: [ 'Link' ],
specialLink: [ 'hrefLeft', 'hrefRight' ],
aspects: [ 'invalidHref', 'preferButton' ],
}],
},
};
2 changes: 2 additions & 0 deletions components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export default class Navbar extends React.Component {
</ul>
</div>
<div className="nav-section right" id="mobile-nav">
{/* TODO: resolve this by refactoring the navbar */}
{/* eslint-disable-next-line jsx-a11y/label-has-for */}
<label htmlFor="menu-toggle">
<div className="hamburger-icon">
<div className="bar" id="top-bar" />
Expand Down
22 changes: 19 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
]
},
"devDependencies": {
"@axe-core/react": "^4.2.2",
"eslint": "^7.32.0",
"eslint-config-next": "^11.1.0",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"stylelint": "^13.13.1",
"stylelint-config-recommended": "^5.0.0",
Expand Down
9 changes: 8 additions & 1 deletion pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { config } from '@fortawesome/fontawesome-svg-core';
import Head from 'next/head';
import React from 'react';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';

import '@fortawesome/fontawesome-svg-core/styles.css';
import '../styles/App.scss';

config.autoAddCss = false; // Tell Font Awesome to skip adding the CSS automatically since it's being imported above

export default function App({ Component, pageProps}) {
useEffect(() => {
if (process.env.NODE_ENV !== 'production') {
const axe = require('@axe-core/react');
axe(React, ReactDOM, 1000);
}
}, []);
return (
<>
<Head>
Expand Down
2 changes: 1 addition & 1 deletion pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function About() {
<div className={`${styles.ornament} ${styles['square-ornament']}`}>
{/* TODO: resolve next/image issue */}
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className={styles['square-splash']} src='/images/about1.png' alt="a picture of acm students at our annual CS BBQ!"/>
<img className={styles['square-splash']} src='/images/about1.png' alt="ACM students at our annual CS BBQ!"/>
{/* TODO: use next image without breaking deploy */}
<div className={styles['square-small']} />
<div className={styles['square-tiny']} />
Expand Down
2 changes: 1 addition & 1 deletion styles/components/Navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
height: 60px;
width: 180px;
}

#navbar-inner {
margin: auto;
max-width: 1000px;
Expand Down

0 comments on commit 25775b3

Please sign in to comment.