Skip to content

Instantly share code, notes, and snippets.

Alex Lockwood alexjlockwood

Block or report user

Report or block alexjlockwood

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
alexjlockwood / print-unlinked-colors.ts
Created Feb 3, 2020
Prints nodes that have fill/stroke colors that aren't linked to a style.
View print-unlinked-colors.ts
.flatMap(pageNode => pageNode.findAll(n => true))
.forEach(node => {
if ('fills' in node && 'fillStyleId' in node) {
if (node.fills !== figma.mixed && node.fills.length > 0 && node.fillStyleId !== '') {
print(`${}'s fill color is not linked to a style`);
if ('strokes' in node && 'strokeStyleId' in node) {
if (node.strokes.length > 0 && node.strokeStyleId !== '') {
alexjlockwood / delete-unused-component.ts
Last active Feb 3, 2020
Deletes the selected component if it is private and unused in the file.
View delete-unused-component.ts
if (figma.currentPage.selection.length !== 1) {
figma.notify("🚫 Select a component");
const [componentNode] = figma.currentPage.selection;
if (componentNode.type !== "COMPONENT") {
figma.notify("🚫 Select a component");
alexjlockwood / flatten-icons.ts
Last active Feb 3, 2020
Flattens all components in a Figma file. Note that this script assumes that (1) every component in the file is an icon, (2) each icon contains a single color, and (3) the icons don't use masks. The `figma.flatten` function may not work as you expect if one of these conditions aren't met.
View flatten-icons.ts
// Create a list of all component nodes in the Figma file.
const componentNodes = figma.root.children.flatMap(pageNode => {
return pageNode.findAll(node => node.type === 'COMPONENT');
}) as readonly ComponentNode[];
// Create a list of component nodes that have more than one child node.
const unflattenedComponentNodes = componentNodes.filter(componentNode => {
const childrenNodes = componentNode.findAll(() => true);
return childrenNodes.length > 1;
alexjlockwood / cleanup-figma-names.ts
Last active Feb 2, 2020
Cleans up Figma component and style names
View cleanup-figma-names.ts
const components = figma.root.children.flatMap(pageNode => {
return pageNode.findAll(node => node.type === 'COMPONENT');
const styles = [
alexjlockwood / generate-style-descriptions.ts
Last active Feb 4, 2020
Generates style descriptions for each color style in the current Figma file.
View generate-style-descriptions.ts
// Get the list of color styles in the current Figma file.
const colorStyles = figma.getLocalPaintStyles();
const updatedColorStyles = colorStyles.filter(style => {
const { paints } = style;
if (paints.length !== 1) {
// Skip styles containing multiple colors.
return false;
const [paint] = paints;
View scripter.ts
// The Scripter environment.
// What's declared in there is available to scripts in their global namespace.
// symbolic type aliases
type int = number
type float = number
type byte = number
alexjlockwood / TypedArrayUtils.kt
Created Aug 13, 2019
Kotlin helper functions for extracting ColorStateLists and Drawables from a TypedArray using AppCompatResources.
View TypedArrayUtils.kt
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.TypedArray
import androidx.annotation.StyleableRes
import androidx.appcompat.content.res.AppCompatResources
* Utility methods for extracting [ColorStateList]s and [Drawable]s from a [TypedArray].
alexjlockwood / AppCompatViewConstructorDetector.kt
Created Aug 10, 2019
Custom lint rule that prohibits requires instantiating AppCompat views when possible.
View AppCompatViewConstructorDetector.kt
import com.intellij.psi.PsiMethod
import org.jetbrains.uast.UCallExpression
class AppCompatViewConstructorDetector : Detector(), Detector.UastScanner {
companion object {
View my_sample_avd.xml
<aapt:attr name="android:drawable">
alexjlockwood / CircleSquareView.kt
Created Apr 8, 2019
Inspired by @beesandbombs (
View CircleSquareView.kt
import android.content.Context
import android.util.AttributeSet
import android.view.View
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
You can’t perform that action at this time.