Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update public README #261

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 18 additions & 194 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

**[WEBSITE](https://sourcery.ai/) | [DOCS](https://docs.sourcery.ai/Welcome/) | [BUGS](https://github.com/sourcery-ai/sourcery/issues)**

Sourcery is the pair programmer who will help you improve your code. It reviews and improves your code automatically so you can spend more time focused on writing new code and less time cleaning things up.
Sourcery is your pair programmer that reviews and enhances your code in real-time. With intelligent code reviews and an AI chat assistant that understands your code, you can ship better code faster.

![Sourcery in VS Code](https://raw.githubusercontent.com/sourcery-ai/sourcery-vscode/main/assets/Sourcery_VS_Code_Example.gif)

Expand All @@ -25,39 +25,50 @@ Sourcery is a VS Code extension to help you move faster and ship code with confi

Here are some of the features Sourcery offers to help improve your code:

- [Chat with an AI that knows about your code](#chat)
- [Code reviews anytime, in IDE](#code-reviews-on-demand)
- [GitHub & GitLab Pull Request reviews](#github-pull-request-review)
Hellebore marked this conversation as resolved.
Show resolved Hide resolved
- [Real-time refactoring suggestions](#real-time-refactoring-suggestions)
- [Set up your own rules - or use public rulesets](#set-up-your-own-rules---or-use-public-rulesets)
- [Continuous code quality feedback](#continuous-code-quality-feedback)



To start using Sourcery on your code, check out our [Getting Started guide](https://docs.sourcery.ai/getting-started/).

Check out our [documentation](https://docs.sourcery.ai/Welcome/) for more information on how to use Sourcery.

Sourcery is free to use for open source projects.

To use Sourcery on non open sourced projects you'll need a Sourcery Pro or Sourcery Team subscription. To get a 14 day free trial to Sourcery Pro, **[sign up for an account on the Sourcery site](https://sourcery.ai/signup/?product=prod_pro&utm_source=VS-Code)**.
To use Sourcery on non open-sourced projects you'll need a Sourcery Pro subscription. To get a 14 day free trial to Sourcery Pro, **[sign up for an account on the Sourcery site](https://app.sourcery.ai/dashboard/subscription?utm_source=vscode_marketplace&utm_medium=web&utm_campaign=vscode_marketplace)**.

---

## Features

### Chat

![Generating documentation](https://raw.githubusercontent.com/sourcery-ai/sourcery-vscode/main/assets/docstring_generation.png)

Talk with an AI that knows about your code. Select code to add it to context and ask questions or ask for improvements. Apply code changes with a single click.

Sourcery Chat comes with in-built recipes to:
- Generate diagrams: No need to spend hours manually creating diagrams. Sourcery can generate them for you in Mermaid format - grab the code or view it as an image.
- Generate Tests: Generate comprehensive unit tests for your code.
- Generate docstrings: Sourcery can generate docstrings for your code, copying the style from your existing docstrings. Add them to your code with a single click.
- Explain code: Sourcery can explain your code, point out how it works and anything unusual or not idiomatic.

### Code reviews on demand

![Sourcery Code Reviews](https://raw.githubusercontent.com/sourcery-ai/sourcery-vscode/main/assets/code_review.png)

Get feedback on your code anytime you want. Sourcery can review your code directly in your IDE, looking at the branch you're currently on or the uncommitted changes you have.

Get feedback on your code anytime you want. Sourcery can review your code directly in your IDE and give you instant actionable feedback.
Review your current file, your uncommitted changes, or compare any two Git branches. Individual review comments are shown inline in your code, along with suggested fixes if applicable.


### GitHub & GitLab Pull Request Review

![Sourcery Reviewing GitHub PRs](https://raw.githubusercontent.com/sourcery-ai/sourcery-vscode/main/assets/Sourcery_Code_Review.gif)

Sourcery can help you speed up code reviews and clean up every new commit by automatically reviewing each of your GitHub pull requests.
Sourcery can help you speed up code reviews and clean up every new commit by automatically reviewing each of your GitHub pull requests. This also gives you a PR summary, can generate PR titles, and posts a reviewers guide to the PR, including diagrams and a breakdown of the changes.

To get started, add [Sourcery to your GitHub repo](https://github.com/apps/sourcery-ai/installations/new) or [GitLab project](https://app.sourcery.ai/login?connection=gitlab). Sourcery will then start reviewing every new pull request automatically!

Expand Down Expand Up @@ -109,193 +120,6 @@ Sourcery gives each of your functions a quality score ranging from 0% (bad) - 10

Sourcery will warn you if your overall quality score for a function falls below 25%.

### Multi-File Analysis

![Multi-File Analysis & Refactoring in Sourcery](https://raw.githubusercontent.com/sourcery-ai/sourcery-vscode/main/assets/Sourcery_Example_Full_Project_Scan_VS_Code.gif)

You can use Sourcery to review a single file, a folder, or your whole project at once.

Right-click on any item in the Explorer window and select "Sourcery → Scan for Refactorings". Sourcery will show you a notification when the scan is done & will show all of the suggestions it found in the Problems window.

### Duplicate Code Detection

![Duplicate Code Detection in Sourcery](https://raw.githubusercontent.com/sourcery-ai/sourcery-vscode/main/assets/Sourcery_Example_Duplicates_VS_Code.gif)

Sourcery can help you find duplicate code and near-duplicate code across your whole project.

Right-click on any item in the Explorer window and select "Sourcery → Detect Clones". Sourcery will show you a notification when it's done scanning for clones & will show you all of the instances of duplication it found in the Problems window.

By default, Sourcery will flag items where at least 3 lines are duplicates or near-duplicates that occur at least twice in the scanned files.

---

## Configuring Sourcery

Not everyone's coding style is the same, so we know you won't always want to accept every refactoring Sourcery suggests.

Sourcery reads [configuration settings from two sources](https://docs.sourcery.ai/Reference/Configuration/Sources/#configuration-sources):

- a [`.sourcery.yaml` file](https://docs.sourcery.ai/Reference/Configuration/sourcery-yaml/) in the project directory; and
- a [user-specific config file](https://docs.sourcery.ai/Reference/Configuration/Sources/#user-configuration-file-system-locations).

You can use the project-specific config file to set project-specific settings, and the user-specific config file to set settings that apply to all projects. The project-specific configuration takes precedence over the user configuration.

The config file uses YAML syntax. If you are new to YAML check out "[Learn YAML in 5 minutes](https://www.codeproject.com/Articles/1214409/Learn-YAML-in-five-minutes)".

Here is the default set of values set for the file. If a config file isn't set or if a setting isn't specified then Sourcery will use these values:

```yaml
ignore: []

rule_settings:
enable: [default]
disable: []
rule_types:
- refactoring
- suggestion
- comment
python_version: '3.9'

rules: []

metrics:
quality_threshold: 25.0

github:
labels: []
ignore_labels:
- sourcery-ignore
request_review: author
sourcery_branch: sourcery/{base_branch}

clone_detection:
min_lines: 3
min_duplicates: 2
identical_clones_only: false

proxy:
no_ssl_verify: false
```

You can easily configure Sourcery to:

- [Only show certain types of suggestions](#choosing-which-rules-to-be-shown)
- [Not show suggestions on certain files, paths, or functions](#skip-suggestions)

### Choosing which rules to be shown

You can choose to have Sourcery never show you a specific type of rule by adding it to a list under the `refactor: skip` section of the .sourcery.yaml file. Just add in the rule ID for the rule you don't want to see and Sourcery will stop suggesting it.

Individual ids are displayed in the plugin suggestions and GitHub Bot comments for easy lookup or you can find a full list in the [refactorings section](https://docs.sourcery.ai/refactorings/) of the docs.

For example:

```
refactor:
skip:
- assign-if-exp
- de-morgan
```

Would mean that the Assign If Expression & De Morgan's Identity refactorings are never shown.

To make this even easier, we’ve set up the Sourcery Hub. Click on the Sourcery button in the status bar to bring up the Hub, click on settings, and you can toggle on and off individual types of suggestions

### Skip suggestions

You can also choose to have Sourcery not review specific files, paths, or individual functions.

To ignore a path or a file, add the paths or files as items in a list underneath the `ignore` setting in the `.sourcery.yaml` file.

For example:

```
ignore:
- data/*
- .venv/*
- '*_test.py' # Note that any strings beginning with * must be quoted
```

If you want to just ignore a specific function you can add a `# sourcery skip` comment next to the line declaring the function and Sourcery will ignore that function.

```
def func(a,b): #sourcery skip
if a < b:
min_value = a
else:
min_value = b
c = min_value ** 2
return c
```

If you want to ignore specific refactorings in a function you can add in `# sourcery skip: <refactoring id 1>, <refactoring id 2>` where each ID is from our list of available refactorings.

```
def func(a,b):
if a < b: #sourcery skip: inline-immediately-returned-variable
min_value = a
else:
min_value = b
c = min_value ** 2
return c
```


---

## Example Code

We've put together a handful of examples if you want to play around with Sourcery and see a bit more what it can do:

```
def list_comprehension(list, filter, func):
new_list = list()
for i in list:
if filter(i):
new_list.append(func(i))
return new_list


def augmented_assignment():
a = 0
a = a + 1
print(a)


def sort_out_return():
if something == other_thing:
return True
return False


def dictionary_get():
dictionary = {}
data = ""
if "message" in dictionary:
data = dictionary["message"]
```

Here is an example where Sourcery would chain together multiple refactorings:

```
def enable_local(self, opt):
if opt == ECHO:
return True
elif opt == SGA:
return True
else:
return False


def __getstate__(self):
state = {}
state['min'] = self.min
state['max'] = self.max
return state
```

Copy these examples into a Python file to see how Sourcery would handle them.


---

Expand Down
Binary file modified assets/Sourcery_VS_Code_Example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/code_review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/docstring_generation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading