From 8967d436fb6a55ab57a60134e579b6f40bb247a1 Mon Sep 17 00:00:00 2001 From: 7PH Date: Tue, 18 Apr 2023 16:15:49 +0200 Subject: [PATCH] SONAR-19069 Add issue characteristic enum for Clean Code Taxonomy --- .../__snapshots__/SourceViewer-test.tsx.snap | 2 ++ .../__snapshots__/LineIssueList-test.tsx.snap | 1 + .../src/main/js/helpers/testMocks.ts | 11 +++++- server/sonar-web/src/main/js/types/issues.ts | 35 +++++++++++++++++++ server/sonar-web/src/main/js/types/types.ts | 3 +- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewer-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewer-test.tsx.snap index 8688bd62ed3..420f1357cde 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewer-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewer-test.tsx.snap @@ -77,6 +77,7 @@ exports[`should render correctly 1`] = ` [ { "actions": [], + "characteristic": "ROBUST", "component": "main.js", "componentEnabled": true, "componentLongName": "main.js", @@ -113,6 +114,7 @@ exports[`should render correctly 1`] = ` "26": [ { "actions": [], + "characteristic": "ROBUST", "component": "main.js", "componentEnabled": true, "componentLongName": "main.js", diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineIssueList-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineIssueList-test.tsx.snap index 11e954e8499..ed924c9d241 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineIssueList-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineIssueList-test.tsx.snap @@ -17,6 +17,7 @@ exports[`should render issues 1`] = ` issue={ { "actions": [], + "characteristic": "ROBUST", "component": "main.js", "componentEnabled": true, "componentLongName": "main.js", diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index c5646eff516..0e67606bdb6 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -26,7 +26,14 @@ import { Location, Router } from '../components/hoc/withRouter'; import { AppState } from '../types/appstate'; import { RuleRepository } from '../types/coding-rules'; import { EditionKey } from '../types/editions'; -import { IssueScope, IssueSeverity, IssueStatus, IssueType, RawIssue } from '../types/issues'; +import { + IssueCharacteristic, + IssueScope, + IssueSeverity, + IssueStatus, + IssueType, + RawIssue, +} from '../types/issues'; import { Language } from '../types/languages'; import { Notification } from '../types/notifications'; import { DumpStatus, DumpTask } from '../types/project-dump'; @@ -296,6 +303,7 @@ export function mockRawIssue(withLocations = false, overrides: Partial severity: IssueSeverity.Major, status: IssueStatus.Open, textRange: { startLine: 25, endLine: 26, startOffset: 0, endOffset: 15 }, + characteristic: IssueCharacteristic.Clear, type: IssueType.CodeSmell, transitions: [], scope: IssueScope.Main, @@ -324,6 +332,7 @@ export function mockRawIssue(withLocations = false, overrides: Partial export function mockIssue(withLocations = false, overrides: Partial = {}): Issue { const issue: Issue = { actions: [], + characteristic: IssueCharacteristic.Robust, component: 'main.js', componentEnabled: true, componentLongName: 'main.js', diff --git a/server/sonar-web/src/main/js/types/issues.ts b/server/sonar-web/src/main/js/types/issues.ts index 3e96f1cf3c7..04ec365eaf1 100644 --- a/server/sonar-web/src/main/js/types/issues.ts +++ b/server/sonar-web/src/main/js/types/issues.ts @@ -29,6 +29,40 @@ export enum IssueType { SecurityHotspot = 'SECURITY_HOTSPOT', } +export enum IssueCharacteristic { + Clear = 'CLEAR', + Consistent = 'CONSISTENT', + Structured = 'STRUCTURED', + Tested = 'TESTED', + Robust = 'ROBUST', + Secure = 'SECURE', + Portable = 'PORTABLE', + Compliant = 'COMPLIANT', +} + +export enum IssueCharacteristicFitFor { + Production = 'PRODUCTION', + Development = 'DEVELOPMENT', +} + +export const ISSUE_CHARACTERISTIC_TO_FIT_FOR = { + [IssueCharacteristic.Clear]: IssueCharacteristicFitFor.Development, + [IssueCharacteristic.Consistent]: IssueCharacteristicFitFor.Development, + [IssueCharacteristic.Structured]: IssueCharacteristicFitFor.Development, + [IssueCharacteristic.Tested]: IssueCharacteristicFitFor.Development, + [IssueCharacteristic.Robust]: IssueCharacteristicFitFor.Production, + [IssueCharacteristic.Secure]: IssueCharacteristicFitFor.Production, + [IssueCharacteristic.Portable]: IssueCharacteristicFitFor.Production, + [IssueCharacteristic.Compliant]: IssueCharacteristicFitFor.Production, +}; + +export const ISSUE_TYPE_TO_CHARACTERISTIC = { + [IssueType.Bug]: IssueCharacteristic.Robust, + [IssueType.CodeSmell]: IssueCharacteristic.Clear, + [IssueType.SecurityHotspot]: IssueCharacteristic.Secure, + [IssueType.Vulnerability]: IssueCharacteristic.Secure, +}; + // Keep this enum in the correct order (most severe to least severe). export enum IssueSeverity { Blocker = 'BLOCKER', @@ -127,6 +161,7 @@ export interface RawIssue { severity: string; status: string; textRange?: TextRange; + characteristic: IssueCharacteristic; type: IssueType; scope: string; ruleDescriptionContextKey?: string; diff --git a/server/sonar-web/src/main/js/types/types.ts b/server/sonar-web/src/main/js/types/types.ts index 29415171dfd..a67d5360d49 100644 --- a/server/sonar-web/src/main/js/types/types.ts +++ b/server/sonar-web/src/main/js/types/types.ts @@ -19,7 +19,7 @@ */ import { RuleDescriptionSection } from '../apps/coding-rules/rule'; import { ComponentQualifier, Visibility } from './component'; -import { MessageFormatting } from './issues'; +import { IssueCharacteristic, MessageFormatting } from './issues'; import { UserActive, UserBase } from './users'; export type Dict = { [key: string]: T }; @@ -246,6 +246,7 @@ export interface Issue { assigneeName?: string; author?: string; branch?: string; + characteristic: IssueCharacteristic; comments?: IssueComment[]; component: string; componentEnabled?: boolean; -- 2.39.5