Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

issues.ts 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { keyBy, times } from 'lodash';
  21. import { mockSnippetsByComponent } from '../../../helpers/mocks/sources';
  22. import { mockLoggedInUser, mockRawIssue } from '../../../helpers/testMocks';
  23. import {
  24. CleanCodeAttributeCategory,
  25. SoftwareImpactSeverity,
  26. SoftwareQuality,
  27. } from '../../../types/clean-code-taxonomy';
  28. import {
  29. IssueActions,
  30. IssueDeprecatedStatus,
  31. IssueResolution,
  32. IssueScope,
  33. IssueSeverity,
  34. IssueStatus,
  35. IssueTransition,
  36. IssueType,
  37. RawIssue,
  38. } from '../../../types/issues';
  39. import { Dict, FlowType, SnippetsByComponent } from '../../../types/types';
  40. import {
  41. ISSUE_0,
  42. ISSUE_1,
  43. ISSUE_101,
  44. ISSUE_11,
  45. ISSUE_1101,
  46. ISSUE_1102,
  47. ISSUE_1103,
  48. ISSUE_2,
  49. ISSUE_3,
  50. ISSUE_4,
  51. ISSUE_TO_FILES,
  52. ISSUE_TO_RULE,
  53. PARENT_COMPONENT_KEY,
  54. } from './ids';
  55. export interface IssueData {
  56. issue: RawIssue;
  57. snippets: Dict<SnippetsByComponent>;
  58. }
  59. export function mockIssuesList(baseComponentKey = PARENT_COMPONENT_KEY): IssueData[] {
  60. return [
  61. {
  62. issue: mockRawIssue(false, {
  63. key: ISSUE_101,
  64. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_101][0]}`,
  65. creationDate: '2023-01-05T09:36:01+0100',
  66. message: 'Issue with no location message',
  67. cleanCodeAttributeCategory: CleanCodeAttributeCategory.Consistent,
  68. type: IssueType.Vulnerability,
  69. rule: ISSUE_TO_RULE[ISSUE_101],
  70. textRange: {
  71. startLine: 10,
  72. endLine: 10,
  73. startOffset: 0,
  74. endOffset: 2,
  75. },
  76. flows: [
  77. {
  78. locations: [
  79. {
  80. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_101][0]}`,
  81. textRange: {
  82. startLine: 1,
  83. endLine: 1,
  84. startOffset: 0,
  85. endOffset: 1,
  86. },
  87. },
  88. ],
  89. },
  90. {
  91. locations: [
  92. {
  93. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_101][1]}`,
  94. textRange: {
  95. startLine: 20,
  96. endLine: 20,
  97. startOffset: 0,
  98. endOffset: 1,
  99. },
  100. },
  101. ],
  102. },
  103. ],
  104. resolution: IssueResolution.WontFix,
  105. scope: IssueScope.Main,
  106. tags: ['tag0', 'tag1'],
  107. }),
  108. snippets: keyBy(
  109. [
  110. mockSnippetsByComponent(
  111. ISSUE_TO_FILES[ISSUE_101][0],
  112. baseComponentKey,
  113. times(40, (i) => i + 1),
  114. ),
  115. mockSnippetsByComponent(
  116. ISSUE_TO_FILES[ISSUE_101][1],
  117. baseComponentKey,
  118. times(40, (i) => i + 1),
  119. ),
  120. ],
  121. 'component.key',
  122. ),
  123. },
  124. {
  125. issue: mockRawIssue(false, {
  126. key: ISSUE_11,
  127. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_11][0]}`,
  128. creationDate: '2022-01-01T09:36:01+0100',
  129. message: 'FlowIssue',
  130. type: IssueType.CodeSmell,
  131. severity: IssueSeverity.Minor,
  132. rule: ISSUE_TO_RULE[ISSUE_11],
  133. textRange: {
  134. startLine: 10,
  135. endLine: 10,
  136. startOffset: 0,
  137. endOffset: 2,
  138. },
  139. flows: [
  140. {
  141. type: FlowType.DATA,
  142. description: 'Backtracking 1',
  143. locations: [
  144. {
  145. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_11][0]}`,
  146. msg: 'Data location 1',
  147. textRange: {
  148. startLine: 20,
  149. endLine: 20,
  150. startOffset: 0,
  151. endOffset: 1,
  152. },
  153. },
  154. {
  155. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_11][0]}`,
  156. msg: 'Data location 2',
  157. textRange: {
  158. startLine: 21,
  159. endLine: 21,
  160. startOffset: 0,
  161. endOffset: 1,
  162. },
  163. },
  164. ],
  165. },
  166. {
  167. type: FlowType.EXECUTION,
  168. locations: [
  169. {
  170. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_11][1]}`,
  171. msg: 'Execution location 1',
  172. textRange: {
  173. startLine: 20,
  174. endLine: 20,
  175. startOffset: 0,
  176. endOffset: 1,
  177. },
  178. },
  179. {
  180. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_11][1]}`,
  181. msg: 'Execution location 2',
  182. textRange: {
  183. startLine: 22,
  184. endLine: 22,
  185. startOffset: 0,
  186. endOffset: 1,
  187. },
  188. },
  189. {
  190. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_11][1]}`,
  191. msg: 'Execution location 3',
  192. textRange: {
  193. startLine: 5,
  194. endLine: 5,
  195. startOffset: 0,
  196. endOffset: 1,
  197. },
  198. },
  199. ],
  200. },
  201. ],
  202. tags: ['tag1'],
  203. }),
  204. snippets: keyBy(
  205. [
  206. mockSnippetsByComponent(
  207. ISSUE_TO_FILES[ISSUE_11][0],
  208. baseComponentKey,
  209. times(40, (i) => i + 1),
  210. ),
  211. mockSnippetsByComponent(
  212. ISSUE_TO_FILES[ISSUE_11][1],
  213. baseComponentKey,
  214. times(40, (i) => i + 1),
  215. ),
  216. ],
  217. 'component.key',
  218. ),
  219. },
  220. {
  221. issue: mockRawIssue(false, {
  222. key: ISSUE_0,
  223. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_0][0]}`,
  224. message: 'Issue on file',
  225. assignee: mockLoggedInUser().login,
  226. rule: ISSUE_TO_RULE[ISSUE_0],
  227. textRange: undefined,
  228. line: undefined,
  229. scope: IssueScope.Test,
  230. }),
  231. snippets: {},
  232. },
  233. {
  234. issue: mockRawIssue(false, {
  235. key: ISSUE_1,
  236. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_1][0]}`,
  237. message: 'Fix this',
  238. type: IssueType.Vulnerability,
  239. scope: IssueScope.Test,
  240. rule: ISSUE_TO_RULE[ISSUE_1],
  241. textRange: {
  242. startLine: 10,
  243. endLine: 10,
  244. startOffset: 0,
  245. endOffset: 2,
  246. },
  247. flows: [
  248. {
  249. locations: [
  250. {
  251. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_1][0]}`,
  252. msg: 'location 1',
  253. textRange: {
  254. startLine: 1,
  255. endLine: 1,
  256. startOffset: 0,
  257. endOffset: 1,
  258. },
  259. },
  260. ],
  261. },
  262. {
  263. locations: [
  264. {
  265. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_1][0]}`,
  266. msg: 'location 2',
  267. textRange: {
  268. startLine: 50,
  269. endLine: 50,
  270. startOffset: 0,
  271. endOffset: 1,
  272. },
  273. },
  274. ],
  275. },
  276. ],
  277. }),
  278. snippets: keyBy(
  279. [
  280. mockSnippetsByComponent(
  281. ISSUE_TO_FILES[ISSUE_1][0],
  282. baseComponentKey,
  283. times(80, (i) => i + 1),
  284. ),
  285. mockSnippetsByComponent(
  286. ISSUE_TO_FILES[ISSUE_1][0],
  287. baseComponentKey,
  288. times(80, (i) => i + 1),
  289. ),
  290. ],
  291. 'component.key',
  292. ),
  293. },
  294. {
  295. issue: mockRawIssue(false, {
  296. key: ISSUE_2,
  297. actions: Object.values(IssueActions),
  298. transitions: [
  299. IssueTransition.Accept,
  300. IssueTransition.Confirm,
  301. IssueTransition.Resolve,
  302. IssueTransition.FalsePositive,
  303. IssueTransition.WontFix,
  304. ],
  305. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_2][0]}`,
  306. message: 'Fix that',
  307. rule: ISSUE_TO_RULE[ISSUE_2],
  308. textRange: {
  309. startLine: 25,
  310. endLine: 25,
  311. startOffset: 0,
  312. endOffset: 1,
  313. },
  314. impacts: [
  315. { softwareQuality: SoftwareQuality.Security, severity: SoftwareImpactSeverity.High },
  316. ],
  317. resolution: IssueResolution.Unresolved,
  318. status: IssueDeprecatedStatus.Open,
  319. issueStatus: IssueStatus.Open,
  320. ruleDescriptionContextKey: 'spring',
  321. }),
  322. snippets: keyBy(
  323. [
  324. mockSnippetsByComponent(
  325. ISSUE_TO_FILES[ISSUE_2][0],
  326. baseComponentKey,
  327. times(40, (i) => i + 20),
  328. ),
  329. ],
  330. 'component.key',
  331. ),
  332. },
  333. {
  334. issue: mockRawIssue(false, {
  335. key: ISSUE_3,
  336. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_3][0]}`,
  337. message: 'Second issue',
  338. rule: ISSUE_TO_RULE[ISSUE_3],
  339. textRange: {
  340. startLine: 28,
  341. endLine: 28,
  342. startOffset: 0,
  343. endOffset: 1,
  344. },
  345. resolution: IssueResolution.Fixed,
  346. status: IssueDeprecatedStatus.Confirmed,
  347. issueStatus: IssueStatus.Confirmed,
  348. }),
  349. snippets: keyBy(
  350. [
  351. mockSnippetsByComponent(
  352. ISSUE_TO_FILES[ISSUE_3][0],
  353. baseComponentKey,
  354. times(40, (i) => i + 20),
  355. ),
  356. ],
  357. 'component.key',
  358. ),
  359. },
  360. {
  361. issue: mockRawIssue(false, {
  362. key: ISSUE_4,
  363. actions: Object.values(IssueActions),
  364. transitions: [
  365. IssueTransition.Confirm,
  366. IssueTransition.Resolve,
  367. IssueTransition.FalsePositive,
  368. IssueTransition.WontFix,
  369. ],
  370. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_4][0]}`,
  371. message: 'Issue with tags',
  372. rule: ISSUE_TO_RULE[ISSUE_4],
  373. textRange: {
  374. startLine: 25,
  375. endLine: 25,
  376. startOffset: 0,
  377. endOffset: 1,
  378. },
  379. ruleDescriptionContextKey: 'spring',
  380. ruleStatus: 'DEPRECATED',
  381. quickFixAvailable: true,
  382. tags: ['unused'],
  383. codeVariants: ['variant 1', 'variant 2'],
  384. project: 'org.project2',
  385. assignee: 'email1@sonarsource.com',
  386. author: 'email3@sonarsource.com',
  387. }),
  388. snippets: keyBy(
  389. [
  390. mockSnippetsByComponent(
  391. ISSUE_TO_FILES[ISSUE_4][0],
  392. baseComponentKey,
  393. times(40, (i) => i + 20),
  394. ),
  395. ],
  396. 'component.key',
  397. ),
  398. },
  399. {
  400. issue: mockRawIssue(false, {
  401. key: ISSUE_1101,
  402. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_1101][0]}`,
  403. message: 'Issue on page 2',
  404. impacts: [
  405. {
  406. softwareQuality: SoftwareQuality.Maintainability,
  407. severity: SoftwareImpactSeverity.High,
  408. },
  409. ],
  410. rule: ISSUE_TO_RULE[ISSUE_1101],
  411. textRange: undefined,
  412. line: undefined,
  413. }),
  414. snippets: {},
  415. },
  416. {
  417. issue: mockRawIssue(false, {
  418. key: ISSUE_1102,
  419. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_1102][0]}`,
  420. message: 'Issue inside folderA',
  421. creationDate: '2022-01-15T09:36:01+0100',
  422. type: IssueType.CodeSmell,
  423. rule: ISSUE_TO_RULE[ISSUE_1102],
  424. textRange: {
  425. startLine: 10,
  426. endLine: 10,
  427. startOffset: 0,
  428. endOffset: 2,
  429. },
  430. }),
  431. snippets: {},
  432. },
  433. {
  434. issue: mockRawIssue(false, {
  435. key: ISSUE_1103,
  436. component: `${baseComponentKey}:${ISSUE_TO_FILES[ISSUE_1103][0]}`,
  437. creationDate: '2022-01-15T09:36:01+0100',
  438. message: 'Issue inside folderA',
  439. type: IssueType.CodeSmell,
  440. rule: ISSUE_TO_RULE[ISSUE_1103],
  441. textRange: {
  442. startLine: 10,
  443. endLine: 10,
  444. startOffset: 0,
  445. endOffset: 2,
  446. },
  447. }),
  448. snippets: {},
  449. },
  450. ];
  451. }