Skip to content

Commit

Permalink
Lint fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernaferrari committed Mar 1, 2023
1 parent f67e5cf commit 8bf5ef6
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const config = {
complexity: "off",
"default-case": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "warn",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-unnecessary-condition": "off",
"space-before-function-paren": [
"error",
Expand Down
15 changes: 7 additions & 8 deletions src/flutter/flutterMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
AltRectangleNode,
AltGroupNode,
AltTextNode,
AltSceneNode } from "../altNodes/altMixins";
AltSceneNode,
} from "../altNodes/altMixins";
import { numToAutoFixed } from "../common/numToAutoFixed";
import { retrieveTopFill } from "../common/retrieveFill";
import { FlutterDefaultBuilder } from "./flutterDefaultBuilder";
Expand Down Expand Up @@ -163,7 +164,7 @@ const makeRowColumn = (node: AltFrameNode, children: string): string => {
}
const crossAxisAlignment = `\ncrossAxisAlignment: CrossAxisAlignment.${crossAlignType},`;

let mainAlignType;
let mainAlignType = "";
switch (node.primaryAxisAlignItems) {
case "MIN":
mainAlignType = "start";
Expand All @@ -180,18 +181,16 @@ const makeRowColumn = (node: AltFrameNode, children: string): string => {
}
const mainAxisAlignment = `\nmainAxisAlignment: MainAxisAlignment.${mainAlignType},`;

let mainAxisSize;
let mainAxisSize = "";
if (node.layoutGrow === 1) {
mainAxisSize = "\nmainAxisSize: MainAxisSize.max,";
} else {
mainAxisSize = "\nmainAxisSize: MainAxisSize.min,";
}

const properties =
`${mainAxisSize +
mainAxisAlignment +
crossAxisAlignment
}\nchildren:[\n${indentString(children, 1)}\n],`;
const properties = `${
mainAxisSize + mainAxisAlignment + crossAxisAlignment
}\nchildren:[\n${indentString(children, 1)}\n],`;

return `${rowOrColumn}(${indentString(properties, 1)}\n),`;
};
Expand Down
2 changes: 1 addition & 1 deletion src/html/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export const rowColumnProps = (node: AltFrameNode, isJsx: boolean): string => {

// [optimization]
// when all children are STRETCH and layout is Vertical, align won't matter. Otherwise, center it.
let counterAlign: string;
let counterAlign: string = "";
switch (node.counterAxisAlignItems) {
case "MIN":
counterAlign = "flex-start";
Expand Down
6 changes: 3 additions & 3 deletions src/html/htmlTextBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { htmlTextSize as htmlTextSizeBox } from "./builderImpl/htmlTextSize";
import { numToAutoFixed } from "./../common/numToAutoFixed";

export class HtmlTextBuilder extends HtmlDefaultBuilder {
constructor(node: AltTextNode, showLayerName: boolean, optIsJSX: boolean) {
super(node, showLayerName, optIsJSX);
}
// constructor(node: AltTextNode, showLayerName: boolean, optIsJSX: boolean) {
// super(node, showLayerName, optIsJSX);
// }

// must be called before Position method
textAutoSize(node: AltTextNode): this {
Expand Down
28 changes: 15 additions & 13 deletions src/nearest-color/nearestColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ function nearestColor(needle: RGB | string, colors: Array<ColorSpec>): string {
needle = parseColor(needle);

let distanceSq;
let minDistanceSq = Infinity,
rgb,
value: ColorSpec;
let minDistanceSq = Infinity;
// eslint-disable-next-line one-var
let rgb;
// eslint-disable-next-line one-var
let value: ColorSpec;

for (let i = 0; i < colors.length; ++i) {
rgb = colors[i].rgb;

distanceSq =
(needle.r - rgb.r)**2 +
(needle.g - rgb.g)**2 +
(needle.b - rgb.b)**2;
(needle.r - rgb.r) ** 2 +
(needle.g - rgb.g) ** 2 +
(needle.b - rgb.b) ** 2;

if (distanceSq < minDistanceSq) {
minDistanceSq = distanceSq;
Expand Down Expand Up @@ -202,7 +204,7 @@ function parseColor(source: RGB | string): RGB {
return { r: red, g: green, b: blue };
}

throw Error(`"${ source }" is not a valid color`);
throw Error(`"${source}" is not a valid color`);
}

type RGB = {
Expand All @@ -211,12 +213,12 @@ type RGB = {
b: number;
};

type ColorMatch = {
name: string;
value: string;
rgb: RGB;
distance: number;
};
// type ColorMatch = {
// name: string;
// value: string;
// rgb: RGB;
// distance: number;
// };

type ColorSpec = {
source: string;
Expand Down
4 changes: 2 additions & 2 deletions src/swiftui/builderImpl/swiftuiEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const swiftuiShadow = (node: AltSceneNode): string => {
return "";
}

const dropShadow: Array<ShadowEffect> = node.effects.filter(
(d): d is ShadowEffect => d.type === "DROP_SHADOW" && d.visible
const dropShadow: Array<DropShadowEffect> = node.effects.filter(
(d): d is DropShadowEffect => d.type === "DROP_SHADOW" && d.visible
);

if (dropShadow.length === 0) {
Expand Down
12 changes: 9 additions & 3 deletions src/tailwind/builderImpl/tailwindBorder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AltSceneNode , AltGeometryMixin } from "../../altNodes/altMixins";
import { AltSceneNode, AltGeometryMixin } from "../../altNodes/altMixins";
import { nearestValue, pxToBorderRadius } from "../conversionTables";

/**
Expand Down Expand Up @@ -31,8 +31,10 @@ export const tailwindBorderRadius = (node: AltSceneNode): string => {
return "rounded-full ";
} else if (
(!("cornerRadius" in node) && !("topLeftRadius" in node)) ||
(node.cornerRadius === figma.mixed && node.topLeftRadius === undefined) ||
node.cornerRadius === 0
("cornerRadius" in node &&
node.cornerRadius === figma.mixed &&
node.topLeftRadius === undefined) ||
("cornerRadius" in node && node.cornerRadius === 0)
) {
// the second condition is used on tests. On Figma, topLeftRadius is never undefined.
// ignore when 0, undefined or non existent
Expand All @@ -41,6 +43,10 @@ export const tailwindBorderRadius = (node: AltSceneNode): string => {

let comp = "";

if (!("cornerRadius" in node)) {
return "";
}

if (node.cornerRadius !== figma.mixed) {
if (node.cornerRadius >= node.height / 2) {
// special case. If height is 90 and cornerRadius is 45, it is full.
Expand Down
2 changes: 1 addition & 1 deletion src/tailwind/tailwindMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const rowColumnProps = (node: AltFrameNode): string => {

// [optimization]
// when all children are STRETCH and layout is Vertical, align won't matter. Otherwise, center it.
let counterAlign: string;
let counterAlign: string = "";
switch (node.counterAxisAlignItems) {
case "MIN":
counterAlign = "items-start ";
Expand Down
1 change: 1 addition & 0 deletions src/tailwind/vector.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { AltFrameNode, AltGroupNode } from "../altNodes/altMixins";
// import { TailwindDefaultBuilder } from "./tailwindDefaultBuilder";

Expand Down

0 comments on commit 8bf5ef6

Please sign in to comment.