Skip to content

Coding Styles and Standards

CMasterson edited this page Aug 17, 2023 · 2 revisions

Code Style

We try to maintain a set style to ensure code readability across the Pocket code base.

You can read about or style guide here

As mentioned in the above article, we use SwiftLint to help enforce our style guides. Do note that we are moving to a shared rule set with the Firefox iOS team, so we can't just make whatever changes we want without consulting Firefox to align. Swiftlint issues are always build errors and should not be committed as the CI will fail.

You can run swiftlint autocorrect in Terminal if you are feeling lucky.

Logging & Analytics

We can broadly differentiate Logging and Analytics based on how we intend to use the reports that they can generate.

  • Logging is used to provide the developer with actionable information or context to support actionable information.
  • Analytics are used to provide business data around how our users are interacting with the app, to highlight pain-points, adoption of features and justify spending time improving different areas of the app.

Logging in Pocket covers what, why and how we log issues.

Localization

Pocket localization is handled by Smartling. The project is currently setup in Single Branch Mode against the develop branch. Everytime a commit is made to develop Smartling will analyze the branch and determine if it needs to start a translation job. If it does, it will begin automatically and make a PR back against the repo with the needed translations. Occasionally our translators may have a question or need some alterations to unblock their work. You can check in the Smartling Dashboard for these queries.

Adding Strings

Pocket uses swiftgen to generate a Strings.swift file from our English Localizable.strings file.

Moving forward we will use a reverse dns pattern for String keys. e.g. "search.results.empty.header" = "No results found";

To make a new string follow the following steps:

  1. Ensure you have swiftgen installed (brew install swiftgen)
  2. Add your string to Localizable.strings Note: If you add a comment above the string, it will be included for the Smartling translators and is useful if a word translated has different transalations based on the usage.
  3. Either a) Build the project or b) run swiftgen from the root of the Pocket project directory
  4. The new string enum should be available in the Localization enum for you to use.
  5. Once your PR lands in develop watch as Smartling will pick it up and translate it.

Exclusions

In general we want to avoid localizing feature names. "Collections" is a prime example.