Skip to content

Commit

Permalink
Migrate to ESLint 9 and ESLint flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Oct 17, 2024
1 parent 8f2d01f commit 4ce3b39
Show file tree
Hide file tree
Showing 15 changed files with 626 additions and 184 deletions.
14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

37 changes: 37 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import hypothesis from 'eslint-config-hypothesis';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: [
'.tox/**/*',
'.yalc/**/*',
'.yarn/**/*',
'build/**/*',
'**/vendor/**/*.js',
'**/coverage/**/*',
'docs/_build/*',
],
},
...hypothesis,
...tseslint.configs.recommended,
jsxA11y.flatConfigs.recommended,
{
rules: {
'prefer-arrow-callback': 'error',
'prefer-const': ['error', { destructuring: 'all' }],
},
},

{
files: ['*.js'],
ignores: ['h/**'],
languageOptions: {
globals: {
...globals.node,
},
},
},
);
5 changes: 0 additions & 5 deletions h/static/scripts/.eslintrc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export function CreateGroupFormController(element) {
// Create Group form handling
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this._submitBtn = element.querySelector('.js-create-group-create-btn');
this._groupNameInput = element.querySelector('.js-group-name-input');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Button,
CancelIcon,
RadioGroup,
ModalDialog,
useWarnOnPageUnload,
} from '@hypothesis/frontend-shared';
import { readConfig } from '../config';
Expand Down Expand Up @@ -164,8 +163,6 @@ export default function CreateEditGroupForm() {
setErrorMessage('');
setSaveState('saving');

let response: CreateUpdateGroupAPIResponse;

try {
const body: CreateUpdateGroupAPIRequest = {
id: group!.pubid,
Expand All @@ -174,7 +171,7 @@ export default function CreateEditGroupForm() {
type: groupType,
};

response = (await callAPI(config.api.updateGroup!.url, {
(await callAPI(config.api.updateGroup!.url, {
method: config.api.updateGroup!.method,
headers: config.api.updateGroup!.headers,
json: body,
Expand Down
3 changes: 1 addition & 2 deletions h/static/scripts/group-forms/components/forms/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useId, useState } from 'preact/hooks';
import { Input, Textarea } from '@hypothesis/frontend-shared';

import Label from './Label';
import Star from './Star';

function CharacterCounter({
value,
Expand Down Expand Up @@ -85,7 +84,7 @@ export default function TextField({
onChangeValue((e.target as HTMLInputElement).value);
};

const handleChange = (e: Event) => {
const handleChange = () => {
setHasCommitted(true);
};

Expand Down
2 changes: 1 addition & 1 deletion h/static/scripts/group-forms/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { GroupType } from './utils/api';
export type APIConfig = {
method: string;
url: string;
headers: object;
headers: Record<PropertyKey, unknown>;
};

export type ConfigObject = {
Expand Down
8 changes: 6 additions & 2 deletions h/static/scripts/group-forms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ function init() {
const shadowHost = document.querySelector('#create-group-form')!;
const shadowRoot = shadowHost.attachShadow({ mode: 'open' });
const config = readConfig();
const stylesheetLinks = config.styles.map(stylesheetURL => (
<link rel="stylesheet" href={stylesheetURL} />
const stylesheetLinks = config.styles.map((stylesheetURL, index) => (
<link
key={`${stylesheetURL}${index}`}
rel="stylesheet"
href={stylesheetURL}

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
/>
));
render(
<>
Expand Down
4 changes: 2 additions & 2 deletions h/static/scripts/group-forms/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class APIError extends Error {
/* The response that was received, if any. */
response: Response | null;
/* The parsed JSON body of the response, if there was a valid JSON response. */
json: object | Array<any> | null;
json: object | Array<unknown> | null;

constructor(
message: string,
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function callAPI(
}: {
method?: string;
json?: object | null;
headers?: any;
headers?: Record<PropertyKey, unknown>;
} = {},
): Promise<object> {
const options: RequestInit = {
Expand Down
2 changes: 2 additions & 0 deletions h/static/scripts/karma.config.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global module */

module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable mocha/no-nested-tests */
import syn from 'syn';

import { LozengeController } from '../../controllers/lozenge-controller';
Expand Down
1 change: 1 addition & 0 deletions h/static/scripts/tests/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable mocha/no-exports */
/**
* Helper for writing parameterized tests.
*
Expand Down
2 changes: 1 addition & 1 deletion h/static/scripts/util/annotation-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function extractIDFromURL(url) {
} else {
return null;
}
} catch (err) {
} catch {
return null;
}
}
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@
"diff": "^5.2.0",
"enzyme": "^3.11.0",
"enzyme-adapter-preact-pure": "^4.1.0",
"eslint": "^8.57.0",
"eslint-config-hypothesis": "2.6",
"eslint": "^9.12.0",
"eslint-config-hypothesis": "^3.0.0",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-react": "^7.37.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "^5.0.0",
"globals": "^15.11.0",
"karma": "^6.4.4",
"karma-chrome-launcher": "^3.2.0",
"karma-mocha": "^2.0.1",
Expand All @@ -64,7 +66,8 @@
"prettier": "^3.3.3",
"sinon": "^18.0.0",
"syn": "^0.2.2",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"typescript-eslint": "^8.9.0"
},
"engines": {
"node": ">=6"
Expand Down
Loading

0 comments on commit 4ce3b39

Please sign in to comment.