Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-krakowski committed Jun 8, 2021
1 parent 4e41e06 commit 0e25f0d
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 86 deletions.
31 changes: 31 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"ignorePatterns": ["node_modules", "out", "outdir", "dist", "storybook-static"],
"extends": ["xo", "plugin:prettier/recommended", "plugin:import/errors", "plugin:import/warnings"],
"plugins": ["import", "unicorn"],
"overrides": [
{
"files": ["**/*.ts"],
"extends": ["plugin:@typescript-eslint/recommended","plugin:import/typescript"],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/consistent-type-imports": "error"
}
}
],
"rules": {
"max-params": ["off"],
"complexity": ["off"],
"react/jsx-boolean-value": ["error", "always"],
"prefer-destructuring": [
"error",
{
"object": true
}
],
"guard-for-in": ["off"]
}
}
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tonik-figma-plugins",
"private": true,
"workspaces": [
"packages/*",
"packages/*"
],
"scripts": {
"bootstrap": "lerna bootstrap",
Expand All @@ -13,19 +13,21 @@
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@figma/plugin-typings": "^1.23.0",
"@typescript-eslint/eslint-plugin": "^4.24.0",
"@typescript-eslint/parser": "^4.24.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-xo": "^0.36.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.23.2",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-unicorn": "^32.0.1",
"husky": "^6.0.0",
"lerna": "^4.0.0",
"prettier": "^2.3.0",
"typescript": "^4.2.4",
"@figma/plugin-typings": "^1.23.0"
"typescript": "^4.2.4"
},
"husky": {
"hooks": {
Expand Down
89 changes: 61 additions & 28 deletions packages/p1/code.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
const __awaiter =
(this && this.__awaiter) ||
function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function (resolve) {
resolve(value)
})
}

return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
function fulfilled(value) {
try {
step(generator.next(value))
} catch (e) {
reject(e)
}
}

function rejected(value) {
try {
step(generator.throw(value))
} catch (e) {
reject(e)
}
}

function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
}

step((generator = generator.apply(thisArg, _arguments || [])).next())
})
}

function traverse(node) {
return __awaiter(this, void 0, void 0, function* () {
if ("children" in node) {
if (node.type !== "INSTANCE") {
for (const child of node.children) {
traverse(child);
}
}
else if (node.name === '_Specification') {
const spaceComp = node.children.find(element => /^(size|space)\/(width|height)/.test(element.name));
const textNode = node.children.find(element => element.type === "TEXT");
const valueToDisplay = /^(size|space)\/(width)/.test(spaceComp.name) ? spaceComp === null || spaceComp === void 0 ? void 0 : spaceComp.width : spaceComp === null || spaceComp === void 0 ? void 0 : spaceComp.height;
const textToDisplay = String(`${valueToDisplay}px`);
let len = textNode.characters.length;
yield figma.loadFontAsync(textNode.getRangeFontName(0, 1));
textNode.deleteCharacters(0, len);
textNode.insertCharacters(0, textToDisplay);
}
return __awaiter(this, void 0, void 0, function* () {
if ('children' in node) {
if (node.type !== 'INSTANCE') {
for (const child of node.children) {
traverse(child)
}
});
} else if (node.name === '_Specification') {
const spaceComp = node.children.find((element) => /^(size|space)\/(width|height)/.test(element.name))
const textNode = node.children.find((element) => element.type === 'TEXT')
const valueToDisplay = /^(size|space)\/(width)/.test(spaceComp.name)
? spaceComp === null || spaceComp === void 0
? void 0
: spaceComp.width
: spaceComp === null || spaceComp === void 0
? void 0
: spaceComp.height
const textToDisplay = String(`${valueToDisplay}px`)
const len = textNode.characters.length
yield figma.loadFontAsync(textNode.getRangeFontName(0, 1))
textNode.deleteCharacters(0, len)
textNode.insertCharacters(0, textToDisplay)
}
}
})
}
traverse(figma.root);
figma.closePlugin();

traverse(figma.root)
figma.closePlugin()
10 changes: 5 additions & 5 deletions packages/p1/code.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
async function traverse(node) {
if ("children" in node) {
if (node.type !== "INSTANCE") {
if ('children' in node) {
if (node.type !== 'INSTANCE') {
for (const child of node.children) {
traverse(child)
}
} else if (node.name === '_Specification') {
const spaceComp = node.children.find(element => /^(size|space)\/(width|height)/.test(element.name))
const textNode = node.children.find(element => element.type === "TEXT")
const spaceComp = node.children.find((element) => /^(size|space)\/(width|height)/.test(element.name))
const textNode = node.children.find((element) => element.type === 'TEXT')
const valueToDisplay = /^(size|space)\/(width)/.test(spaceComp.name) ? spaceComp?.width : spaceComp?.height
const textToDisplay = String(`${valueToDisplay}px`)

let len = textNode.characters.length
const len = textNode.characters.length
await figma.loadFontAsync(textNode.getRangeFontName(0, 1))

textNode.deleteCharacters(0, len)
Expand Down
89 changes: 61 additions & 28 deletions packages/p2/code.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
const __awaiter =
(this && this.__awaiter) ||
function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function (resolve) {
resolve(value)
})
}

return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
function fulfilled(value) {
try {
step(generator.next(value))
} catch (e) {
reject(e)
}
}

function rejected(value) {
try {
step(generator.throw(value))
} catch (e) {
reject(e)
}
}

function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
}

step((generator = generator.apply(thisArg, _arguments || [])).next())
})
}

function traverse(node) {
return __awaiter(this, void 0, void 0, function* () {
if ("children" in node) {
if (node.type !== "INSTANCE") {
for (const child of node.children) {
traverse(child);
}
}
else if (node.name === '_Specification') {
const spaceComp = node.children.find(element => /^(size|space)\/(width|height)/.test(element.name));
const textNode = node.children.find(element => element.type === "TEXT");
const valueToDisplay = /^(size|space)\/(width)/.test(spaceComp.name) ? spaceComp === null || spaceComp === void 0 ? void 0 : spaceComp.width : spaceComp === null || spaceComp === void 0 ? void 0 : spaceComp.height;
const textToDisplay = String(`${valueToDisplay}px`);
let len = textNode.characters.length;
yield figma.loadFontAsync(textNode.getRangeFontName(0, 1));
textNode.deleteCharacters(0, len);
textNode.insertCharacters(0, textToDisplay);
}
return __awaiter(this, void 0, void 0, function* () {
if ('children' in node) {
if (node.type !== 'INSTANCE') {
for (const child of node.children) {
traverse(child)
}
});
} else if (node.name === '_Specification') {
const spaceComp = node.children.find((element) => /^(size|space)\/(width|height)/.test(element.name))
const textNode = node.children.find((element) => element.type === 'TEXT')
const valueToDisplay = /^(size|space)\/(width)/.test(spaceComp.name)
? spaceComp === null || spaceComp === void 0
? void 0
: spaceComp.width
: spaceComp === null || spaceComp === void 0
? void 0
: spaceComp.height
const textToDisplay = String(`${valueToDisplay}px`)
const len = textNode.characters.length
yield figma.loadFontAsync(textNode.getRangeFontName(0, 1))
textNode.deleteCharacters(0, len)
textNode.insertCharacters(0, textToDisplay)
}
}
})
}
traverse(figma.root);
figma.closePlugin();

traverse(figma.root)
figma.closePlugin()
26 changes: 13 additions & 13 deletions packages/p2/code.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
const ColorLuminance = (hex: string, lums: Array<number>) => {
if (/[^0-9a-f]/gi.test(hex)) {
throw new Error ('Invalid color')
if (/[^0-9a-f]/gi.test(hex)) {
throw new Error('Invalid color')
}

const colors = []

if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
if (hex.length < 6) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
}

for (const lum of lums) {
let color = "#"
let color = '#'

for (let i = 0; i < 3; i++) {
let cNumber = parseInt(hex.substr(i*2,2), 16);
const colorParh = Math.round(Math.min(Math.max(0, cNumber + (cNumber * lum)), 255)).toString(16);
color += ('00'+colorParh).substr(colorParh.length);
const cNumber = parseInt(hex.substr(i * 2, 2), 16)
const colorParh = Math.round(Math.min(Math.max(0, cNumber + cNumber * lum), 255)).toString(16)
color += ('00' + colorParh).substr(colorParh.length)
}

colors.push(color)
}

return colors;
return colors
}

// console.log(ColorLuminance("6699C", [0, 1, 2]))

// Console.log(ColorLuminance("6699C", [0, 1, 2]))

figma.closePlugin()
Loading

0 comments on commit 0e25f0d

Please sign in to comment.