A tool for refactoring code related to feature flag APIs
A tool for refactoring code related to feature flag APIs
PolyglotPiranha is a lightweight code transformation toolset for automating large scale changes. At Uber, it is mostly used to clean up stale feature flags.
We only support languages that are used at Uber. We likely won't be able to add new languages in this repo. There are a number of forks (see https://github.com/uber/piranha/forks for a full list) that may provide additional features.
To install Polyglot Piranha, you can use it as a Python library or as a command-line tool.
To install the Python API, run the following command:
pip install polyglot-piranha
To install the command-line interface, follow these steps:
git clone https://github.com/uber/piranha.gitcd piranhacargo build --release (or cargo build --release --no-default-features for macOS)target/release…
For more examples and explanations of the toolset, please check our demos and extended POLYGLOT_README.md file.
Feature flags are commonly used to enable gradual rollout or experiment with new features. In a few cases, even after the purpose of the flag is accomplished, the code pertaining to the feature flag is not removed. We refer to such flags as stale flags. The presence of code pertaining to stale flags can have the following drawbacks:
PolyglotPiranha is a tool that can automatically refactor code related to stale flags. At a higher level, the input to the tool is the name of the flag and the expected behavior, after specifying a list of APIs related to flags in a properties file. Piranha will use these inputs to automatically refactor the code according to the expected behavior.
PolyglotPiranha (as of May 2022) is a common refactoring tool to support multiple languages and feature flag APIs. For legacy language-specific implementations please check following tag.
A few additional links on Piranha:
If you have any questions on how to use Piranha or find any bugs, please open a GitHub issue.
Piranha uses several grammar repositories with custom patches to support the transformations. While these patches are being upstreamed, there may be discrepancies between the grammars in this repository and the upstream grammars. Therefore, we have built a custom tree-sitter playground that can be used to test the grammars and queries for easier development:
https://uber.github.io/piranha/tree-sitter-playground/
Piranha is licensed under the Apache 2.0 license. See the LICENSE file for more information.
This is not an official Uber product, and provided as is.
No open issues yet, or sync has not completed.