Skip to content

Commit df55414

Browse files
committed
Improve code quality
1 parent bf39ae6 commit df55414

File tree

11 files changed

+35
-22
lines changed

11 files changed

+35
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![SPM compatible](https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager)
66
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/RedMadRobot/Catbird/blob/master/LICENSE)
77
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/FigmaExport.svg)](https://cocoapods.org/pods/FigmaExport)
8+
[![codebeat badge](https://codebeat.co/badges/6c346142-a942-4c13-ae6b-5517b4c50b1d)](https://codebeat.co/projects/github-com-redmadrobot-figma-export-master)
89

910
Command line utility to export colors, typography, icons and images from Figma to Xcode / Android Studio project.
1011
* color - Figma's color style

Sources/FigmaExport/Loaders/ColorsLoader.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ final class ColorsLoader {
3636
return styles.compactMap { style -> Color? in
3737
guard let node = nodes[style.nodeId] else { return nil}
3838
guard let fill = node.document.fills.first else { return nil }
39-
let a: Double = fill.opacity ?? fill.color.a
39+
let alpha: Double = fill.opacity ?? fill.color.a
4040
let platform = Platform(rawValue: style.description)
41-
return Color(name: style.name, platform: platform, r: fill.color.r, g: fill.color.g, b: fill.color.b, a: a)
41+
42+
return Color(name: style.name, platform: platform,
43+
red: fill.color.r, green: fill.color.g, blue: fill.color.b, alpha: alpha)
4244
}
4345
}
4446

Sources/FigmaExport/Output/FileDownloader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class FileDownloader {
2727
}
2828

2929
group.enter()
30-
let task = session.downloadTask(with: remoteURL) { localURL, urlResponse, error in
30+
let task = session.downloadTask(with: remoteURL) { localURL, _, error in
3131
defer { group.leave() }
3232

3333
guard let fileURL = localURL, error == nil else {

Sources/FigmaExport/Output/XcodeProjectWritter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class XcodeProjectWritter {
4040
.dropLast() as Array
4141

4242
var currentGroup: PBXGroup? = project.mainGroup
43-
var prevGroup: PBXGroup? = nil
43+
var prevGroup: PBXGroup?
4444

4545
while currentGroup != nil {
4646
if groups.isEmpty { break }

Sources/FigmaExport/Subcommands/ExportColors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extension FigmaExportCommand {
6969
}
7070

7171
private func exportXcodeColors(colorPairs: [AssetPair<Color>], iosParams: Params.iOS, logger: Logger) throws {
72-
var colorsURL: URL? = nil
72+
var colorsURL: URL?
7373
if iosParams.colors.useColorAssets {
7474
if let folder = iosParams.colors.assetsFolder {
7575
colorsURL = iosParams.xcassetsPath.appendingPathComponent(folder)

Sources/FigmaExport/Subcommands/ExportIcons.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ extension FigmaExportCommand {
1515
abstract: "Exports icons from Figma",
1616
discussion: "Exports icons from Figma to Xcode / Android Studio project")
1717

18-
@Option(name: .shortAndLong, default: "figma-export.yaml", help: "An input YAML file with figma and platform properties.")
18+
@Option(name: .shortAndLong, default: "figma-export.yaml",
19+
help: "An input YAML file with figma and platform properties.")
1920
var input: String
2021

21-
@Argument(help: "[Optional] Name of the icons to export. For example \"ic/24/edit\" to export single icon, \"ic/24/edit, ic/16/notification\" to export several icons and \"ic/16/*\" to export all icons of size 16 pt")
22+
@Argument(help: """
23+
[Optional] Name of the icons to export. For example \"ic/24/edit\" \
24+
to export single icon, \"ic/24/edit, ic/16/notification\" to export several icons and \
25+
\"ic/16/*\" to export all icons of size 16 pt
26+
""")
2227
var filter: String?
2328

2429
func run() throws {

Sources/FigmaExport/Subcommands/ExportImages.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ extension FigmaExportCommand {
1515
abstract: "Exports images from Figma",
1616
discussion: "Exports images from Figma to Xcode / Android Studio project")
1717

18-
@Option(name: .shortAndLong, default: "figma-export.yaml", help: "An input YAML file with figma and platform properties.")
18+
@Option(name: .shortAndLong, default: "figma-export.yaml",
19+
help: "An input YAML file with figma and platform properties.")
1920
var input: String
2021

21-
@Argument(help: "[Optional] Name of the images to export. For example \"img/login\" to export single image, \"img/onboarding/1, img/onboarding/2\" to export several images and \"img/onboarding/*\" to export all images from onboarding group")
22+
@Argument(help: """
23+
[Optional] Name of the images to export. For example \"img/login\" to export \
24+
single image, \"img/onboarding/1, img/onboarding/2\" to export several images \
25+
and \"img/onboarding/*\" to export all images from onboarding group
26+
""")
2227
var filter: String?
2328

2429
func run() throws {

Sources/FigmaExportCore/Color.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ public struct Color: Asset {
1111
/// Color components, Double value from 0 to 1
1212
public let red, green, blue, alpha: Double
1313

14-
public init(name: String, platform: Platform? = nil, r: Double, g: Double, b: Double, a: Double) {
14+
public init(name: String, platform: Platform? = nil, red: Double, green: Double, blue: Double, alpha: Double) {
1515
self.name = name
1616
self.platform = platform
17-
self.red = r
18-
self.green = g
19-
self.blue = b
20-
self.alpha = a
17+
self.red = red
18+
self.green = green
19+
self.blue = blue
20+
self.alpha = alpha
2121
}
2222

2323
// MARK: Hashable

Sources/XcodeExport/XcodeIconsExporter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final public class XcodeIconsExporter: XcodeImagesExporterBase {
1313
data: contentsJson.data
1414
))
1515

16-
assets.forEach { image in
16+
try assets.forEach { image in
1717
// Create directory for imageset
1818
let dirURL = output.assetsFolderURL.appendingPathComponent("\(image.name).imageset")
1919

@@ -34,7 +34,7 @@ final public class XcodeIconsExporter: XcodeImagesExporterBase {
3434
)
3535
let encoder = JSONEncoder()
3636
encoder.outputFormatting = .prettyPrinted
37-
let data = try! encoder.encode(contents)
37+
let data = try encoder.encode(contents)
3838
let fileURL = URL(string: "Contents.json")!
3939
files.append(FileContents(
4040
destination: Destination(directory: dirURL, file: fileURL),

Sources/XcodeExport/XcodeImagesExporter.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ final public class XcodeImagesExporter: XcodeImagesExporterBase {
1010
files.append(makeEmptyContentsJson())
1111

1212
// For each pair...
13-
assets.forEach { pair in
13+
try assets.forEach { pair in
1414
let name = pair.light.name
1515

1616
// Create imageset directory
@@ -25,7 +25,7 @@ final public class XcodeImagesExporter: XcodeImagesExporterBase {
2525

2626
let encoder = JSONEncoder()
2727
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
28-
let data = try! encoder.encode(contents)
28+
let data = try encoder.encode(contents)
2929
let fileURL = URL(string: "Contents.json")!
3030
files.append(FileContents(
3131
destination: Destination(directory: imageDirURL, file: fileURL),
@@ -124,7 +124,7 @@ final public class XcodeImagesExporter: XcodeImagesExporterBase {
124124

125125
private func imageDataForImage(_ image: Image, scale: Double? = nil, dark: Bool) -> XcodeAssetContents.ImageData {
126126

127-
var appearance: [XcodeAssetContents.DarkAppeareance]? = nil
127+
var appearance: [XcodeAssetContents.DarkAppeareance]?
128128
if dark {
129129
appearance = [XcodeAssetContents.DarkAppeareance()]
130130
}

0 commit comments

Comments
 (0)