Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Panel
borderColor#888888

Table of Contents

Table of Contents
indent16px


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:

Image Removed

To create a custom rule from a template, you will have to fill the following information을 가진 계정으로 로그인 한 경우, 다음의 2가지 액션을 수행할 수 있습니다:

  • 태그 삭제 및 추가:
    • 규칙의 기존 태그를 수정하거나, 새로운 태그를 추가할 수 있습니다(텍스트 필드에 새로운 이름을 입력합니다).
    • 일부 규칙의 기본 태그는 삭제할 수 없습니다 - 해당 태그들은 코딩 규칙을 제공하는 플러그인이 기본적으로 지정합니다.
  • 설명 확장
    • 코딩 규칙의 설명을 추가해서 규칙의 사용 목적을 더 잘 알릴 수 있습니다. 
    • 코딩 규칙의 설명은 admin 권한의 사용자가 아니어도 추가할 수 있습니다.

규칙 템플릿과 사용자 정의 규칙

규칙 템플릿(Rule Templates)는 플러그인에 의해 제공되며, 사용자들은 이를 사용해 사용자 규칙을 설정할 수 있습니다. 예를 들어, "Architectural Constraint" 템플릿을 사용해 특정 파일 셋이 다른 파일 셋에 접근하지 못하도록 확인하는 규칙을 생성할 수 있습니다.

규칙 템플릿은 새로운 "사용자 정의 규칙"을 쉽게 만들어낼 수 있도록 합니다. 템플릿은 Template Facet 메뉴에서 찾을 수 있습니다:

Image Added

템플릿을 사용해 사용자 정의 규칙을 생성하려면, 다음의 정보를 입력해야 합니다:

  • 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.

Image Removed

Custom Rules

Custom Rules are considered like any other rule, except that they can be fully edited or even deleted:

Image Removed

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규칙 템플릿에서 해당 템플릿을 사용해 생성한 사용자 규칙을 찾는 것은 매우 쉽습니다: "Custom Rules" 섹션의 링크를 클릭해, 세부 규칙으로 이동할 수 있습니다.

Image Added

사용자 정의 규칙

사용자 정의 규칙(Custom Rules)은 일반 코딩 규칙과 동일하게 적용됩니다. 다만 사용자 정의 규칙의 내용은 자유롭게 수정 및 삭제 가능합니다:

Image Added

사용자 정의 규칙을 삭제하는 경우, 해당 규칙은 SonarQube 인스턴스에서 완전히 삭제되는 것이 아니라 "REMOVED"로 상태만 변경됩니다. 해당 규칙과 관련된 이슈들은 이슈 자체가 제거될 때까지 SonarQube 인스턴스에 표시됩니다.

코딩 규칙 확장하기

사용자 정의 코딩 규칙을 추가할 수 있습니다. 보다 자세한 내용은 코딩 규칙 추가하기 페이지를 참조합니다.