-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from s2mr/prioritizeTodoOverMixedChinese
Add `prioritizeTodoOverMixedChinese` option
- Loading branch information
Showing
11 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Sources/L10nLintFramework/Rules/RuleConfigurations/RuleConfigurations.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Sources/L10nLintFramework/Rules/RuleConfigurations/TodoRuleConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import XCTest | ||
@testable import L10nLintFramework | ||
|
||
final class ConfigurationTests: XCTestCase { | ||
func testLoad1() throws { | ||
XCTAssertEqual( | ||
try Configuration.load(at: TestHelper.fixtureURL(fixtureName: "config1.yml")), | ||
Configuration( | ||
basePath: "Tests/L10nLintFrameworkTests/Resources/Fixtures/Localizables4", | ||
reporter: nil, | ||
disabledRules: Optional(["empty_value"]), | ||
enabledRules: nil, | ||
prioritizeTodoOverMixedChinese: true, | ||
ruleConfigurations: RuleConfigurations( | ||
todo: .init(isSummaryEnabled: true, summaryViolationLimit: 20) | ||
) | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import XCTest | ||
@testable import L10nLintFramework | ||
|
||
final class LintRunnerTests: XCTestCase { | ||
func testPreferFixMeThanMixedChineseFalse() throws { | ||
let violations = try LintRunner.run(configuration: Configuration( | ||
basePath: TestHelper.fixtureURL(fixtureName: "Localizables7").path, | ||
prioritizeTodoOverMixedChinese: false | ||
)) | ||
XCTAssertEqual(violations.map(\.ruleWithLocationPoint), [ | ||
RuleWithLocationPoint(ruleIdentifier: "todo", file: "zh-Hans.lproj", line: 2, character: 1), | ||
RuleWithLocationPoint(ruleIdentifier: "mixed_chinese", file: "zh-Hans.lproj", line: 2, character: 19), | ||
RuleWithLocationPoint(ruleIdentifier: "mixed_chinese", file: "zh-Hans.lproj", line: 3, character: 12), | ||
RuleWithLocationPoint(ruleIdentifier: "todo", file: "zh-Hant.lproj", line: 2, character: 1) | ||
]) | ||
} | ||
|
||
func testPreferFixMeThanMixedChineseTrue() throws { | ||
let violations = try LintRunner.run(configuration: Configuration( | ||
basePath: TestHelper.fixtureURL(fixtureName: "Localizables7").path, | ||
prioritizeTodoOverMixedChinese: true | ||
)) | ||
XCTAssertEqual(violations.map(\.ruleWithLocationPoint), [ | ||
RuleWithLocationPoint(ruleIdentifier: "todo", file: "zh-Hans.lproj", line: 2, character: 1), | ||
RuleWithLocationPoint(ruleIdentifier: "mixed_chinese", file: "zh-Hans.lproj", line: 3, character: 12), | ||
RuleWithLocationPoint(ruleIdentifier: "todo", file: "zh-Hant.lproj", line: 2, character: 1) | ||
]) | ||
} | ||
} | ||
|
||
private struct RuleWithLocationPoint: Equatable, CustomStringConvertible { | ||
var ruleIdentifier: String | ||
var file: String? | ||
var line: Int? | ||
var character: Int? | ||
|
||
var description: String { | ||
"RuleWithLocationPoint(ruleIdentifier: \"\(ruleIdentifier)\", file: \"\(file ?? "nil")\", line: \(line ?? -1), character: \(character ?? -1))" | ||
} | ||
} | ||
|
||
private extension StyleViolation { | ||
var ruleWithLocationPoint: RuleWithLocationPoint { | ||
let components = location.file!.components(separatedBy: "/") | ||
return RuleWithLocationPoint( | ||
ruleIdentifier: ruleIdentifier, | ||
file: components[components.count - 2], | ||
line: location.line, | ||
character: location.character | ||
) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Tests/L10nLintFrameworkTests/Resources/Fixtures/Localizables7/Base.lproj/Localizable.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// MARK: LintRunner | ||
"Key1" = "Value1"; | ||
"Key2" = "Value2"; |
3 changes: 3 additions & 0 deletions
3
...L10nLintFrameworkTests/Resources/Fixtures/Localizables7/zh-Hans.lproj/Localizable.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// MARK: LintRunner | ||
"Key1" = "FIXME: 時間"; | ||
"Key2" = "時間"; |
3 changes: 3 additions & 0 deletions
3
...L10nLintFrameworkTests/Resources/Fixtures/Localizables7/zh-Hant.lproj/Localizable.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// MARK: LintRunner | ||
"Key1" = "FIXME: 時間"; | ||
"Key2" = "時間"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
base_path: Tests/L10nLintFrameworkTests/Resources/Fixtures/Localizables4 | ||
prioritize_todo_over_mixed_chinese: true | ||
|
||
disabled_rules: | ||
- empty_value | ||
|
||
todo: | ||
is_summary_enabled: true | ||
summary_violation_limit: 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters