Skip to content

Commit a176a55

Browse files
authored
Make figma project stricter (#8461)
This tidies up some dead code and turns on a more stricter tsconfig to automate keeping the project this way.
1 parent 6d8ea50 commit a176a55

File tree

9 files changed

+1175
-803
lines changed

9 files changed

+1175
-803
lines changed

tools/figma-inspector/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ As of writing Figma has real test support. Testing is limited to unit testing so
6464
You can find the test files under `/tests`. This folder also includes the JSON export of a real Figma file
6565
to test against. The easiest way to update the file is to to edit it in Figma and then use a personal access token to get a JSON version.
6666

67-
To get an access Token in Figma go to the home screen. Then top right click the loggedin user name. Then `Settings` and then the `Security` tab. Scroll to the bottom and choose `Generate new token`. Then save the token in a secure private place.
67+
To get an access Token in Figma go to the home screen. Then top right click the logged in user name. Then `Settings` and then the `Security` tab. Scroll to the bottom and choose `Generate new token`. Then save the token in a secure private place.
6868

6969
You then need to get the file ID. Open figma.com, login and open the file. You will then have a url like
7070
`https://www.figma.com/design/njC6jSUbrYpqLRJ2dyV6NT/energy-test-file?node-id=113-2294&p=f&t=5IDwrGIFUnri3Z17-0`. The ID is the part of the URL after `/design/` so in this example `njC6jSUbrYpqLRJ2dyV6NT`.
@@ -77,7 +77,7 @@ curl -H 'X-Figma-Token: <YOUR_ACCESS_TOKEN>' \
7777
-o figma_output.json
7878
```
7979

80-
Vitest can then be run in hot reload mode for ease of test developmet with:
80+
Vitest can then be run in hot reload mode for ease of test development with:
8181

8282
```sh
8383
pnpm test

tools/figma-inspector/backend/code.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,12 @@ listenTS("generateSnippetRequest", async (payload) => {
5555
if (selection.length === 1) {
5656
const node = selection[0];
5757
title = node.name;
58-
try {
59-
// --- Pass the useVariables value received from UI ---
60-
slintSnippet = await generateSlintSnippet(node, useVariables);
6158

62-
if (slintSnippet === null) {
63-
slintSnippet = `// Unsupported node type: ${node.type}`;
64-
}
65-
} catch (error) {
66-
console.error(
67-
`[Backend] Error generating snippet for ${node.name}:`,
68-
error,
69-
);
70-
slintSnippet = `// Error generating snippet for ${node.name}:\n// ${error instanceof Error ? error.message : String(error)}`;
59+
// --- Pass the useVariables value received from UI ---
60+
slintSnippet = await generateSlintSnippet(node, useVariables);
61+
62+
if (slintSnippet === null) {
63+
slintSnippet = `// Unsupported node type: ${node.type}`;
7164
}
7265
} else if (selection.length > 1) {
7366
slintSnippet = "// Select a single component to inspect";
@@ -127,9 +120,6 @@ const variableMonitoring: {
127120
lastEventTime: 0,
128121
};
129122

130-
// Keep the DEBOUNCE_INTERVAL as a constant
131-
const DEBOUNCE_INTERVAL = 3000; // 3 seconds
132-
133123
listenTS("monitorVariableChanges", () => {
134124
figma.ui.postMessage({
135125
type: "variableMonitoringActive", // Keep this confirmation

tools/figma-inspector/backend/utils/code-utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright © SixtyFPS GmbH <info@slint.dev>
22
// SPDX-License-Identifier: MIT
33

4-
import type { Message, PluginMessageEvent } from "../../src/globals";
54
import type { EventTS } from "../../shared/universals";
6-
import { generateSlintSnippet } from "./property-parsing.js";
75

86
export function dispatch(data: any, origin = "*") {
97
figma.ui.postMessage(data, {

tools/figma-inspector/backend/utils/export-variables.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ function createReferenceExpression(
216216

217217
// Loop Detection
218218
const targetIdentifier = `${targetCollection}.${targetPath.join(".")}`;
219-
const currentIdentifier = `${currentCollection}.${currentPath.join(".")}`;
220219

221220
if (resolutionStack.includes(targetIdentifier)) {
222221
const loopPath = `${resolutionStack.join(" -> ")} -> ${targetIdentifier}`;
@@ -558,7 +557,7 @@ interface PropertyInstance {
558557

559558
function generateStructsAndInstances(
560559
variableTree: VariableNode,
561-
collectionName: string,
560+
_collectionName: string,
562561
collectionData: CollectionData, // using strict type interface
563562
): {
564563
structs: string;
@@ -581,8 +580,6 @@ function generateStructsAndInstances(
581580
if (node.name === "root") {
582581
// Process all root children
583582
for (const [childName, childNode] of node.children.entries()) {
584-
const sanitizedChildName = sanitizePropertyName(childName);
585-
586583
// Always process child nodes with proper path propagation
587584
buildStructModel(childNode, [childName]); // Keep this single-element path for first level
588585
}
@@ -916,10 +913,6 @@ function generateStructsAndInstances(
916913
result += `${indent}// NOTE: This property was renamed from "mode" to "mode-var" to avoid collision\n`;
917914
result += `${indent}// with the scheme mode property of the same name.\n`;
918915
}
919-
// Root level property
920-
const slintType = instance.isMultiMode
921-
? `${collectionData.formattedName}_mode${collectionData.modes.size}_${instance.type}`
922-
: instance.type;
923916

924917
if (instance.children && instance.children.size > 0) {
925918
// Struct instance
@@ -1118,9 +1111,6 @@ export async function exportFigmaVariablesToSeparateFiles(
11181111
const variableCollections =
11191112
await figma.variables.getLocalVariableCollectionsAsync();
11201113

1121-
// Array to store all exported files
1122-
const exportedFiles: Array<{ name: string; content: string }> = [];
1123-
11241114
// First, initialize the collection structure for ALL collections
11251115
const collectionStructure = new Map<string, CollectionData>();
11261116

@@ -1450,7 +1440,7 @@ export async function exportFigmaVariablesToSeparateFiles(
14501440

14511441
// Generate content for each collection
14521442
for (const [
1453-
collectionName,
1443+
_collectionName,
14541444
collectionData,
14551445
] of collectionStructure.entries()) {
14561446
// Skip collections with no variables
@@ -1613,7 +1603,7 @@ export async function exportFigmaVariablesToSeparateFiles(
16131603
// Replace unresolved references with appropriate defaults based on context
16141604
file.content = file.content.replace(
16151605
/(@ref:VariableID:[0-9:]+)/g,
1616-
(match, reference) => {
1606+
(_match, reference) => {
16171607
exportInfo.warnings.add(
16181608
` Replacing unresolved reference: ${reference}`,
16191609
);
@@ -1705,12 +1695,6 @@ interface SchemeStruct {
17051695
path: string[];
17061696
}
17071697

1708-
interface ModeValue {
1709-
value: string;
1710-
refId?: string;
1711-
comment?: string;
1712-
}
1713-
17141698
// Main function for generating scheme structs
17151699
function generateSchemeStructs(
17161700
variableTree: VariableNode,
@@ -1960,7 +1944,7 @@ function collectMultiModeStructs(
19601944

19611945
// Still scan the tree for any other types we might have missed (for future proofing)
19621946
function findUniqueTypeConfigs(node: VariableNode) {
1963-
for (const [childName, childNode] of node.children.entries()) {
1947+
for (const [_childName, childNode] of node.children.entries()) {
19641948
if (childNode.valuesByMode && childNode.valuesByMode.size > 0) {
19651949
const slintType = getSlintType(childNode.type || "COLOR");
19661950
// Skip if we already added this type

tools/figma-inspector/backend/utils/property-parsing.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ export async function generateSlintSnippet(
376376
useVariables: boolean,
377377
): Promise<string> {
378378
const nodeType = sceneNode.type;
379-
const nodeId = sanitizePropertyName(sceneNode.name);
380379

381380
switch (nodeType) {
382381
case "FRAME":

tools/figma-inspector/src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright © SixtyFPS GmbH <info@slint.dev>
22
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

4-
import { useEffect, useState, useRef } from "react";
4+
import { useEffect, useState } from "react";
55
import { getColorTheme, subscribeColorTheme } from "./utils/bolt-utils";
66
import CodeSnippet from "./components/snippet/CodeSnippet";
77
import { ExportType, useInspectorStore } from "./utils/store";
@@ -22,7 +22,7 @@ export const App = () => {
2222
exportFiles,
2323
} = useInspectorStore();
2424

25-
const [lightOrDarkMode, setLightOrDarkMode] = useState(getColorTheme());
25+
const [_lightOrDarkMode, setLightOrDarkMode] = useState(getColorTheme());
2626

2727
// Init
2828
useEffect(() => {

0 commit comments

Comments
 (0)