Skip to content

Commit

Permalink
Stricter eslint checks and a ton of resultant updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mdirolf committed Nov 1, 2023
1 parent 6e34869 commit 5a86baa
Show file tree
Hide file tree
Showing 118 changed files with 1,651 additions and 1,227 deletions.
66 changes: 66 additions & 0 deletions app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* eslint-env node */

module.exports = {
env: {
browser: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:jsx-a11y/recommended',
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'next/core-web-vitals',
'prettier',
],
overrides: [
{
extends: ['plugin:@typescript-eslint/disable-type-checked'],
files: ['./**/*.{js,cjs}'],
},
],
ignorePatterns: ['next.config.mjs', 'jest.config.mjs'],
parser: '@typescript-eslint/parser',
parserOptions: { project: true, tsconfigRootDir: __dirname },
plugins: ['@emotion', 'lingui'],
rules: {
// someday?... "lingui/no-unlocalized-strings": 2,
'lingui/t-call-in-function': 2,
'lingui/no-single-variables-to-translate': 2,
'lingui/no-expression-in-message': 2,
'lingui/no-single-tag-to-translate': 2,
'lingui/no-trans-inside-trans': 2,
'@emotion/pkg-renaming': 'error',
'jsx-a11y/anchor-is-valid': [
'error',
{
components: ['Link'],
},
],
'jsx-a11y/anchor-has-content': [
'error',
{
components: ['Link'],
},
],
'linebreak-style': ['error', 'unix'],
semi: ['error', 'always'],
'@typescript-eslint/strict-boolean-expressions': [
'error',
{
allowNullableBoolean: true,
allowNullableNumber: true,
allowNullableString: true,
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
},
],

// TODO get this turned on, it's just a lot to update all at once.
'@typescript-eslint/prefer-nullish-coalescing': 'off'
},
};
58 changes: 0 additions & 58 deletions app/.eslintrc.json

This file was deleted.

25 changes: 17 additions & 8 deletions app/components/AlternateSolutionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from '../reducers/reducer';
import { isSome } from 'fp-ts/lib/Option';
import { GridView } from './Grid';
import { logAsyncErrors } from '../lib/utils';

export function AlternateSolutionEditor(props: {
grid: string[];
Expand Down Expand Up @@ -106,13 +107,13 @@ export function AlternateSolutionEditor(props: {

const pasteHandler = useCallback(
(e: ClipboardEvent) => {
const tagName = (e.target as HTMLElement)?.tagName?.toLowerCase();
const tagName = (e.target as HTMLElement).tagName.toLowerCase();
if (tagName === 'textarea' || tagName === 'input') {
return;
}
const pa: PasteAction = {
type: 'PASTE',
content: e.clipboardData?.getData('Text') || '',
content: e.clipboardData?.getData('Text') ?? '',
};
dispatch(pa);
e.preventDefault();
Expand All @@ -138,7 +139,7 @@ export function AlternateSolutionEditor(props: {
<TopBarLink
icon={<FaSave />}
text="Add Alternate"
onClick={async () => {
onClick={logAsyncErrors(async () => {
const alt: Record<number, string> = {};
let hadAny = false;
for (const [idx, cellValue] of state.grid.cells.entries()) {
Expand All @@ -155,8 +156,10 @@ export function AlternateSolutionEditor(props: {
props.cancel();
return;
}
return props.save(alt).then(() => props.cancel());
}}
return props.save(alt).then(() => {
props.cancel();
});
})}
/>
<TopBarLink
icon={<FaWindowClose />}
Expand All @@ -182,19 +185,25 @@ export function AlternateSolutionEditor(props: {
<TopBarDropDownLink
icon={<FaVolumeUp />}
text="Unmute"
onClick={() => setMuted(false)}
onClick={() => {
setMuted(false);
}}
/>
) : (
<TopBarDropDownLink
icon={<FaVolumeMute />}
text="Mute"
onClick={() => setMuted(true)}
onClick={() => {
setMuted(true);
}}
/>
)}
<TopBarDropDownLink
icon={<FaKeyboard />}
text="Toggle Keyboard"
onClick={() => setToggleKeyboard(!toggleKeyboard)}
onClick={() => {
setToggleKeyboard(!toggleKeyboard);
}}
/>
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion app/components/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AccountPrefsT } from '../lib/prefs';

export interface AuthContextValue {
user?: User;
notifications?: Array<NotificationT>;
notifications?: NotificationT[];
isAdmin: boolean;
isPatron: boolean;
loading: boolean;
Expand Down
8 changes: 6 additions & 2 deletions app/components/AuthHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function renderLoginIfNeeded({

/* Ensure we have a non-anonymous user, upgrading an anonymous user if we have one. */
export function requiresAuth<T>(WrappedComponent: React.ComponentType<T>) {
return (props: T & WithConditionalCSSProp<T>): ReactNode => {
return function AuthRequired(
props: T & WithConditionalCSSProp<T>
): ReactNode {
const ctx = useContext(AuthContext);
const login = renderLoginIfNeeded(ctx);
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
Expand All @@ -109,7 +111,9 @@ export function requiresAuth<T>(WrappedComponent: React.ComponentType<T>) {

/* Ensure we have an admin user, upgrading an anonymous user if we have one. */
export function requiresAdmin<T>(WrappedComponent: React.ComponentType<T>) {
return (props: T & WithConditionalCSSProp<T>): ReactNode => {
return function AdminRequired(
props: T & WithConditionalCSSProp<T>
): ReactNode {
const ctx = useContext(AuthContext);
const login = renderLoginIfNeeded(ctx);
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
Expand Down
Loading

0 comments on commit 5a86baa

Please sign in to comment.