### Install StringsLint via Mint Source: https://github.com/dral3x/stringslint/blob/master/README.md Use Mint to install the StringsLint binary. ```bash mint install dral3x/stringslint ``` -------------------------------- ### Install StringsLint via Homebrew Source: https://github.com/dral3x/stringslint/blob/master/README.md Use Homebrew to tap and install the StringsLint package. ```bash brew tap dral3x/dral3x brew install stringslint ``` -------------------------------- ### Display Version Source: https://context7.com/dral3x/stringslint/llms.txt Check the installed version of the tool. ```bash # Show version stringslint version # Output: 0.1.10 ``` -------------------------------- ### CocoaPods Integration Script Source: https://context7.com/dral3x/stringslint/llms.txt Run the tool when installed via CocoaPods. ```bash # If installed via CocoaPods "${PODS_ROOT}/StringsLint/stringslint" ``` -------------------------------- ### Swift String(localized:) API Source: https://context7.com/dral3x/stringslint/llms.txt Demonstrates the modern Swift `String(localized:)` API for localization, available from iOS 15. This example uses a simple key 'welcome_title'. ```swift // Modern String localized API (iOS 15+) let title = String(localized: "welcome_title") ``` -------------------------------- ### Configuration Class Source: https://context7.com/dral3x/stringslint/llms.txt The Configuration class allows for programmatic setup of linting parameters, including file inclusion/exclusion and rule definitions. ```APIDOC ## Configuration Class ### Description Used to define the scope and rules for the linting process. Can be initialized from a YAML file or programmatically. ### Initialization - **init()**: Loads configuration from default .stringslint.yml - **init(path: String, rootPath: String)**: Loads from a specific YAML file path - **init(included: [String], excluded: [String], rules: [LintRule]?)**: Manual configuration ### Properties - **included** ([String]): List of paths to include - **excluded** ([String]): List of paths to exclude - **rules** ([LintRule]): Configured linting rules ``` -------------------------------- ### Install StringsLint via CocoaPods Source: https://github.com/dral3x/stringslint/blob/master/README.md Add the dependency to your Podfile to manage StringsLint versions. ```ruby pod 'StringsLint' ``` -------------------------------- ### Detect Partially Localized Strings Source: https://context7.com/dral3x/stringslint/llms.txt This example illustrates a 'partial' localization issue where a string key exists in one language file but is missing in another. 'farewell' is missing in the French file. ```strings /* en.lproj/Localizable.strings */ "greeting" = "Hello"; "farewell" = "Goodbye"; /* fr.lproj/Localizable.strings */ "greeting" = "Bonjour"; /* Missing "farewell" - will trigger violation */ ``` -------------------------------- ### Detect Unused Localized Strings Source: https://context7.com/dral3x/stringslint/llms.txt This example shows strings defined in a .strings file that are not used in the codebase. StringLint will flag 'legacy_string' as unused. ```strings /* Localizable.strings */ /* Used string */ "active_string" = "This is used"; /* Unused string - will trigger violation */ "legacy_string" = "This is never used in code"; ``` -------------------------------- ### Build StringsLint from Source Source: https://context7.com/dral3x/stringslint/llms.txt Clone the repository and build using make. ```bash # Clone and build git clone https://github.com/dral3x/StringsLint.git cd StringsLint make install ``` -------------------------------- ### Display Help Information Source: https://context7.com/dral3x/stringslint/llms.txt View available commands and options. ```bash stringslint help # Output: # OVERVIEW: A tool to enforce Swift style and conventions. # # USAGE: stringslint # # OPTIONS: # --version Show the version. # -h, --help Show help information. # # SUBCOMMANDS: # lint (default) Print lint warnings and errors (default command) # version Display the current version of StringsLint ``` -------------------------------- ### Full Form of Swift String(localized:) Source: https://context7.com/dral3x/stringslint/llms.txt Demonstrates the complete `String(localized:)` API including key, default value, table name, and comment. Ensure 'user_greeting' is in 'Onboarding.strings' or use 'Welcome, user!' as fallback. ```swift // Full form let complete = String(localized: "user_greeting", defaultValue: "Welcome, user!", table: "Onboarding", comment: "Greeting on first launch") ``` -------------------------------- ### View StringsLint Command Line Help Source: https://github.com/dral3x/stringslint/blob/master/README.md Display the CLI help and available subcommands. ```text $ stringslint help OVERVIEW: A tool to enforce Swift style and conventions. USAGE: stringslint OPTIONS: --version Show the version. -h, --help Show help information. SUBCOMMANDS: lint (default) Print lint warnings and errors (default command) version Display the current version of StringsLint See 'stringslint help ' for detailed help. ``` -------------------------------- ### Run Basic Lint Commands Source: https://context7.com/dral3x/stringslint/llms.txt Execute linting on directories or with custom configurations. ```bash # Lint current directory stringslint # Lint specific path stringslint lint --path /path/to/project # Lint multiple paths stringslint lint /path/to/src /path/to/resources # Use custom configuration file stringslint lint --config custom-config.yml ``` -------------------------------- ### Basic Configuration File Source: https://context7.com/dral3x/stringslint/llms.txt Define included and excluded paths in .stringslint.yml. ```yaml # .stringslint.yml # Paths to include during linting included: - Source - Resources # Paths to ignore during linting (takes precedence over included) excluded: - Carthage - Pods - Source/ExcludedFolder - Source/ExcludedFile.swift - Source/*/ExcludedFile.swift # Wildcard support ``` -------------------------------- ### Programmatically Configure StringsLint Source: https://context7.com/dral3x/stringslint/llms.txt Initialize the Configuration class to manage linting settings from files or manual definitions. ```swift import StringsLintFramework // Load from default .stringslint.yml let config = Configuration() // Load from custom path let customConfig = Configuration(path: "custom-config.yml", rootPath: "/project") // Create programmatically let manualConfig = Configuration( included: ["Sources", "Resources"], excluded: ["Pods", "Carthage"], rules: nil // Uses default rules ) // Access configuration properties print(config.included) // [String] paths to include print(config.excluded) // [String] paths to exclude print(config.rules) // [LintRule] configured rules ``` -------------------------------- ### Configure StringsLint with .stringslint.yml Source: https://github.com/dral3x/stringslint/blob/master/README.md Define included/excluded paths, parser settings, and rule severities in the configuration file. ```yaml included: # paths to include during linting. `--path` is ignored if present. - Source excluded: # paths to ignore during linting. Takes precedence over `included`. - Carthage - Pods - Source/ExcludedFolder - Source/ExcludedFile.swift - Source/*/ExcludedFile.swift # Exclude files with a wildcard # Customize parsers objc_parser: implicit_macros: - SPKLocalizedString # detect this custom macro xib_parser: key_paths: - textLocalized # keyPath used to localized UI elements swift_parser: swiftui_implicit: false # disable implicit detection of SwiftUI localized strings # Customize specific rules missing: severity: error ignored: - Demo title partial: severity: warning unused: severity: note ignored: - NSAppleMusicUsageDescription # used by iOS directly missing_comment: severity: none ``` -------------------------------- ### Configure StringsLint via GitHub Actions Source: https://github.com/dral3x/stringslint/blob/master/README.md Automate linting in your CI pipeline using a workflow file. ```yaml name: StringsLint on: pull_request: paths: - '.github/workflows/stringslint.yml' - '.stringslint.yml' - '**/*.swift' - '**/*.strings' - '**/*.stringsdict' jobs: StringsLint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: GitHub Action for StringsLint uses: dral3x/action-stringslint@1.1.9 ``` -------------------------------- ### Configure XIB and Storyboard Localization Source: https://context7.com/dral3x/stringslint/llms.txt Detect localized strings in Interface Builder by defining custom keyPaths in the .stringslint.yml file. ```xml ``` ```yaml # .stringslint.yml xib_parser: key_paths: - textLocalized - accessibilityLocalized - placeholderLocalized ``` -------------------------------- ### Xcode Build Phase Script Source: https://context7.com/dral3x/stringslint/llms.txt Integrate StringsLint into Xcode build phases to surface warnings. ```bash # Add this as a new Run Script Phase in Build Phases if which stringslint >/dev/null; then stringslint else echo "warning: StringsLint not installed, download from https://github.com/dral3x/StringsLint" fi ``` -------------------------------- ### Custom Rule Implementation Source: https://context7.com/dral3x/stringslint/llms.txt Developers can extend StringsLint by implementing the LintRule protocol. ```APIDOC ## Custom Rule Implementation ### Description Create custom validation logic by conforming to the LintRule protocol. ### Required Methods - **init()**: Default initializer - **init(configuration: Any)**: Initializer for YAML-based configuration - **processFile(File)**: Logic to analyze a file and collect violations ### Properties - **description** (RuleDescription): Metadata about the rule - **violations** ([Violation]): Collection of detected issues ``` -------------------------------- ### Integrate StringsLint into Xcode Build Phases Source: https://github.com/dral3x/stringslint/blob/master/README.md Add a Run Script Phase to your Xcode scheme to execute linting during builds. ```bash if which stringslint >/dev/null; then stringslint else echo "warning: StringsLint not installed, download from https://github.com/dral3x/StringsLint" fi ``` ```bash "${PODS_ROOT}/StringsLint/stringslint" ``` -------------------------------- ### Parser Configuration Source: https://context7.com/dral3x/stringslint/llms.txt Customize how the tool parses source files for localization keys. ```yaml # .stringslint.yml # Objective-C parser: detect custom localization macros objc_parser: implicit_macros: - SPKLocalizedString # Custom macro - MyLocalizedString # XIB/Storyboard parser: detect custom keyPaths for localization xib_parser: key_paths: - textLocalized # Custom keyPath for IBInspectable - accessibilityLocalized # Swift parser: configure SwiftUI implicit detection swift_parser: swiftui_implicit: false # Disable implicit SwiftUI string detection ``` -------------------------------- ### SwiftUI Implicit Localization with Text Source: https://context7.com/dral3x/stringslint/llms.txt This SwiftUI `View` demonstrates implicit localization using the `Text` view. StringLint detects 'welcome_message' as a string that should be localized. ```swift import SwiftUI struct ContentView: View { var body: some View { VStack { // Implicitly localized - detected by StringsLint Text("welcome_message") Button("submit_button") { // action } TextField("email_placeholder", text: $email) Toggle("notifications_toggle", isOn: $enabled) } .navigationTitle("settings_title") .accessibilityLabel("main_content_label") } } ``` -------------------------------- ### Detect Missing Localized Strings in Swift Source: https://context7.com/dral3x/stringslint/llms.txt This Swift code snippet demonstrates a common localization pattern that StringLint detects. Ensure that 'welcome_message' and 'hello_world' are defined in your .strings files to avoid violations. ```swift // Example Swift code with missing localization // This will trigger a violation if "welcome_message" is not in Localizable.strings let message = NSLocalizedString("welcome_message", comment: "Welcome screen title") // SwiftUI example Text("hello_world") // Triggers if not in .strings file ``` -------------------------------- ### Implement LocalizableParser Source: https://context7.com/dral3x/stringslint/llms.txt Defines a custom file parser by conforming to the LocalizableParser protocol. ```swift import StringsLintFramework public struct CustomParser: LocalizableParser { public static var identifier: String { return "custom_parser" } public var supportedFileExtentions: [String] { return ["custom"] } public init() {} public init(configuration: Any) throws { // Parse configuration } public func support(file: File) -> Bool { return file.name.hasSuffix(".custom") } public func parse(file: File) throws -> [LocalizedString] { var strings = [LocalizedString]() for (index, line) in file.lines.enumerated() { // Custom parsing logic let location = Location(file: file, line: index + 1) // Extract and append LocalizedString instances } return strings } } ``` -------------------------------- ### Configure Custom Objective-C Macros Source: https://context7.com/dral3x/stringslint/llms.txt Define custom localization macros in Objective-C and register them in the .stringslint.yml configuration file. ```objc // Custom macro usage NSString *text = SPKLocalizedString(@"custom_key", @"Comment"); NSString *other = MyLocalizedString(@"another_key", nil); ``` ```yaml # .stringslint.yml objc_parser: implicit_macros: - SPKLocalizedString - MyLocalizedString ``` -------------------------------- ### Swift String(localized:) with Default Value Source: https://context7.com/dral3x/stringslint/llms.txt Shows `String(localized:)` with a `defaultValue` parameter. If 'greeting' is not found, 'Hello!' will be used. ```swift // With default value let message = String(localized: "greeting", defaultValue: "Hello!") ``` -------------------------------- ### Rule Configuration Source: https://context7.com/dral3x/stringslint/llms.txt Set severity levels and ignore specific strings for individual rules. ```yaml # .stringslint.yml # Missing rule: strings used in code but not in .strings files missing: severity: error # Options: none, warning, error ignored: - Demo title - Debug string # Partial rule: strings not localized in all languages partial: severity: warning # Unused rule: strings in .strings files but not used in code unused: severity: warning ignored: - NSAppleMusicUsageDescription # iOS system keys - NSCameraUsageDescription # Missing comment rule: strings without comments missing_comment: severity: none # Disable this rule ``` -------------------------------- ### GitHub Actions Workflow Source: https://context7.com/dral3x/stringslint/llms.txt Automate linting on pull requests using GitHub Actions. ```yaml # .github/workflows/stringslint.yml name: StringsLint on: pull_request: paths: - '.github/workflows/stringslint.yml' - '.stringslint.yml' - '**/*.swift' - '**/*.strings' - '**/*.stringsdict' jobs: StringsLint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: GitHub Action for StringsLint uses: dral3x/action-stringslint@1.1.9 ``` -------------------------------- ### Implement Custom Lint Rules Source: https://context7.com/dral3x/stringslint/llms.txt Create custom validation logic by conforming to the LintRule protocol. ```swift import StringsLintFramework public class CustomRule: LintRule { public static var description = RuleDescription( identifier: "custom_rule", name: "Custom", description: "Custom validation for localized strings" ) var severity: ViolationSeverity = .warning private var issues = [Violation]() public required init() {} public required init(configuration: Any) throws { // Parse configuration from YAML } public func processFile(_ file: File) { // Analyze file and collect violations if file.name.hasSuffix(".strings") { // Custom analysis logic } } public var violations: [Violation] { return issues } } ``` -------------------------------- ### Configure Partial Rule Severity Source: https://context7.com/dral3x/stringslint/llms.txt Set the severity for the 'partial' rule in your StringLint configuration. ```yaml # Configuration partial: severity: warning ``` -------------------------------- ### Configure Unused Rule Severity Source: https://context7.com/dral3x/stringslint/llms.txt Configure the severity level for the 'unused' rule and list any keys to ignore, such as system-defined descriptions. ```yaml # Configuration unused: severity: warning ignored: - NSPhotoLibraryUsageDescription - NSLocationWhenInUseUsageDescription ``` -------------------------------- ### Configure ViolationSeverity Source: https://context7.com/dral3x/stringslint/llms.txt Defines severity levels for reported violations and demonstrates their comparative ordering. ```swift import StringsLintFramework // Severity levels let none = ViolationSeverity.none // Ignored, not reported let warning = ViolationSeverity.warning // Non-fatal, Xcode shows warning let error = ViolationSeverity.error // Fatal, Xcode fails build // Comparison print(ViolationSeverity.warning < ViolationSeverity.error) // true print(ViolationSeverity.none < ViolationSeverity.warning) // true ``` -------------------------------- ### Programmatically Lint Files Source: https://context7.com/dral3x/stringslint/llms.txt Use the Linter class to process files against a set of rules and handle the resulting violations. ```swift import StringsLintFramework // Create linter with rules let rules: [LintRule] = [ MissingRule(), UnusedRule(), PartialRule(), MissingCommentRule() ] let linter = Linter(rules: rules, parallel: true) // Lint files let files = [ "/path/to/Localizable.strings", "/path/to/ViewController.swift", "/path/to/Main.storyboard" ] let result = linter.lintFiles(files) switch result { case .success(let violations): for violation in violations { print(violation.description) // Output: /path/to/file.swift:42: warning: Missing Violation: Localized string "key" is missing (missing) } case .failure(let error): print("Linting failed: \(error)") } ``` -------------------------------- ### Generate Xcode Reports Source: https://context7.com/dral3x/stringslint/llms.txt Creates Xcode-compatible violation reports for single or multiple violations. ```swift import StringsLintFramework // Generate report for multiple violations let violations: [Violation] = [/* violations */] let report = XcodeReporter.generateReport(violations) print(report) // Output: // /path/to/File.swift:10: warning: Missing Violation: Localized string "key1" is missing (missing) // /path/to/File.swift:25: error: Unused Violation: Localized string "key2" is unused (unused) // Generate for single violation let singleReport = XcodeReporter.generateForSingleViolation(violation) ``` -------------------------------- ### Swift String(localized:) with Table Name Source: https://context7.com/dral3x/stringslint/llms.txt Illustrates using `String(localized:)` to specify a table name ('Errors') for loading localized strings. The key 'network_error' will be looked for in 'Errors.strings'. ```swift // With table let error = String(localized: "network_error", table: "Errors") ``` -------------------------------- ### Basic NSLocalizedString in Swift Source: https://context7.com/dral3x/stringslint/llms.txt Demonstrates the standard `NSLocalizedString` function in Swift for retrieving localized strings. Ensure the key 'screen_title' is present in your .strings file. ```swift // Basic NSLocalizedString let title = NSLocalizedString("screen_title", comment: "Main screen title") ``` -------------------------------- ### Configure Missing Rule Severity Source: https://context7.com/dral3x/stringslint/llms.txt Configure the severity level for the 'missing' rule in your StringLint configuration. You can also specify strings to ignore. ```yaml # Configuration missing: severity: error ignored: - debug_only_string ``` -------------------------------- ### Detect Missing Comments in Strings Files Source: https://context7.com/dral3x/stringslint/llms.txt StringLint flags strings in .strings files that lack a descriptive comment. 'undocumented_key' will trigger a violation because it is missing a comment. ```strings /* Localizable.strings */ /* This string has a proper comment */ "documented_key" = "Value with documentation"; "undocumented_key" = "Value without comment"; /* Triggers violation */ ``` -------------------------------- ### Standard NSLocalizedString Macro in Objective-C Source: https://context7.com/dral3x/stringslint/llms.txt Demonstrates the basic `NSLocalizedString` macro in Objective-C for retrieving localized strings. Ensure 'screen_title' is defined in your .strings file. ```objc // Basic NSLocalizedString NSString *title = NSLocalizedString(@"screen_title", @"Main screen title"); ``` -------------------------------- ### Configure Missing Comment Rule Severity Source: https://context7.com/dral3x/stringslint/llms.txt Configure the severity for the 'missing_comment' rule in your StringLint configuration. ```yaml # Configuration missing_comment: severity: warning ``` -------------------------------- ### Manage LocalizedString Models Source: https://context7.com/dral3x/stringslint/llms.txt Represent detected localized strings using the LocalizedString struct. ```swift import StringsLintFramework // LocalizedString structure let localizedString = LocalizedString( key: "welcome_message", // The localization key table: "Localizable", // The .strings file name value: "Welcome!", // Optional default value locale: Locale(identifier: "en"), // The locale location: location, // File location comment: "Welcome screen title" // Optional comment ) // Equality is based on key and table let string1 = LocalizedString(key: "key", table: "Main", value: nil, locale: .none, location: loc) let string2 = LocalizedString(key: "key", table: "Main", value: "Value", locale: .none, location: loc) print(string1 == string2) // true - same key and table ``` -------------------------------- ### SwiftUI Explicit Localization with LocalizedStringKey Source: https://context7.com/dral3x/stringslint/llms.txt Shows explicit localization in SwiftUI using `LocalizedStringKey`. The key 'explicit_key' is directly used for localization. ```swift import SwiftUI struct ExplicitView: View { var body: some View { VStack { // Explicit LocalizedStringKey Text(LocalizedStringKey("explicit_key")) // With table name Text("custom_key", tableName: "CustomStrings") // With comment Text("documented_key", tableName: "UI", comment: "Button label") } } } ``` -------------------------------- ### Ignore Specific Lines in Objective-C Source: https://context7.com/dral3x/stringslint/llms.txt Use the `// stringslint:ignore` comment to exclude specific lines from StringLint analysis in Objective-C code. ```objc // Objective-C - ignore this line NSString *debug = NSLocalizedString(@"debug_key", nil); // stringslint:ignore ``` -------------------------------- ### Linter Usage Source: https://context7.com/dral3x/stringslint/llms.txt The Linter class is the primary engine for processing files against a set of rules. ```APIDOC ## Linter Usage ### Description Executes linting on a collection of files using a provided set of rules. ### Method - **lintFiles([String]) -> Result<[Violation], Error>** ### Parameters - **rules** ([LintRule]): Array of rules to apply - **parallel** (Bool): Whether to run linting in parallel ### Response - **Success**: Returns an array of Violation objects - **Failure**: Returns an error if the linting process fails ``` -------------------------------- ### Ignore Specific Lines in Swift Source: https://context7.com/dral3x/stringslint/llms.txt Use the `// stringslint:ignore` comment to exclude specific lines from StringLint analysis in Swift code. ```swift // Swift - ignore this line let debug = NSLocalizedString("debug_key", comment: "") // stringslint:ignore // Also works with leading comment // stringslint:ignore let test = NSLocalizedString("test_key", comment: "") ``` -------------------------------- ### Manage Violation Models Source: https://context7.com/dral3x/stringslint/llms.txt Represent linting issues using the Violation struct, which supports Xcode-compatible output. ```swift import StringsLintFramework // Violation structure let violation = Violation( ruleDescription: MissingRule.description, severity: .error, location: Location(file: file, line: 42), reason: "Localized string \"missing_key\" is missing" ) // Generate Xcode-compatible output print(violation.description) // Output: /path/to/File.swift:42: error: Missing Violation: Localized string "missing_key" is missing (missing) ``` -------------------------------- ### NSLocalizedStringFromTable in Objective-C Source: https://context7.com/dral3x/stringslint/llms.txt Illustrates using `NSLocalizedStringFromTable` in Objective-C to specify a table name ('Errors') for localization. The key 'error_text' will be searched in 'Errors.strings'. ```objc // With table name NSString *error = NSLocalizedStringFromTable(@"error_text", @"Errors", @"Error message"); ``` -------------------------------- ### NSLocalizedString with Table Name in Swift Source: https://context7.com/dral3x/stringslint/llms.txt Shows how to use `NSLocalizedString` with a specific table name ('Errors') to load strings from a different .strings file. The key 'error_message' should be in 'Errors.strings'. ```swift // With table name let message = NSLocalizedString("error_message", tableName: "Errors", comment: "Generic error") ``` -------------------------------- ### NSLocalizedString with Value Fallback in Swift Source: https://context7.com/dral3x/stringslint/llms.txt Illustrates using `NSLocalizedString` with a `value` parameter, which serves as a default if the key is not found. 'missing_key' will use 'Default Value' if not present in 'Localizable.strings'. ```swift // With value fallback let fallback = NSLocalizedString("missing_key", tableName: "Localizable", value: "Default Value", comment: "Fallback text") ``` -------------------------------- ### NSLocalizedString with Nil Comment in Objective-C Source: https://context7.com/dral3x/stringslint/llms.txt Shows `NSLocalizedString` in Objective-C where the comment parameter is `nil`. StringLint still detects this as a valid localization call. ```objc // With nil comment NSString *message = NSLocalizedString(@"alert_message", nil); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.