Overview
The article discusses the implementation of linting at Pinterest for their iOS codebase, focusing on the integration of Clang tools with their Bazel build system. It highlights the importance of coding consistency, the architecture of their custom linting tool called PINLinter, and specific linting rules that enhance code quality.
What You'll Learn
1
How to implement a custom linting tool using Clang Plugins
2
Why linting is critical for maintaining code quality in large teams
3
How to create and manage linter rules in a JSON configuration
4
When to use escape hatches in linting to bypass specific rules
Prerequisites & Requirements
- Understanding of C++ and Clang tooling
- Familiarity with Bazel build system(optional)
Key Questions Answered
What is the purpose of linting in a large codebase?
Linting helps maintain coding consistency and quality by analyzing code for potential errors, which is crucial in a collaborative environment with many developers. It provides immediate feedback during the compile process, ensuring adherence to best practices.
How does Pinterest implement linting in their iOS application?
Pinterest uses a custom linting tool called PINLinter, built as a Clang Plugin, which integrates with their Bazel build system. This allows them to enforce coding standards and provide real-time feedback to developers during compilation.
What are some examples of linting rules implemented at Pinterest?
Examples include preventing the use of 'assign' properties for Objective-C pointers and avoiding accessing view properties in initialization methods. These rules help maintain performance and prevent common coding mistakes.
What challenges did Pinterest face when implementing Clang plugins?
Pinterest encountered issues with the default Clang version in Xcode, which does not support plugins. They resolved this by using a custom-built Clang binary, ensuring compatibility with their linting infrastructure.
Technologies & Tools
Tooling
Clang
Used for building the custom linting tool, PINLinter, which integrates with the compilation process.
Build System
Bazel
Used as the build infrastructure for integrating the linting process.
Key Actionable Insights
1Implementing a custom linting tool can significantly improve code quality and developer efficiency.By integrating linting early in the development process, developers receive immediate feedback, which helps catch errors before they become larger issues.
2Utilizing Clang Plugins allows for more flexible and powerful linting capabilities.Clang's AST provides a detailed structure of the code, enabling the creation of sophisticated linting rules that can enforce specific coding standards.
3Maintaining a JSON configuration for linter rules simplifies management and customization.This approach allows teams to easily enable or disable rules based on different environments, such as development or production.
Common Pitfalls
1
Using the default Clang version in Xcode can lead to compatibility issues with plugins.
This can be avoided by using a custom-built Clang binary that supports the necessary features for linting.
Related Concepts
Clang Tooling
Linting Best Practices
Bazel Build System