Skip to content

AI-native design editor. Open-source Figma alternative.

Harden linting: add eqeqeq, prefer-const, radix, no-console, no-typeof-window-check

Danila Poyarkovc06ed32990e8
diff --git a/lint/plugin.js b/lint/plugin.js
index 1e62e2c4d..3a56867ed 100644
--- a/lint/plugin.js
+++ b/lint/plugin.js
@@ -214,6 +214,37 @@ const noSilentCatch = {
},
}
+const noTypeofWindowCheck = {
+ meta: {
+ docs: {
+ description:
+ 'Disallow raw typeof window checks — use IS_BROWSER or IS_TAURI from constants',
+ },
+ },
+ create(context) {
+ const file = context.filename ?? context.getFilename?.()
+ if (file?.endsWith('constants.ts') || file?.endsWith('fonts.ts')) return {}
+
+ return {
+ BinaryExpression(node) {
+ if (node.operator !== '!==' && node.operator !== '===') return
+ const isTypeofWindow = (side) =>
+ side.type === 'UnaryExpression' &&
+ side.operator === 'typeof' &&
+ side.argument?.type === 'Identifier' &&
+ side.argument.name === 'window'
+ if (isTypeofWindow(node.left) || isTypeofWindow(node.right)) {
+ context.report({
+ node,
+ message:
+ "Use IS_BROWSER or IS_TAURI from constants instead of raw 'typeof window' checks.",
+ })
+ }
+ },
+ }
+ },
+}
+
const plugin = {
meta: { name: 'open-pencil' },
rules: {
@@ -223,6 +254,7 @@ const plugin = {
'no-hand-rolled-color': noHandRolledColor,
'no-raw-console-format': noRawConsoleFormat,
'no-silent-catch': noSilentCatch,
+ 'no-typeof-window-check': noTypeofWindowCheck,
},
}
diff --git a/oxlint.json b/oxlint.json
index 8e86530c2..1bcb828c6 100644
--- a/oxlint.json
+++ b/oxlint.json
@@ -15,7 +15,11 @@
},
"rules": {
"no-unused-vars": "warn",
- "no-console": "off",
+ "no-console": ["warn", { "allow": ["warn", "error", "debug", "time", "timeEnd"] }],
+ "eqeqeq": ["error", "always", { "null": "ignore" }],
+ "prefer-const": "error",
+ "radix": "error",
+
"no-restricted-imports": [
"error",
{
@@ -113,7 +117,8 @@
"open-pencil/no-math-random": "error",
"open-pencil/no-hand-rolled-color": "error",
"open-pencil/no-raw-console-format": "off",
- "open-pencil/no-silent-catch": "error"
+ "open-pencil/no-silent-catch": "error",
+ "open-pencil/no-typeof-window-check": "warn"
},
"overrides": [
{
@@ -135,6 +140,14 @@
"typescript/no-explicit-any": "off"
}
},
+ {
+ "files": [
+ "**/figma-api.ts"
+ ],
+ "rules": {
+ "no-console": "off"
+ }
+ },
{
"files": [
"**/render/render-jsx.ts"
@@ -156,7 +169,10 @@
"typescript/consistent-type-imports": "off",
"typescript/no-unnecessary-condition": "off",
"import/no-mutable-exports": "off",
- "complexity": "off"
+ "complexity": "off",
+ "prefer-const": "off",
+ "eqeqeq": "off",
+ "radix": "off"
}
},
{
@@ -169,6 +185,15 @@
"max-lines": "off"
}
},
+ {
+ "files": [
+ "packages/cli/src/**",
+ "packages/mcp/src/**"
+ ],
+ "rules": {
+ "no-console": "off"
+ }
+ },
{
"files": [
"packages/cli/src/commands/**"
diff --git a/packages/core/src/kiwi/codec.ts b/packages/core/src/kiwi/codec.ts
index 991c9b5c4..11af85855 100644
--- a/packages/core/src/kiwi/codec.ts
+++ b/packages/core/src/kiwi/codec.ts
@@ -584,7 +584,7 @@ function injectVariableBinding(
// Find visible=true pattern (04 01) after the marker
const visiblePattern = '0401'
- let patternIdx = hex.indexOf(visiblePattern, markerIdx)
+ const patternIdx = hex.indexOf(visiblePattern, markerIdx)
if (patternIdx === -1) return hex
// Move past 0401 to find where to insert
diff --git a/packages/core/src/renderer/renderer.ts b/packages/core/src/renderer/renderer.ts
index f7861f1f1..01429223e 100644
--- a/packages/core/src/renderer/renderer.ts
+++ b/packages/core/src/renderer/renderer.ts
@@ -529,7 +529,7 @@ export class SkiaRenderer {
const pillH = SECTION_TITLE_HEIGHT / this.zoom
const gap = SECTION_TITLE_GAP / this.zoom
- let pillX = ax
+ const pillX = ax
let pillY: number
if (insideSection) {
pillY = ay + gap
diff --git a/src/components/LayerTree.vue b/src/components/LayerTree.vue
index 88c6cf30f..96cb64933 100644
--- a/src/components/LayerTree.vue
+++ b/src/components/LayerTree.vue
@@ -217,7 +217,7 @@ function resolveInsertPosition(
if (!parent) return null
const idx = parent.childIds.indexOf(rowId)
- const level = parseInt(row.dataset.level ?? '0')
+ const level = parseInt(row.dataset.level ?? '0', 10)
if (edge === 'before') {
return {
diff --git a/src/composables/use-canvas-input.ts b/src/composables/use-canvas-input.ts
index 11b0d7d47..ec0e4f745 100644
--- a/src/composables/use-canvas-input.ts
+++ b/src/composables/use-canvas-input.ts
@@ -1015,7 +1015,7 @@ export function useCanvasInput(
cursorOverride.value = null
}
- let wheelAccum = {
+ const wheelAccum = {
deltaX: 0,
deltaY: 0,
zoomDelta: 0,