SQ Official Doc Link: https://docs.sonarqube.org/display/SONAR/Rules
Table of Contents
SonarQube 플랫폼에서, 플러그인은 소스 코드를 분석하고 이슈를 생성하는 코딩 규칙을 제공합니다. 이 이슈들은 이슈 완화 비용과 기술 부채를 계산하기 위한 자료로 사용됩니다. SonarQube는 세가지 종류의 코딩 규칙을 제공합니다:
- 신뢰성(Reliability)
- 유지보수성(Maintainability)
- 보안성(Security)
이 중 신뢰성과 유지보수성 관련 코딩 규칙은 zero false positive가 기대되며, 보안성 관련 코딩 규칙은 약간의 false positive를 생성할 수 있습니다. Rules 페이지에서 적용 가능한 모든 코딩 규칙들을 살펴볼 수 있으며, 제공하는 템플릿을 기반으로 새로운 코딩 규칙을 생성할 수 있습니다.
코딩 규칙 찾기
"Rules" 메뉴를 클릭하면, 코딩 규칙 페이지로 이동합니다. 기본적으로 적용 가능한 코딩 규칙들을 표시하며, 화면 왼쪽의 검색 기준으로 원하는 코딩 규칙들을 필터링할 수 있습니다:
- Language: 해당 규칙을 적용할 프로그래밍 언어
- Type: 버그(Bug), 취약점(Vulnerability) 혹은 코드 냄새(Code Smell) 코딩 규칙
- Tag: 보다 쉬운 검색을 위해 코딩 규칙에 태그 추가 가능
- Repository: SonarQube에 코딩 규칙을 제공하는 분석 엔진
- Default Severity: 해당 코딩 규칙의 기본 심각도 - 코딩 규칙을 제공하는 플러그인이 정의함
- Status: 코딩 규칙은 다음의 3가지 상태를 가짐:
- Beta: 최근에 구현된 코딩 규칙으로, 사용자들의 충분한 피드백을 얻지 못했으며 다수의 false positive/ false negative 이슈를 검출할 수 있음
- Deprecated: 해당 규칙과 비슷하거나 정확한 규칙이 존재하여, 더 이상 사용해서는 안되는 코딩 규칙
- Ready: 프로덕션에서 실제로 사용 가능한 코딩 규칙
- Available Since: 해당 코딩 규칙이 처음으로 SonarQube 인스턴스에 추가된 날짜. 플러그인 업데이트 이후 추가된 신규 코딩 규칙을 확인하고자 할 때 유용함
- Template: 사용자 정의 코딩 규칙을 생성할 수 있는 규칙 템플릿을 표시함(본 페이지에서 다시 설명)
- Quality Profile: 특정 품질 프로파일 내 포함/ 미포함을 기준으로 검색
품질 프로파일을 선택하면 해당 프로파일 내 코딩 규칙의 활성화 된 심각도 미 해당 프로파일의 상속 여부를 확인할 수 있습니다. 더 자세한 정보는 품질 프로파일 페이지를 참조합니다.
Rule Details
To see the details of a rule, either click on it, or use the right arrow key. Along with basic rule data, you'll also be able to see which, if any, profiles it's active in and how many open issues have been raised with it.
The 2 following actions are available only if you have the right permissions ("Administer Quality Profiles and Gates"):
- Add/Remove Tags:
- It is possible to add existing tags on a rule, or to create new ones (just enter a new name while typing in the text field).
- Note that some rules have built-in tags that you cannot remove - they are provided by the plugins which contribute the rules.
- Extend Description:
- Extending rule descriptions is useful to let users know how your organization is using a particular rule for instance or to give more insight on a rule.
- Note that the extension will be available to non-admin users as a normal part of the rule details.
Rule Templates and Custom Rules
Rule Templates are provided by plugins to allow users to define their own rules in SonarQube. For instance, the template "Architectural Constraint" can be used to create any kind of rule that checks forbidden access from a set of file to another set of files.
Rule templates are like cookie cutters from which you can stamp out new, "custom rules". To find templates, use the template facet:
To create a custom rule from a template, you will have to fill the following information:
- Name
- Key (auto-suggested)
- Description (Markdown format is supported)
- Default Severity
- Status
- The parameters specified by the template
It's easy to navigate from a template to the custom rules defined from it: just click on the link in the "Custom Rules" section and you will end up on the details of the given rule.
Custom Rules
Custom Rules are considered like any other rule, except that they can be fully edited or even deleted:
Note that when deleting a custom rule, it is not physically removed from the SonarQube instance but rather its status is set to "REMOVED". This allows current or old issues related to this rule to be displayed properly in SonarQube until they are fully removed.
Extending Coding Rules
Custom coding rules can be added. See Adding Coding Rules for detailed information and tutorials.