# Quality standards and new code

### Defining a quality standard <a href="#defining-a-quality-standard" id="defining-a-quality-standard"></a>

SonarQube helps you improve code quality as you write by focusing on new code and applying consistent quality standards. As a developer, you focus on maintaining high standards for the code you add or change. SonarQube gives you the tools to enforce those standards and take pride in shipping maintainable and secure code.

## Understanding the benefits of focusing on new code <a href="#understanding-the-benefits-of-focusing-on-new-code" id="understanding-the-benefits-of-focusing-on-new-code"></a>

To get a visual representation of the benefits of focusing on new code based on the data in your projects:

1. Download and install the [Clean as You Code stats](https://github.com/SonarSource/sonar-cayc-stats-plugin?tab=readme-ov-file#installation) plugin.
2. In SonarQube, navigate to **More** > **Clean as You Code**.

## Focus on new code <a href="#focus-on-new-code" id="focus-on-new-code"></a>

By focusing on [Defining New Code](/sonarqube-server/8.9/project-administration/defining-new-code.md) (code that has been added or changed according to your new code definition), you can make sure the code you write today is maintainable and secure.

The [Defining New Code](/sonarqube-server/8.9/project-administration/defining-new-code.md) definition can be set at different levels (global, project, and, starting in [Developer Edition](https://www.sonarsource.com/plans-and-pricing/developer/), at the branch level). Depending on the level at which your new code definition is set, you can change the starting point to fit your situation.

For more information on setting your [Defining New Code](/sonarqube-server/8.9/project-administration/defining-new-code.md), check out [https://app.gitbook.com/s/okrRDNmcwFJDrkLkn0sz/project-administration/defining-new-code](https://app.gitbook.com/s/okrRDNmcwFJDrkLkn0sz/project-administration/defining-new-code "mention").

## Personal responsibility <a href="#personal-responsibility" id="personal-responsibility"></a>

By focusing on new code, you aren’t responsible for anyone else’s code. You own the quality and security of the code you are working on today. If you add new issues, SonarQube automatically assigns them to you so you can maintain the quality of your code.

For more information on issues and how they are assigned, check out the [Issues](/sonarqube-server/8.9/user-guide/issues.md) page.

## Quality gate <a href="#quality-gate" id="quality-gate"></a>

Your [Quality gates](/sonarqube-server/8.9/user-guide/quality-gates.md) is a set of conditions that tells you whether or not your project is ready for release. To support improving code quality as you write, your quality gate should:

* **Focus on New code metrics** – When your quality gate is set to focus on new code metrics (like the built-in Sonar way quality gate), new features will be delivered cleanly. As long as your quality gate is green, your releases will continue to improve.
* **Set and enforce high standards** – When standards are set and enforced on new code, you aren’t worried about having to meet those standards in old code and having to clean up someone else’s code. You can take pride in meeting high standards in *your* code. If a project doesn’t meet these high standards, it won’t pass the quality gate, and is therefore not ready to be released.

For more information on quality gates and to make sure your quality gate is enforcing your standards, check out the [https://app.gitbook.com/s/okrRDNmcwFJDrkLkn0sz/user-guide/quality-gates](https://app.gitbook.com/s/okrRDNmcwFJDrkLkn0sz/user-guide/quality-gates "mention") page.

## Pull request analysis <a href="#pull-request-analysis" id="pull-request-analysis"></a>

You can use pull request analysis and pull request decoration to make sure that your code meets your standards before merging. Pull request analysis lets you see your pull request’s quality gate in the SonarQube UI. You can then decorate your pull requests with SonarQube issues directly in your DevOps platform’s interface.

For more information on setting up pull request analysis and pull request decoration, see the documentation on[Pull request analysis](/sonarqube-server/8.9/analyzing-source-code/pull-request-analysis.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-server/8.9/user-guide/clean-as-you-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
