Allow using a period in a CLI product name (#5178)

* Allow using a period in cli product name

* PR fixes

---------

Co-authored-by: Daniele Formichelli <df@bendingspoons.com>
This commit is contained in:
Serhii Butenko 2023-05-08 14:56:18 +03:00 committed by GitHub
parent 3769449844
commit 58413d07e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -73,14 +73,14 @@ class TargetLinter: TargetLinting {
private func lintProductName(target: Target) -> [LintingIssue] {
var allowed = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")
if target.product == .app {
let allowsDot = target.product == .app || target.product == .commandLineTool
if allowsDot {
allowed.formUnion(CharacterSet(charactersIn: "."))
}
if target.productName.unicodeScalars.allSatisfy(allowed.contains) == false {
let reason = target.product == .app ?
"Invalid product name '\(target.productName)'. This string must contain only alphanumeric (A-Z,a-z,0-9), period (.), and underscore (_) characters." :
"Invalid product name '\(target.productName)'. This string must contain only alphanumeric (A-Z,a-z,0-9), and underscore (_) characters."
let reason =
"Invalid product name '\(target.productName)'. This string must contain only alphanumeric (A-Z,a-z,0-9)\(allowsDot ? ", period (.)" : ""), and underscore (_) characters."
return [LintingIssue(reason: reason, severity: .warning)]
}

View File

@ -25,9 +25,16 @@ final class TargetLinterTests: TuistUnitTestCase {
func test_lint_when_target_has_invalid_product_name() {
let XCTAssertInvalidProductNameApp: (Target) -> Void = { target in
let got = self.subject.lint(target: target)
let reason = target.product == .app ?
"Invalid product name '\(target.productName)'. This string must contain only alphanumeric (A-Z,a-z,0-9), period (.), and underscore (_) characters." :
"Invalid product name '\(target.productName)'. This string must contain only alphanumeric (A-Z,a-z,0-9), and underscore (_) characters."
let reason: String
switch target.product {
case .app, .commandLineTool:
reason =
"Invalid product name '\(target.productName)'. This string must contain only alphanumeric (A-Z,a-z,0-9), period (.), and underscore (_) characters."
default:
reason =
"Invalid product name '\(target.productName)'. This string must contain only alphanumeric (A-Z,a-z,0-9), and underscore (_) characters."
}
self.XCTContainsLintingIssue(got, LintingIssue(reason: reason, severity: .warning))
}