realm / realm/SwiftLint

Rule Request: [nslocalizedstring_key] Expand existing rule to support alternate localization functions to be matched.

Open
#3,584 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
New rule request

Regarding: https://github.com/realm/SwiftLint/blob/master/Source/SwiftLintFramework/Rules/Lint/NSLocalizedStringKeyRule.swift

  1. Why should this rule be added?

The existing nslocalizedstring_key rule (NSLocalizedStringKeyRule) is useful however in some code bases alternate functions are used to support localization that follow the rule/pattern of NSLocalizedString. This is supported by the LOCALIZED_STRING_MACRO_NAMES build setting that Xcode uses to locate localization function that need to be process on language export.

For example in our code base we have the following build setting set that allows Xcode find and export localization keys used:

LOCALIZED_STRING_MACRO_NAMES = Localized.string Localized.text

The above matches against a set of swift static functions like the following which are value added wrappers around lower level Apple provided localization API:

//The following return a translated Swift.String

Localized.string("Hello World", comment:"main window title")

Localized.string("Welcome back %@ you have %@ worlds left to explore.", comment:"main window message", name, count)

//The following return a translated SwiftUI.Text

Localized.text("Hello World", comment:"main window title")

Localized.text("Welcome back %@ you have %@ worlds left to explore.", comment:"main window message", name, count)
  1. Provide several examples of what would and wouldn't trigger violations.

The existing rule will remain unchanged other then some how accepting a configuration that outlines one or more localization function prefixes that should be matched against in addition to NSLocalizedString.

  1. Should the rule be configurable, if so what parameters should be configurable?

Yes, a list of functions to match against when applying the rule.

  1. Should the rule be opt-in or enabled by default? Why?

Existing rule should remain unchanged in this regard.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Source/SwiftLintFramework/Rules/Lint/NSLocalizedStringKeyRule.swift, which is the existing rule named in the issue. Trace how it matches localization calls and how rule configuration is represented. Done means supporting a configurable list of additional localization function names or prefixes while preserving the existing NSLocalizedString behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.