Switch to SWC Vite plugin, ESLint rules

This commit is contained in:
Adrian Rumpold
2025-05-22 09:26:56 +02:00
parent 0335e0cedb
commit 06bf874b80
10 changed files with 597 additions and 643 deletions

View File

@@ -1,28 +1,42 @@
import js from '@eslint/js' import js from "@eslint/js";
import globals from 'globals' import reactDOM from "eslint-plugin-react-dom";
import reactHooks from 'eslint-plugin-react-hooks' import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from 'eslint-plugin-react-refresh' import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from 'typescript-eslint' import reactX from "eslint-plugin-react-x";
import globals from "globals";
import tseslint from "typescript-eslint";
export default tseslint.config( export default tseslint.config(
{ ignores: ['dist'] }, { ignores: ["dist"] },
{ {
extends: [js.configs.recommended, ...tseslint.configs.recommended], extends: [
files: ['**/*.{ts,tsx}'], js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
],
files: ["**/*.{ts,tsx}"],
languageOptions: { languageOptions: {
ecmaVersion: 2020, ecmaVersion: 2020,
globals: globals.browser, globals: globals.browser,
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
}, },
plugins: { plugins: {
'react-hooks': reactHooks, "react-hooks": reactHooks,
'react-refresh': reactRefresh, "react-refresh": reactRefresh,
"react-x": reactX,
"react-dom": reactDOM,
}, },
rules: { rules: {
...reactHooks.configs.recommended.rules, ...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [ ...reactX.configs["recommended-typescript"].rules,
'warn', ...reactDOM.configs.recommended.rules,
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true }, { allowConstantExport: true },
], ],
}, },
}, }
) );

1131
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -22,10 +22,12 @@
"@types/papaparse": "^5.3.16", "@types/papaparse": "^5.3.16",
"@types/react": "^19.1.2", "@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2", "@types/react-dom": "^19.1.2",
"@vitejs/plugin-react": "^4.4.1", "@vitejs/plugin-react-swc": "^3.9.0",
"eslint": "^9.25.0", "eslint": "^9.25.0",
"eslint-plugin-react-dom": "^1.49.0",
"eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19", "eslint-plugin-react-refresh": "^0.4.19",
"eslint-plugin-react-x": "^1.49.0",
"globals": "^16.0.0", "globals": "^16.0.0",
"typescript": "~5.8.3", "typescript": "~5.8.3",
"typescript-eslint": "^8.30.1", "typescript-eslint": "^8.30.1",

View File

@@ -36,9 +36,9 @@ function App() {
{entries.length} entries found {entries.length} entries found
{selectedCitation && ( {selectedCitation && (
<CitationEntry <CitationEntry
citation={ citation={citations.find(
citations.find((citation) => citation.key === selectedCitation)! (citation) => citation.key === selectedCitation
} )}
onClose={() => setSelectedCitation(null)} onClose={() => setSelectedCitation(null)}
/> />
)} )}

View File

@@ -1,9 +1,9 @@
import { useState } from "react"; import { useState } from "react";
import "./AlphabeticalFilter.css"; import "./AlphabeticalFilter.css";
type AlphabeticalFilterProps = { interface AlphabeticalFilterProps {
onChange: (value: string) => void; onChange: (value: string) => void;
}; }
function AlphabeticalFilter({ onChange }: AlphabeticalFilterProps) { function AlphabeticalFilter({ onChange }: AlphabeticalFilterProps) {
const [selectedLetter, setSelectedLetter] = useState<string | null>(null); const [selectedLetter, setSelectedLetter] = useState<string | null>(null);
@@ -24,6 +24,7 @@ function AlphabeticalFilter({ onChange }: AlphabeticalFilterProps) {
const buttons = letters.map((letter) => ( const buttons = letters.map((letter) => (
<button <button
onClick={() => handleClick(letter)} onClick={() => handleClick(letter)}
type="button"
key={letter} key={letter}
className={[ className={[
"alphabetical-filter-button", "alphabetical-filter-button",

View File

@@ -1,10 +1,10 @@
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import type { Citation } from "../../lib/nist-api"; import type { Citation } from "../../lib/nist-api";
import "./CitationEntry.css"; import "./CitationEntry.css";
type CitationEntryProps = { interface CitationEntryProps {
citation?: Citation; citation?: Citation;
onClose?: () => void; onClose?: () => void;
}; }
export default function CitationEntry({ export default function CitationEntry({
citation, citation,

View File

@@ -1,17 +1,18 @@
import type { GlossaryTerm } from "../../lib/nist-api"; import type { GlossaryTerm } from "../../lib/nist-api";
import { hash } from "../../lib/util";
import "./GlossaryEntry.css"; import "./GlossaryEntry.css";
type GlossaryEntryProps = { interface GlossaryEntryProps {
term: GlossaryTerm; term: GlossaryTerm;
onSelectCitation?: (citationKey: string) => void; onSelectCitation?: (citationKey: string) => void;
}; }
function GlossaryEntry({ term, onSelectCitation }: GlossaryEntryProps) { function GlossaryEntry({ term, onSelectCitation }: GlossaryEntryProps) {
return ( return (
<> <>
<dt key={term.term}>{term.term}</dt> <dt key={term.term}>{term.term}</dt>
{term.definitions.map((def, index) => ( {term.definitions.map((def) => (
<dd key={term.term + index}> <dd key={`${hash(def.definition)}-${hash(def.citationKey)}`}>
{def.definition} {def.definition}
<a <a
className="citation" className="citation"

View File

@@ -1,12 +1,12 @@
import { Axios } from "axios"; import { Axios } from "axios";
import Papa from "papaparse"; import Papa from "papaparse";
export type Definition = { export interface Definition {
definition: string; definition: string;
citationKey: string; citationKey: string;
}; }
export type Citation = { export interface Citation {
key: string; key: string;
title: string; title: string;
authors: string; authors: string;
@@ -16,19 +16,19 @@ export type Citation = {
pages?: string; pages?: string;
year: string; year: string;
url: string; url: string;
}; }
export type GlossaryTerm = { export interface GlossaryTerm {
term: string; term: string;
definitions: Definition[]; definitions: Definition[];
relatedTerms: string; relatedTerms: string;
legalDefinition: string; legalDefinition: string;
}; }
export type Glossary = { export interface Glossary {
definitions: GlossaryTerm[]; definitions: GlossaryTerm[];
citations: Citation[]; citations: Citation[];
}; }
const baseUrl = const baseUrl =
"https://docs.google.com/spreadsheets/d/e/2PACX-1vTRBYglcOtgaMrdF11aFxfEY3EmB31zslYI4q2_7ZZ8z_1lKm7OHtF0t4xIsckuogNZ3hRZAaDQuv_K/pub?output=csv"; "https://docs.google.com/spreadsheets/d/e/2PACX-1vTRBYglcOtgaMrdF11aFxfEY3EmB31zslYI4q2_7ZZ8z_1lKm7OHtF0t4xIsckuogNZ3hRZAaDQuv_K/pub?output=csv";
@@ -45,7 +45,7 @@ const makeClient = () => {
export const fetchCitations = async () => { export const fetchCitations = async () => {
const client = makeClient(); const client = makeClient();
const resp = await client.get(baseUrl, { const resp = await client.get<string>(baseUrl, {
params: { params: {
gid: citationGid, gid: citationGid,
}, },
@@ -55,7 +55,7 @@ export const fetchCitations = async () => {
export const fetchDefinitions = async () => { export const fetchDefinitions = async () => {
const client = makeClient(); const client = makeClient();
const resp = await client.get(baseUrl, { const resp = await client.get<string>(baseUrl, {
params: { params: {
gid: glossaryGid, gid: glossaryGid,
}, },

13
src/lib/util.ts Normal file
View File

@@ -0,0 +1,13 @@
/**
* Generate a (non-cryptographic) hash value from a string.
* @param s string
* @returns string
*/
export function hash(s: string): string {
let hash = 0;
for (let i = 0; i < s.length; i++) {
hash = (hash << 5) - hash + s.charCodeAt(i);
hash |= 0; // Convert to 32bit integer
}
return hash.toString(16);
}

View File

@@ -1,7 +1,7 @@
import { defineConfig } from 'vite' import react from "@vitejs/plugin-react-swc";
import react from '@vitejs/plugin-react' import { defineConfig } from "vite";
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
}) });