Skip to content

Commit 3c4cd70

Browse files
Fix bugs in 0.9.9 & bump version to 0.9.10 (#50)
* Fix implicit positions error message with correct explicit formatting. * Actually fix the bug * Don't report implicit-position errors on strings with just 1 arg * 0.9.10 --------- Co-authored-by: Tomer HaCohen <[email protected]>
1 parent 474fd99 commit 3c4cd70

File tree

7 files changed

+65
-52
lines changed

7 files changed

+65
-52
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
EXECUTABLE_NAME = locheck
22
REPO = https://github.com/Asana/locheck
3-
VERSION = 0.9.9
3+
VERSION = 0.9.10
44

55
PREFIX = /usr/local
66
INSTALL_PATH = $(PREFIX)/bin/$(EXECUTABLE_NAME)

Sources/LocheckCommand/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Files
1111
import Foundation
1212
import LocheckLogic
1313

14-
let version = "0.9.9"
14+
let version = "0.9.10"
1515

1616
struct Locheck: ParsableCommand {
1717
static let configuration = CommandConfiguration(

Sources/LocheckLogic/Types/FormatArgument.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct FormatArgument: Equatable, Hashable {
1515
let position: Int
1616
let isPositionExplicit: Bool
1717

18-
var asExplicit: String { "%$\(position)\(specifier)" }
18+
var asExplicit: String { "%\(position)$\(specifier)" }
1919
}
2020

2121
extension FormatArgument {

Sources/LocheckLogic/Types/StringsdictEntry.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public struct StringsdictEntry: Equatable {
6969

7070
for string in permutations {
7171
for arg in string.arguments {
72-
if !arg.isPositionExplicit {
72+
if !arg.isPositionExplicit && string.arguments.count > 1 {
7373
report(
7474
StringsdictEntryHasImplicitPosition(
7575
key: key,

Tests/LocheckCommandTests/ExecutableTests.swift

+30-30
Large diffs are not rendered by default.

Tests/LocheckLogicTests/ValidateStringsTests.swift

+21-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class ValidateStringsTests: XCTestCase {
4141
let problemReporter = ProblemReporter(log: false)
4242
validateStrings(
4343
baseStrings: [
44+
// Don't report errors on just one arg
45+
LocalizedStringPair(
46+
string: "\"%d\" = \"%d\";",
47+
path: "abc",
48+
line: 0,
49+
basePath: "",
50+
baseLineFallback: 0)!,
4451
LocalizedStringPair(
4552
string: "\"present %d %@\" = \"present %d %@\";",
4653
path: "abc",
@@ -49,6 +56,12 @@ class ValidateStringsTests: XCTestCase {
4956
baseLineFallback: 0)!,
5057
],
5158
translationStrings: [
59+
LocalizedStringPair(
60+
string: "\"%d\" = \"%d\";",
61+
path: "abc",
62+
line: 0,
63+
basePath: "",
64+
baseLineFallback: 0)!,
5265
LocalizedStringPair(
5366
string: "\"present %d %@\" = \"%d %@\";",
5467
path: "def",
@@ -64,10 +77,10 @@ class ValidateStringsTests: XCTestCase {
6477
XCTAssertEqual(
6578
problemReporter.problems.map(\.messageForXcode),
6679
[
67-
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$1d). (string_has_implicit_position)",
68-
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$2@). (string_has_implicit_position)",
69-
"def:0: warning: Argument 1 in translation of \'present %d %@\' (\'%d %@\') has an implicit position. Use an explicit position for safety (%$1d). (string_has_implicit_position)",
70-
"def:0: warning: Argument 2 in translation of \'present %d %@\' (\'%d %@\') has an implicit position. Use an explicit position for safety (%$2@). (string_has_implicit_position)",
80+
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%1$d). (string_has_implicit_position)",
81+
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%2$@). (string_has_implicit_position)",
82+
"def:0: warning: Argument 1 in translation of \'present %d %@\' (\'%d %@\') has an implicit position. Use an explicit position for safety (%1$d). (string_has_implicit_position)",
83+
"def:0: warning: Argument 2 in translation of \'present %d %@\' (\'%d %@\') has an implicit position. Use an explicit position for safety (%2$@). (string_has_implicit_position)",
7184
])
7285
}
7386

@@ -98,11 +111,11 @@ class ValidateStringsTests: XCTestCase {
98111
XCTAssertEqual(
99112
problemReporter.problems.map(\.messageForXcode),
100113
[
101-
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$1d). (string_has_implicit_position)",
102-
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$2@). (string_has_implicit_position)",
103-
"def:0: warning: Argument 1 in translation of \'present %d %@\' (\'%@ %d tneserp\') has an implicit position. Use an explicit position for safety (%$1@). (string_has_implicit_position)",
114+
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%1$d). (string_has_implicit_position)",
115+
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%2$@). (string_has_implicit_position)",
116+
"def:0: warning: Argument 1 in translation of \'present %d %@\' (\'%@ %d tneserp\') has an implicit position. Use an explicit position for safety (%1$@). (string_has_implicit_position)",
104117
"def:0: error: Specifier for argument 1 does not match (should be d, is @) (string_has_invalid_argument)",
105-
"def:0: warning: Argument 2 in translation of \'present %d %@\' (\'%@ %d tneserp\') has an implicit position. Use an explicit position for safety (%$2d). (string_has_implicit_position)",
118+
"def:0: warning: Argument 2 in translation of \'present %d %@\' (\'%@ %d tneserp\') has an implicit position. Use an explicit position for safety (%2$d). (string_has_implicit_position)",
106119
"def:0: error: Specifier for argument 2 does not match (should be @, is d) (string_has_invalid_argument)",
107120
])
108121
}

Tests/LocheckLogicTests/parseAndValidateStringsdictTests.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ class ParseAndValidateStringsdictTests: XCTestCase {
3434
Examples/Demo_Base.stringsdict:81: warning: '%s added %d task(s) to 's'' is missing from Demo_Translation (key_missing_from_translation)
3535
Examples/Demo_Base.stringsdict:63: warning: 'missing from translation' is missing from Demo_Translation (key_missing_from_translation)
3636
Examples/Demo_Translation.stringsdict:22: warning: 'missing from base' is missing from the base translation (key_missing_from_base)
37-
Examples/Demo_Base.stringsdict:6: warning: Argument 1 in permutation 'Every %d weeks on %2$lu days' of 'Every %d week(s) on %lu days' has an implicit position. Use an explicit position for safety (%$1d). (stringsdict_entry_has_implicit_position)
38-
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added %d tasks and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$1s). (stringsdict_entry_has_implicit_position)
39-
Examples/Demo_Base.stringsdict:81: warning: Argument 2 in permutation '%s added %d tasks and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$2d). (stringsdict_entry_has_implicit_position)
40-
Examples/Demo_Base.stringsdict:81: warning: Argument 3 in permutation '%s added %d tasks and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$3d). (stringsdict_entry_has_implicit_position)
37+
Examples/Demo_Base.stringsdict:6: warning: Argument 1 in permutation 'Every %d weeks on %2$lu days' of 'Every %d week(s) on %lu days' has an implicit position. Use an explicit position for safety (%1$d). (stringsdict_entry_has_implicit_position)
38+
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added %d tasks and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%1$s). (stringsdict_entry_has_implicit_position)
39+
Examples/Demo_Base.stringsdict:81: warning: Argument 2 in permutation '%s added %d tasks and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%2$d). (stringsdict_entry_has_implicit_position)
40+
Examples/Demo_Base.stringsdict:81: warning: Argument 3 in permutation '%s added %d tasks and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%3$d). (stringsdict_entry_has_implicit_position)
4141
Examples/Demo_Base.stringsdict:81: error: Two permutations of '%s added %d task(s) to 's'' contain different format specifiers at position 3. '%s added %d tasks and %d milestones to %3$s' uses 'd', and '%s added %d tasks and %d milestones to %3$s' uses 's'. (stringsdict_entry_permutations_have_conflicting_specifiers)
42-
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added %d tasks and a milestone to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$1s). (stringsdict_entry_has_implicit_position)
43-
Examples/Demo_Base.stringsdict:81: warning: Argument 2 in permutation '%s added %d tasks and a milestone to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$2d). (stringsdict_entry_has_implicit_position)
42+
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added %d tasks and a milestone to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%1$s). (stringsdict_entry_has_implicit_position)
43+
Examples/Demo_Base.stringsdict:81: warning: Argument 2 in permutation '%s added %d tasks and a milestone to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%2$d). (stringsdict_entry_has_implicit_position)
4444
Examples/Demo_Base.stringsdict:81: error: Two permutations of '%s added %d task(s) to 's'' contain different format specifiers at position 3. '%s added %d tasks and %d milestones to %3$s' uses 'd', and '%s added %d tasks and a milestone to %3$s' uses 's'. (stringsdict_entry_permutations_have_conflicting_specifiers)
45-
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added a task and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$1s). (stringsdict_entry_has_implicit_position)
46-
Examples/Demo_Base.stringsdict:81: warning: Argument 2 in permutation '%s added a task and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$2d). (stringsdict_entry_has_implicit_position)
45+
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added a task and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%1$s). (stringsdict_entry_has_implicit_position)
46+
Examples/Demo_Base.stringsdict:81: warning: Argument 2 in permutation '%s added a task and %d milestones to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%2$d). (stringsdict_entry_has_implicit_position)
4747
Examples/Demo_Base.stringsdict:81: error: Two permutations of '%s added %d task(s) to 's'' contain different format specifiers at position 3. '%s added %d tasks and %d milestones to %3$s' uses 'd', and '%s added a task and %d milestones to %3$s' uses 's'. (stringsdict_entry_permutations_have_conflicting_specifiers)
48-
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added a task and a milestone to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%$1s). (stringsdict_entry_has_implicit_position)
48+
Examples/Demo_Base.stringsdict:81: warning: Argument 1 in permutation '%s added a task and a milestone to %3$s' of '%s added %d task(s) to 's'' has an implicit position. Use an explicit position for safety (%1$s). (stringsdict_entry_has_implicit_position)
4949
Examples/Demo_Base.stringsdict:81: error: Two permutations of '%s added %d task(s) to 's'' contain different format specifiers at position 3. '%s added %d tasks and %d milestones to %3$s' uses 'd', and '%s added a task and a milestone to %3$s' uses 's'. (stringsdict_entry_permutations_have_conflicting_specifiers)
50-
Examples/Demo_Translation.stringsdict:6: warning: Argument 1 in permutation '%2$lu jours toutes les %d semaines' of 'Every %d week(s) on %lu days' has an implicit position. Use an explicit position for safety (%$1d). (stringsdict_entry_has_implicit_position)
50+
Examples/Demo_Translation.stringsdict:6: warning: Argument 1 in permutation '%2$lu jours toutes les %d semaines' of 'Every %d week(s) on %lu days' has an implicit position. Use an explicit position for safety (%1$d). (stringsdict_entry_has_implicit_position)
5151
""")
5252
}
5353
}

0 commit comments

Comments
 (0)