Skip to content

Commit

Permalink
Fix lints & improve actions (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-dr authored Nov 2, 2024
2 parents f6b81aa + d53f005 commit 9e0cbbf
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 33 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,20 @@ jobs:

- name: Run prettier
working-directory: ./copperc
run: npx prettier --check .
run: npm run prettier

eslint:
runs-on: ubuntu-latest
container: node:18.20.4

steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Install dependencies
working-directory: ./copperc
run: npm ci

- name: Run eslint
working-directory: ./copperc
run: npm run lint
5 changes: 4 additions & 1 deletion copperc/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"extends": ["next/core-web-vitals", "next/typescript"],
"rules": {
"no-mixed-spaces-and-tabs": "off"
"no-mixed-spaces-and-tabs": "off",
"no-restricted-syntax": ["error", "WithStatement"],
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-empty-function": "error"
}
}
3 changes: 2 additions & 1 deletion copperc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"openapi": "openapi-typescript",
"prettier": "prettier --check .",
"openapi": "openapi-typescript; prettier --write src/lib/api/openapi.ts",
"depcheck": "npm-check --no-emoji"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions copperc/src/app/u/_topbar/topbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ function useUpdateModal(params: { onSuccess: () => void }) {
});

return {
open: (userInfo: components["schemas"]["UserInfo"]) => {
setUserInfo(userInfo);
open: (new_userInfo: components["schemas"]["UserInfo"]) => {
setUserInfo(new_userInfo);
form.setValues({
email: userInfo.email,
name: userInfo.name,
email: new_userInfo.email,
name: new_userInfo.name,
password: null,
password_again: null,
});
Expand Down
12 changes: 6 additions & 6 deletions copperc/src/app/u/pipeline/flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ export function useFlow(params: { disabled: boolean; onModify: () => void }) {

const isValidConnection: IsValidConnection = useCallback(
(connection) => {
const nodes = getNodes();
const edges = getEdges();
const c_nodes = getNodes();
const c_edges = getEdges();

// Get source node details
const source = nodes.find((node) => node.id === connection.source);
const source = c_nodes.find((node) => node.id === connection.source);
if (source === undefined) return false;
const sourcedef = nodeDefinitions[source.type!];
if (sourcedef === undefined) return false;
Expand All @@ -108,7 +108,7 @@ export function useFlow(params: { disabled: boolean; onModify: () => void }) {
if (sourceoutput === undefined) return false;

// Get target node details
const target = nodes.find((node) => node.id === connection.target);
const target = c_nodes.find((node) => node.id === connection.target);
if (target === undefined) return false;
const targetdef = nodeDefinitions[target.type!];
if (targetdef === undefined) return false;
Expand All @@ -123,7 +123,7 @@ export function useFlow(params: { disabled: boolean; onModify: () => void }) {
}

// Make sure target handle is not already connected
const incoming_edges = edges.filter((x) => x.target === target.id);
const incoming_edges = c_edges.filter((x) => x.target === target.id);
const repeat_input = incoming_edges.reduce(
(prev, edge) => prev || edge.targetHandle === targetinput.id,
false,
Expand All @@ -135,7 +135,7 @@ export function useFlow(params: { disabled: boolean; onModify: () => void }) {
if (visited.has(node.id)) return true;
visited.add(node.id);

for (const out of getOutgoers(node, nodes, edges)) {
for (const out of getOutgoers(node, c_nodes, c_edges)) {
if (out.id === source.id) return true;
if (hasCycle(out, visited)) return true;
}
Expand Down
44 changes: 30 additions & 14 deletions copperc/src/app/u/pipeline/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ function Main() {

const setPipeline = useCallback(
async (
pipeline: components["schemas"]["PipelineInfo"] | null,
new_pipeline: components["schemas"]["PipelineInfo"] | null,
fit?: boolean,
) => {
setReloading(true);
if (pipeline === null) {
if (new_pipeline === null) {
setNodes([]);
setEdges([]);
} else {
const de = await deserializePipeline(pipeline.data);
const de = await deserializePipeline(new_pipeline.data);
setNodes(de.nodes);
setEdges(de.edges);
}

_setPipeline(pipeline);
_setPipeline(new_pipeline);

// Hack that makes sure `fitView` is called _after_ nodes are updated.
// This also gives us a minimum of 500ms while reloading time
Expand Down Expand Up @@ -142,10 +142,10 @@ function Main() {
return;
}

const pipeline =
const new_pipeline =
pipelines.data?.find((x) => x.id === int) || null;

setPipeline(pipeline);
setPipeline(new_pipeline);
}}
/>

Expand Down Expand Up @@ -246,7 +246,9 @@ function Main() {
text="Input"
node_type="pipelineinput"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand All @@ -257,7 +259,9 @@ function Main() {
text="Constant"
node_type="constant"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand All @@ -268,7 +272,9 @@ function Main() {
text="IfNone"
node_type="ifnone"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand All @@ -279,7 +285,9 @@ function Main() {
text="Checksum"
node_type="hash"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand All @@ -293,7 +301,9 @@ function Main() {
text="Add item"
node_type="additem"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand All @@ -307,7 +317,9 @@ function Main() {
text="Strip tags"
node_type="striptags"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand All @@ -317,7 +329,9 @@ function Main() {
text="Extract tags"
node_type="extracttags"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand All @@ -327,7 +341,9 @@ function Main() {
text="Extract covers"
node_type="extractcovers"
setNodes={setNodes}
onInfo={() => {}}
onInfo={() => {
console.log("todo");
}}
onModify={() => {
setModified(true);
}}
Expand Down
2 changes: 1 addition & 1 deletion copperc/src/app/u/pipeline/serde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export async function deserializePipeline(
const v = x[1];

const nodedef = Object.entries(nodeDefinitions).find(
(x) => x[1].copper_node_type === v.node_type,
(y) => y[1].copper_node_type === v.node_type,
);
if (nodedef === undefined) {
console.error(`Unknown node type ${v.node_type}`);
Expand Down
2 changes: 1 addition & 1 deletion copperc/src/app/u/upload/controlpanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function ControlPanel(params: {
// exactly one `Blob` input.
let disabled = false;
const inputs = Object.entries(x.data.nodes).filter(
(x) => x[1].node_type === "Input",
(y) => y[1].node_type === "Input",
);
if (inputs.length !== 1) {
disabled = true;
Expand Down
6 changes: 5 additions & 1 deletion copperc/src/components/navblock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { useRouter } from "next/navigation";

const NavigationBlockerContext = createContext<
[isBlocked: boolean, setBlocked: Dispatch<SetStateAction<boolean>>]
>([false, () => {}]);
>([
false,
// eslint-disable-next-line @typescript-eslint/no-empty-function
() => {},
]);

export function NavigationBlockerProvider({
children,
Expand Down
6 changes: 3 additions & 3 deletions copperc/src/components/tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ export function useTree<D>(params: { defaultOpen?: boolean }) {
/>
);

const setTreeData = useCallback((data: TreeNode<D>[]) => {
const setTreeData = useCallback((new_data: TreeNode<D>[]) => {
// Note that we don't de-select anything when data
// changes. This is intentional.
setOpened((o) => {
// Auto-close nodes that were removed from the tree
const s = new Set(o);
for (const i in s.keys) {
if (!data.some((x) => x.uid === i)) {
if (!new_data.some((x) => x.uid === i)) {
s.delete(i);
}
}
return s;
});
setData(data);
setData(new_data);
}, []);

return { node, data, setTreeData, selected };
Expand Down

0 comments on commit 9e0cbbf

Please sign in to comment.