Skip to content

Commit

Permalink
Merge pull request #3461 from quantified-uncertainty/eslint9
Browse files Browse the repository at this point in the history
ESLint v9
  • Loading branch information
berekuk authored Dec 11, 2024
2 parents 586e2f9 + 01529bf commit 7736492
Show file tree
Hide file tree
Showing 42 changed files with 1,158 additions and 1,454 deletions.
6 changes: 4 additions & 2 deletions packages/ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"build": "pnpm run build:ts",
"build:ts": "tsc -b",
"dev": "tsc -b -w",
"lint": "prettier --check .",
"lint": "pnpm lint:prettier && pnpm eslint",
"lint:prettier": "prettier --check .",
"eslint": "ESLINT_USE_FLAT_CONFIG=false NODE_NO_WARNINGS=1 eslint src",
"format": "prettier --write .",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"prepareSquiggleFiles": "tsx src/scripts/prepareSquiggleFiles.ts",
Expand Down Expand Up @@ -38,7 +40,7 @@
"@babel/preset-env": "^7.25.8",
"@types/jest": "^29.5.13",
"@types/node": "^22.7.5",
"eslint": "^8.57.1",
"eslint": "^9.16.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
Expand Down
36 changes: 18 additions & 18 deletions packages/ai/src/scripts/fine-tuning/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ async function fetchAndProcessGroupModels(
return rawModels.map(processModel);
}

async function saveModelsToJSON(
models: ProcessedModel[],
outputPath: string
): Promise<void> {
try {
const jsonData = models.map((code, index) => ({
prompt: code.prompt,
code: code.response,
}));

const jsonString = JSON.stringify(jsonData, null, 2);
await fs.promises.writeFile(outputPath, jsonString, "utf-8");
console.log(`Successfully saved ${models.length} models to ${outputPath}`);
} catch (error) {
console.error("Error saving models to JSON:", error);
throw error;
}
}
// async function saveModelsToJSON(
// models: ProcessedModel[],
// outputPath: string
// ): Promise<void> {
// try {
// const jsonData = models.map((code, index) => ({
// prompt: code.prompt,
// code: code.response,
// }));

// const jsonString = JSON.stringify(jsonData, null, 2);
// await fs.promises.writeFile(outputPath, jsonString, "utf-8");
// console.log(`Successfully saved ${models.length} models to ${outputPath}`);
// } catch (error) {
// console.error("Error saving models to JSON:", error);
// throw error;
// }
// }

function formatModelsForFineTuning(models: ProcessedModel[]): string {
const formattedData = models.map((model) => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/ai/src/squiggle/squiggleCodeWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function getInvalidSquiggleElements(): InvalidElement[] {
},
{
check: (line: string) => /\bDate\.now\b/.test(line),
getMessage: (lineNumber: number, line: string) =>
getMessage: (lineNumber: number) =>
`Line ${lineNumber}: 'Date.now' is not available in Squiggle. Use 'Danger.now' instead for the current timestamp. Be cautious with time-dependent calculations as they may produce varying results.`,
},
{
Expand All @@ -96,7 +96,7 @@ function getInvalidSquiggleElements(): InvalidElement[] {
},
{
check: (line: string) => /=>/.test(line),
getMessage: (lineNumber: number, line: string) =>
getMessage: (lineNumber: number) =>
`Line ${lineNumber}: The arrow function syntax "=>" is not allowed in Squiggle. Use the standard function declaration syntax instead. If you want to write a lambda function, you can do this: {|x| x + 1 }`,
},
];
Expand Down
14 changes: 1 addition & 13 deletions packages/components/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,8 @@ module.exports = {
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "@wogns3623/better-exhaustive-deps"],
plugins: ["@typescript-eslint"],
rules: {
// Replace exhaustive-deps hook with a better fork
// Context: https://github.com/facebook/react/issues/16873
"react-hooks/exhaustive-deps": "off",
"@wogns3623/better-exhaustive-deps/exhaustive-deps": [
"warn",
{
checkMemoizedVariableIsStatic: true,
staticHooks: {
useLazyRef: true,
},
},
],
"no-constant-condition": [
"error",
{
Expand Down
12 changes: 6 additions & 6 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/unist": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"@wogns3623/eslint-plugin-better-exhaustive-deps": "^1.1.0",
"babel-jest": "^29.7.0",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint": "^9.16.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"jest": "^29.7.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
Expand Down Expand Up @@ -105,7 +105,7 @@
"build:storybook": "storybook build",
"lint": "pnpm lint:prettier && pnpm eslint",
"lint:prettier": "prettier --check .",
"eslint": "eslint --ignore-path .gitignore .",
"eslint": "ESLINT_USE_FLAT_CONFIG=false NODE_NO_WARNINGS=1 eslint src",
"format": "prettier --write .",
"prepack": "pnpm run build",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function useConfigureCodemirrorView(
view?.destroy();
};
// we initialize the view only once; no need for deps
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const setViewDom = useCallback(
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/components/CodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(
selection: { anchor: location.start.offset, head: location.end.offset },
scrollIntoView: true,
});
focus && view.focus();
if (focus) {
view.focus();
}
};

useImperativeHandle(ref, () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ function useNodesAndEdges({
}

return layoutGraph(nodes, edges);
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps

// `project.state` dependency is necessary;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [headTooltips, project, project.state]);
return { nodes, edges };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export const SquigglePlayground: React.FC<SquigglePlaygroundProps> = (
title: e[1].tags.name() ? e[1].tags.name() : e[1].title() || "",
docstring: e[1].context?.docstring() || "",
}));
onExportsChange && onExportsChange(_exports);
onExportsChange?.(_exports);
} else {
onExportsChange && onExportsChange([]);
onExportsChange?.([]);
}
}, [simulation, onExportsChange]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ export const ValueWithContextViewer: FC<Props> = ({
scrollEditorToPath();
}}
onKeyDown={(event) => {
isZoomedIn ? focusedKeyEvent(event) : unfocusedKeyEvent(event);
if (isZoomedIn) {
focusedKeyEvent(event);
} else {
unfocusedKeyEvent(event);
}
}}
>
<div className="inline-flex items-center space-x-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ export function useSetCollapsed() {
...state,
collapsed: isCollapsed,
}));
options?.skipUpdate || itemStore.forceUpdate(path);

if (!options?.skipUpdate) {
itemStore.forceUpdate(path);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export function useZoomedOutSqValueKeyEvent(selected: SqValuePath) {
return keyboardEventHandler({
ArrowDown: () => {
const newPath = findNode(selected)?.next()?.node.path;
newPath && itemStore.focusByPath(newPath);
if (newPath) itemStore.focusByPath(newPath);
},
ArrowUp: () => {
const newPath = findNode(selected)?.prev()?.node.path;
newPath && itemStore.focusByPath(newPath);
if (newPath) itemStore.focusByPath(newPath);
},
ArrowLeft: () => {
const newItem = findNode(selected)?.parent();
newItem && !newItem.isRoot() && itemStore.focusByPath(newItem.node.path);
if (newItem && !newItem.isRoot()) {
itemStore.focusByPath(newItem.node.path);
}
},
ArrowRight: () => {
const newItem = findNode(selected)?.children().at(0);
Expand Down
17 changes: 7 additions & 10 deletions packages/components/src/lib/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,13 @@ export function viewerTabToValue(
}
}

const selectableViewerTabs = [
"Imports",
"Variables",
"Exports",
"Result",
"Dependency Graph",
"AST",
] as const;

export type SelectableViewerTab = (typeof selectableViewerTabs)[number];
export type SelectableViewerTab =
| "Imports"
| "Variables"
| "Exports"
| "Result"
| "Dependency Graph"
| "AST";

export function viewerTabsToShow(
outputResult: SqModuleOutput["result"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const CalculatorResult: FC<Props> = ({
>(() => savedState?.calculatorResult);

const runCalculator = useCallback(() => {
!autorun && processAllFieldCodes();
if (!autorun) {
processAllFieldCodes();
}
const parameters: SqValue[] = [];

// Unpack all input values.
Expand All @@ -59,7 +61,9 @@ export const CalculatorResult: FC<Props> = ({

//runCalculator is updated every time that the inputResults or calculator changes, after which this will trigger.
useEffect(() => {
autorun && runCalculator();
if (autorun) {
runCalculator();
}
}, [runCalculator, autorun]);

// Back up calculatorResult to ViewerContext.
Expand Down
19 changes: 9 additions & 10 deletions packages/components/src/widgets/DistWidget/DistributionsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,15 @@ const InnerDistributionsChart: FC<{
}
}

{
showCursorLine &&
drawCursorLines({
frame,
cursor,
x: {
scale: xScale,
format: plot.xScale.tickFormat,
},
});
if (showCursorLine) {
drawCursorLines({
frame,
cursor,
x: {
scale: xScale,
format: plot.xScale.tickFormat,
},
});
}

if (verticalLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const Cell: FC<{
<RelativeValueCell item={item} showMedian={true} />
</CellBox>
);
} catch (e) {
} catch {
return <ErrorCell />;
}
};
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/widgets/TableChartWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ widgetRegistry.register("TableChart", {
if (event.key === "Enter" && item.ok) {
event.preventDefault();
const path = item.value.context?.path;
path && zoomedIn(path);
if (path) {
zoomedIn(path);
}
}
}}
className={clsx(
Expand Down
1 change: 1 addition & 0 deletions packages/components/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-require-imports */
import type { Config } from "tailwindcss";

export default {
Expand Down
19 changes: 19 additions & 0 deletions packages/content/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
rules: {
eqeqeq: "error",
"no-constant-condition": ["error", { checkLoops: false }],
// "multiline-comment-style": "warn",
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }],
"@typescript-eslint/no-empty-function": [
"error",
{ allow: ["constructors"] },
],
"@typescript-eslint/no-this-alias": "off",
// Maybe this should be "warn", but there are a few legitimate cases where typing is too hard,
// and zero-warning eslint output is nice to have.
"@typescript-eslint/no-explicit-any": "off",
},
};
6 changes: 4 additions & 2 deletions packages/content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"scripts": {
"dev": "content-collections watch",
"lint": "prettier --check .",
"lint": "pnpm lint:prettier && pnpm eslint",
"lint:prettier": "prettier --check .",
"eslint": "ESLINT_USE_FLAT_CONFIG=false NODE_NO_WARNINGS=1 eslint src",
"format": "prettier --write .",
"build": "content-collections build && tsc -b && cp -r .content-collections dist/"
},
Expand All @@ -28,7 +30,7 @@
"@quri/configs": "workspace:*",
"@quri/squiggle-textmate-grammar": "workspace:*",
"@types/mdx": "^2.0.13",
"eslint": "^8.57.0",
"eslint": "^9.16.0",
"prettier": "^3.3.3",
"tsx": "^4.11.0",
"typescript": "^5.6.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/content/src/collections/squiggleAiLibraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function fetchCodeFromHub(
}

return parsed.data.code;
} catch (e) {
} catch {
return await fetchCodeFromHubLegacy(owner, slug);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/content/src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function moduleItemToCompressedFormat({

function convertSquiggleEditorTags(input: string): string {
// Replace opening tags and everything up to the closing />
let result = input.replace(
const result = input.replace(
/<SquiggleEditor[\s\S]*?defaultCode=\{`([\s\S]*?)`\}\s*\/>/g,
(match, codeContent) => {
return "```squiggle\n" + codeContent.trim() + "\n```";
Expand Down
8 changes: 5 additions & 3 deletions packages/hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"build:ts": "pnpm gen && tsc",
"bundle": "pnpm build:esbuild && cp ../../node_modules/.pnpm/@prisma+client*/node_modules/.prisma/client/*.node ./dist",
"build": "pnpm gen && __NEXT_PRIVATE_PREBUNDLED_REACT=next next build",
"lint": "prettier --check . && next lint",
"lint": "pnpm lint:prettier && pnpm eslint",
"lint:prettier": "prettier --check .",
"eslint": "ESLINT_USE_FLAT_CONFIG=false NODE_NO_WARNINGS=1 eslint src",
"format": "prettier --write .",
"test:manual": "dotenv -e .env.test -- jest -i",
"build-last-revision": "pnpm build:esbuild && NODE_OPTIONS=--conditions=react-server node ./dist/scripts/buildRecentModelRevision/main.mjs"
Expand Down Expand Up @@ -68,8 +70,8 @@
"@types/react": "^18.3.3",
"dotenv-cli": "^7.4.2",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.3",
"eslint": "^9.16.0",
"eslint-config-next": "^15.0.4",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"nodemon": "^3.1.0",
Expand Down
Loading

0 comments on commit 7736492

Please sign in to comment.