Settings

Theme

Show HN: Sourcery – Automated Refactoring for Python

sourcery.ai

4 points by brendanator 5 years ago · 1 comment

Reader

brendanatorOP 5 years ago

Hi HN! We're Brendan, Nick and Tim — founders of Sourcery.

We're building the most advanced refactoring tool in the world. Most refactoring tools require the user to decide what refactorings to make. Sourcery turns that around and proposes refactorings to you according to its own code quality metrics. It can also do far more advanced refactorings than anything else out there.

The way it works is inspired by how an expert refactors code. They make lots of small changes, each of which slightly improves the quality of the code while keeping the functionality the same. Sourcery has a large library of small, correct refactorings that it composes together to produce larger ones. It uses code quality metrics to guide its search through the possible combinations of these refactorings to find the best overall change. We use a mix of standard metrics, like code size and cognitive complexity, along with some of our own custom metrics which capture what we think is important to high quality code.

Sourcery is currently available for Python and can be used in:

- PyCharm, VSCode and Vim where it refactors the current file you have open

- GitHub where it acts as a code review tool on PRs, suggesting refactorings and scoring the code changes with our code quality metrics

- A CLI which allows it be used as a pre-commit hook or in a CI pipeline

The next step for to start proposing refactorings at the class level, such as extracting methods to remove duplicated code. Then we will add machine learning based refactorings to capture more niche improvements that can be made when using libraries outside the standard library.

Give us a try!

You can also get an instant demo by starring this repo https://github.com/sourcery-ai/sourcery and our GitHub bot will refactor your most starred Python GitHub repo.

We would love to hear your thoughts, feedback and suggestions on how can we improve!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection