Skip to content

Commit

Permalink
Правит часть замечаний линтера
Browse files Browse the repository at this point in the history
  • Loading branch information
avShabaeva committed Jan 15, 2024
1 parent 5f0f935 commit 0ea3556
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ final class DefaultTypographyTokensGenerator: TypographyTokensGenerator {
tokenValues: TokenValues
) throws -> TypographyToken.LineHeightToken {
let lineHeightValue = value.lineHeight
let lineHeightResolvedValue = try tokensResolver.resolveValue(lineHeightValue, tokenValues: tokenValues, theme: .undefined)
let lineHeightResolvedValue = try tokensResolver.resolveValue(
lineHeightValue,
tokenValues: tokenValues,
theme: .undefined
)

guard lineHeightResolvedValue.hasSuffix("%") else {
return TypographyToken.LineHeightToken(
Expand All @@ -30,7 +34,9 @@ final class DefaultTypographyTokensGenerator: TypographyTokensGenerator {
)
}

let fontSize = Double(try tokensResolver.resolveValue(value.fontSize, tokenValues: tokenValues, theme: .undefined))
let fontSize = Double(
try tokensResolver.resolveValue(value.fontSize, tokenValues: tokenValues, theme: .undefined)
)
let lineHeight = Double(lineHeightResolvedValue.dropLast()).map { $0 / 100.0 }

guard let fontSize else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,33 @@ final class DefaultColorTokensContextProvider: ColorTokensContextProvider {

return resolveReference(initialReferenceName: nightValue, themeColorTokenValues: tokenValues.night)
}

private func resolveReference(
initialReferenceName: String,
themeColorTokenValues: [TokenValue]
) -> String {
if(initialReferenceName.contains("color.base")) {
if initialReferenceName.contains("color.base") {
return initialReferenceName
}

guard let replaceValue = themeColorTokenValues.first(where: { initialReferenceName.contains($0.name)})?.type.stringValue else {

guard let replaceValue = themeColorTokenValues.first(where: {
initialReferenceName.contains($0.name)
})?.type.stringValue else {
return initialReferenceName
}

let nsString = initialReferenceName as NSString
guard
let tokenRegex = try? NSRegularExpression(pattern: #"\{.*?\}"#),
let firstArgument = tokenRegex.firstMatch(in: initialReferenceName, range: NSRange(location: 0, length: initialReferenceName.count))
let firstArgument = tokenRegex.firstMatch(
in: initialReferenceName,
range: NSRange(location: 0, length: initialReferenceName.count)
)
else {
return initialReferenceName
}

let replacedReferenceName = nsString.replacingCharacters(in: firstArgument.range, with: replaceValue) as String
return replacedReferenceName
return nsString.replacingCharacters(in: firstArgument.range, with: replaceValue) as String
}

private func makeColorToken(
Expand All @@ -84,7 +88,6 @@ final class DefaultColorTokensContextProvider: ColorTokensContextProvider {
tokenValues: TokenValues,
path: [String]
) throws -> ColorToken {

let dayHexColorValue = try tokensResolver.resolveHexColorValue(
dayValue,
tokenValues: tokenValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class DefaultTokensResolver: TokensResolver {

func resolveValue(_ value: String, tokenValues: TokenValues, theme: Theme) throws -> String {
let themeTokens = tokenValues.getThemeTokenValues(theme: theme)

let resolvedValue = try value.replacingOccurrences(matchingPattern: #"\{.*?\}"#) { referenceName in
let referenceName = String(
referenceName
Expand All @@ -94,7 +94,6 @@ final class DefaultTokensResolver: TokensResolver {
return evaluteValue(resolvedValue)
}


func resolveRGBAColorValue(_ value: String, tokenValues: TokenValues, theme: Theme) throws -> Color {
let components = try resolveValue(value, tokenValues: tokenValues, theme: theme)
.slice(from: "(", to: ")", includingBounds: false)?
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions Sources/FigmaGen/Models/Token/TokenValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ struct TokenValues: Codable, Hashable {
// Для undefined возвращается полный набор токенов. Нужен для Spacer, Font и других независимых от темы параметров.
func getThemeTokenValues(theme: Theme) -> [TokenValue] {
switch theme {
case .day: return [day, core, semantic, colors, typography].flatMap { $0 }
case .night: return [night, core, semantic, colors, typography].flatMap { $0 }
case .undefined: return [core, semantic, colors, typography, day, night].flatMap { $0 }
case .day:
return [day, core, semantic, colors, typography].flatMap { $0 }
case .night:
return [night, core, semantic, colors, typography].flatMap { $0 }
case .undefined:
return [core, semantic, colors, typography, day, night].flatMap { $0 }
}
}
}

0 comments on commit 0ea3556

Please sign in to comment.