Skip to content

Commit

Permalink
Fix bugs in 0.9.9 & bump version to 0.9.10 (#50)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
stevelandeyasana and TomerHacohen authored Apr 4, 2023
1 parent 474fd99 commit 3c4cd70
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EXECUTABLE_NAME = locheck
REPO = https://github.com/Asana/locheck
VERSION = 0.9.9
VERSION = 0.9.10

PREFIX = /usr/local
INSTALL_PATH = $(PREFIX)/bin/$(EXECUTABLE_NAME)
Expand Down
2 changes: 1 addition & 1 deletion Sources/LocheckCommand/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Files
import Foundation
import LocheckLogic

let version = "0.9.9"
let version = "0.9.10"

struct Locheck: ParsableCommand {
static let configuration = CommandConfiguration(
Expand Down
2 changes: 1 addition & 1 deletion Sources/LocheckLogic/Types/FormatArgument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct FormatArgument: Equatable, Hashable {
let position: Int
let isPositionExplicit: Bool

var asExplicit: String { "%$\(position)\(specifier)" }
var asExplicit: String { "%\(position)$\(specifier)" }
}

extension FormatArgument {
Expand Down
2 changes: 1 addition & 1 deletion Sources/LocheckLogic/Types/StringsdictEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public struct StringsdictEntry: Equatable {

for string in permutations {
for arg in string.arguments {
if !arg.isPositionExplicit {
if !arg.isPositionExplicit && string.arguments.count > 1 {
report(
StringsdictEntryHasImplicitPosition(
key: key,
Expand Down
60 changes: 30 additions & 30 deletions Tests/LocheckCommandTests/ExecutableTests.swift

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions Tests/LocheckLogicTests/ValidateStringsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class ValidateStringsTests: XCTestCase {
let problemReporter = ProblemReporter(log: false)
validateStrings(
baseStrings: [
// Don't report errors on just one arg
LocalizedStringPair(
string: "\"%d\" = \"%d\";",
path: "abc",
line: 0,
basePath: "",
baseLineFallback: 0)!,
LocalizedStringPair(
string: "\"present %d %@\" = \"present %d %@\";",
path: "abc",
Expand All @@ -49,6 +56,12 @@ class ValidateStringsTests: XCTestCase {
baseLineFallback: 0)!,
],
translationStrings: [
LocalizedStringPair(
string: "\"%d\" = \"%d\";",
path: "abc",
line: 0,
basePath: "",
baseLineFallback: 0)!,
LocalizedStringPair(
string: "\"present %d %@\" = \"%d %@\";",
path: "def",
Expand All @@ -64,10 +77,10 @@ class ValidateStringsTests: XCTestCase {
XCTAssertEqual(
problemReporter.problems.map(\.messageForXcode),
[
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$1d). (string_has_implicit_position)",
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$2@). (string_has_implicit_position)",
"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)",
"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)",
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%1$d). (string_has_implicit_position)",
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%2$@). (string_has_implicit_position)",
"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)",
"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)",
])
}

Expand Down Expand Up @@ -98,11 +111,11 @@ class ValidateStringsTests: XCTestCase {
XCTAssertEqual(
problemReporter.problems.map(\.messageForXcode),
[
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$1d). (string_has_implicit_position)",
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%$2@). (string_has_implicit_position)",
"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)",
":0: warning: Argument 1 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%1$d). (string_has_implicit_position)",
":0: warning: Argument 2 in \'present %d %@\' has an implicit position. Use an explicit position for safety (%2$@). (string_has_implicit_position)",
"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)",
"def:0: error: Specifier for argument 1 does not match (should be d, is @) (string_has_invalid_argument)",
"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)",
"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)",
"def:0: error: Specifier for argument 2 does not match (should be @, is d) (string_has_invalid_argument)",
])
}
Expand Down
20 changes: 10 additions & 10 deletions Tests/LocheckLogicTests/parseAndValidateStringsdictTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ class ParseAndValidateStringsdictTests: XCTestCase {
Examples/Demo_Base.stringsdict:81: warning: '%s added %d task(s) to 's'' is missing from Demo_Translation (key_missing_from_translation)
Examples/Demo_Base.stringsdict:63: warning: 'missing from translation' is missing from Demo_Translation (key_missing_from_translation)
Examples/Demo_Translation.stringsdict:22: warning: 'missing from base' is missing from the base translation (key_missing_from_base)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
""")
}
}

0 comments on commit 3c4cd70

Please sign in to comment.