generated from sketch-hq/sketch-assistant-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
30 lines (24 loc) · 1.04 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { RuleDefinition, SketchFileObject } from '@sketch-hq/sketch-assistant-types'
export const duplicateSymbols: RuleDefinition = {
rule: async (context) => {
interface Duplicate {
name: string
number: number
object: SketchFileObject
}
var duplicates: Array<Duplicate> = [];
var totalDuplicates: Array<Duplicate> = [];
for (const symbol of context.utils.objects.symbolMaster) {
var existingElement = duplicates.find((element) => element.name.toLowerCase() == symbol.name.toLowerCase());
if (existingElement != null)
existingElement.number++;
else
duplicates.push({ name: symbol.name, number: 1, object:symbol });
}
totalDuplicates = (duplicates.filter((element) => element.number > 1));
totalDuplicates.forEach(element => context.utils.report('\'' + element.name + '\' has a duplicate symbol', element.object));
},
name: 'nds-sketch-theme-assistant/duplicate-symbols',
title: 'Duplicate Symbols',
description: 'Reports duplicate symbols in your NDS theme file.',
}