{"id":1332,"date":"2021-05-24T19:58:27","date_gmt":"2021-05-24T10:58:27","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=1332"},"modified":"2021-05-24T19:58:31","modified_gmt":"2021-05-24T10:58:31","slug":"sonarqube-react-monorepo","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=1332","title":{"rendered":"SonarQube\u3068project\u306e\u9023\u643a\u65b9\u6cd5(monorepo+React + TypeScript)"},"content":{"rendered":"\n<p>single project\u3068\u57fa\u672c\u7684\u306b\u306f\u8a2d\u5b9a\u65b9\u6cd5\u540c\u3058\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u89aa\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u914d\u4e0b\u306b\u3001project1,project2,common\u306e\u30b5\u30d6\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u5b58\u5728\u3059\u308b\u3068\u3057\u3066\u9032\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/react-monorepo\/\">[React.js]monorepo\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b+typescript<\/a><\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">SonarScanner\u306e\u305f\u3081\u306e\u6e96\u5099<\/h2>\n\n\n\n<h3 id=\"outline__1_1\" class=\"wp-block-heading\">\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>sonarqube-scanner\u30fb\u30fb\u30fbSonarQube\u306b\u9759\u7684\u89e3\u6790\u7d50\u679c\u3092\u9001\u4fe1\u3059\u308b<\/li><li>jest-sonar-reporter\u30fb\u30fb\u30fbtest\u7d50\u679c\u3092SonarQube\u7528\u306b\u51fa\u529b\u3059\u308b<\/li><\/ul>\n\n\n\n<p>sonarqube-scanner\u306f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5171\u901a\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002\uff08\u30eb\u30fc\u30c8\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304b\u3089\u5b9f\u884c\u3067\u304d\u308c\u3070\u3044\u3044\uff09<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nyarn add -W  --dev sonarqube-scanner\n<\/pre><\/div>\n\n\n<p>jest-sonar-reporter\u306f\u5404\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nyarn workspace project1 add --dev jest-sonar-reporter\nyarn workspace project2 add --dev jest-sonar-reporter\nyarn workspace common add --dev jest-sonar-reporter\n<\/pre><\/div>\n\n\n<h3 id=\"outline__1_2\" class=\"wp-block-heading\">test report\u306e\u51fa\u529b<\/h3>\n\n\n\n<p>package.json\u3092\u4fee\u6b63\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n  ...\n  &quot;scripts&quot;: {\n    &quot;test&quot;: &quot;jest --setupFiles .\/src\/test\/setup-tests.ts --coverage --testResultsProcessor jest-sonar-reporter&quot;,\n  },\n  &quot;testResultsProcessor&quot;: &quot;jest-sonar-reporter&quot;,\n  &quot;jestSonar&quot;: {\n    &quot;reportPath&quot;: &quot;report&quot;,\n    &quot;reportFile&quot;: &quot;test-report.xml&quot;,\n    &quot;indent&quot;: 4\n  }\n  ...\n<\/pre><\/div>\n\n\n<p>scripts\u306etest<br>\u30ab\u30d0\u30ec\u30c3\u30b8\u306e\u51fa\u529b\u3068jest-sonar-reporter\u3067\u306e\u30ec\u30dd\u30fc\u30c8\u51fa\u529b\u3092\u6307\u5b9a<\/p>\n\n\n\n<p>testResultsProcessor<br>\u4f7f\u7528\u3059\u308b\u30ec\u30dd\u30fc\u30c8\u51fa\u529b\u30d7\u30ed\u30bb\u30c3\u30b5\u3092\u6307\u5b9a<\/p>\n\n\n\n<p>jestSonar<br>\u30ec\u30dd\u30fc\u30c8\u306e\u51fa\u529b\u5148\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u3002<br>report\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306btest-report.xml\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u51fa\u529b\u3059\u308b<\/p>\n\n\n\n<h3 id=\"outline__1_3\" class=\"wp-block-heading\">\u78ba\u8a8d<\/h3>\n\n\n\n<p>\u30b5\u30d6\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306escript\u3092\u5b9f\u884c\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u3089\u308c\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nyarn workspace project1 test\nyarn workspace project2 test\nyarn workspace common test\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"217\" height=\"181\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2021\/05\/image-33.png\" alt=\"\" class=\"wp-image-1333\"\/><\/figure>\n\n\n\n<p>report\u306e\u4e0b\u306btest-report.xml\u304c\u4f5c\u6210\u3055\u308c\u308c\u3070OK\u3067\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">SonarScanner\u306e\u8a2d\u5b9a<\/h2>\n\n\n\n<p>\u30eb\u30fc\u30c8\u306bsonar-scanner.js\u3092\u4f5c\u6210\u3059\u308b<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst scanner = require('sonarqube-scanner');\nscanner(\n    {\n        serverUrl: &quot;http:\/\/localhost:9000&quot;,\n        options: {\n            &quot;sonar.login&quot;: &quot;admin&quot;,\n            &quot;sonar.password&quot;: &quot;password&quot;,\n            &quot;sonar.projectKey&quot;: 'com.example.yourproject:react-monorepo-template',\n            &quot;sonar.projectName&quot;: 'react-monorepo-template',\n            &quot;sonar.language&quot;: &quot;js&quot;,\n            &quot;sonar.sourceEncoding&quot;: &quot;UTF-8&quot;,\n            &quot;sonar.exclusions&quot;: &quot;.\/node_modules&quot;,\n            &quot;sonar.exclusions&quot;: &quot;**\/build\/**&quot;,\n            &quot;sonar.exclusions&quot;: &quot;**\/test\/**&quot;,\n\n            &quot;sonar.modules&quot;: &quot;packages\/project1,packages\/project2,packages\/common&quot;,\n\n            &quot;packages\/project1.sonar.projectName&quot;: &quot;project1&quot;,\n            &quot;packages\/project1.sonar.sources&quot;: &quot;.\/src&quot;,\n            &quot;packages\/project1.sonar.tests&quot;: &quot;.\/src&quot;,\n            &quot;packages\/project1.sonar.eslint.reportPaths&quot;: &quot;report\/eslint-report.json&quot;,\n            &quot;packages\/project1.sonar.testExecutionReportPaths&quot;: &quot;report\/test-report.xml&quot;,\n            &quot;packages\/project1.sonar.typescript.lcov.reportPaths&quot;: &quot;coverage\/lcov.info&quot;,\n\n            &quot;packages\/project2.sonar.projectName&quot;: &quot;project2&quot;,\n            &quot;packages\/project2.sonar.sources&quot;: &quot;.\/src&quot;,\n            &quot;packages\/project2.sonar.tests&quot;: &quot;.\/src&quot;,\n            &quot;packages\/project2.sonar.eslint.reportPaths&quot;: &quot;report\/eslint-report.json&quot;,\n            &quot;packages\/project2.sonar.testExecutionReportPaths&quot;: &quot;report\/test-report.xml&quot;,\n            &quot;packages\/project2.sonar.typescript.lcov.reportPaths&quot;: &quot;coverage\/lcov.info&quot;,\n\n            &quot;packages\/common.sonar.projectName&quot;: &quot;common&quot;,\n            &quot;packages\/common.sonar.sources&quot;: &quot;.\/src&quot;,\n            &quot;packages\/common.sonar.tests&quot;: &quot;.\/src&quot;,\n            &quot;packages\/common.sonar.eslint.reportPaths&quot;: &quot;report\/eslint-report.json&quot;,\n            &quot;packages\/common.sonar.testExecutionReportPaths&quot;: &quot;report\/test-report.xml&quot;,\n            &quot;packages\/common.sonar.typescript.lcov.reportPaths&quot;: &quot;coverage\/lcov.info&quot;,\n\n            &quot;sonar.sources&quot;: &quot;.\/src&quot;,\n            &quot;sonar.tests&quot;: &quot;.\/src&quot;,\n            &quot;sonar.test.inclusions&quot;: &quot;**\/*.test.tsx,**\/*.test.ts&quot;,\n        },\n    },\n    () =&gt; process.exit()\n);\n<\/pre><\/div>\n\n\n<p>monorepo\u69cb\u6210\u306e\u5834\u5408\u3001<br>sonar.modules\u3067\u6307\u5b9a\u3057\u305f\u30b5\u30d6\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u5bfe\u3057\u3066\u3001\u500b\u5225\u306bsonar\u8a2d\u5b9a\u304c\u3067\u304d\u307e\u3059\u3002<br>\u305d\u306e\u5834\u5408\u306f\u3001<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;module\u3067\u6307\u5b9a\u3057\u305f\u30b5\u30d6\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d].sonar.&#x5B;\u30d7\u30ed\u30d1\u30c6\u30a3]\n<\/pre><\/div>\n\n\n<p>\u3068\u3044\u3046\u5f62\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306bpackage.json\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&quot;scripts&quot;: {\n  &quot;sonar&quot;: &quot;node sonarqube-scanner.js&quot;\n},\n<\/pre><\/div>\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">\u5b9f\u884c<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nyarn sonar\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"960\" height=\"224\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2021\/05\/image-34.png\" alt=\"\" class=\"wp-image-1334\"\/><\/figure>\n\n\n\n<h2 id=\"outline__4\" class=\"wp-block-heading\">\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/h2>\n\n\n\n<h3 id=\"outline__4_1\" class=\"wp-block-heading\">can&#8217;t be indexed twice<\/h3>\n\n\n\n<p>sonar-scanner.js\u306e\u4e00\u756a\u4e0b\u6bb5\u306e\u8a2d\u5b9a\u306e<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&quot;sonar.sources&quot;: &quot;.\/src&quot;,\n&quot;sonar.tests&quot;: &quot;.\/src&quot;,\n<\/pre><\/div>\n\n\n<p>\u3053\u308c\u3092\u30b5\u30d6\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u304b\u3089\u3068\u3044\u3046\u7406\u7531\u3067\u629c\u3044\u3066\u3044\u308b\u3068\u3001script\u5b9f\u884c\u6642\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nINFO: ------------------------------------------------------------------------\nINFO: EXECUTION FAILURE\nINFO: ------------------------------------------------------------------------\nINFO: Total time: 1:19.402s\nINFO: Final Memory: 6M\/24M\nINFO: ------------------------------------------------------------------------\nERROR: Error during SonarScanner execution\nERROR: File packages\/project1\/src\/index.tsx can't be indexed twice. Please check that inclusion\/exclusion patterns produce disjoint sets for main and test files\nERROR: \nerror Command failed with exit code 2.\n<\/pre><\/div>\n\n\n<h2 id=\"outline__5\" class=\"wp-block-heading\">\u95a2\u9023<\/h2>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/docker-sonarqube\/\">Docker\u3067SonarQube\u74b0\u5883\u69cb\u7bc9\u3092\u624b\u65e9\u304f\u69cb\u7bc9\u3059\u308b<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/sonarqube-gradle\/\">SonarQube\u3068project\u306e\u9023\u643a\u65b9\u6cd5(Spring Boot,gradle)<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/sonarqube-qualitygate-api\/\">SonarQube\u3067\u7ba1\u7406\u3057\u3066\u3044\u308bproject\u306eQualityGate\u306e\u72b6\u614b\u3092API\u3067\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/react-monorepo\/\">[React.js]monorepo\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b+typescript<\/a><\/p>\n\n\n\n<h2 id=\"outline__6\" class=\"wp-block-heading\">\u53c2\u8003<\/h2>\n\n\n\n<p><a href=\"https:\/\/docs.sonarqube.org\/latest\/analysis\/analysis-parameters\/\">Analysis Parameters &#8211; SonarQube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>single project\u3068\u57fa\u672c\u7684\u306b\u306f\u8a2d\u5b9a\u65b9\u6cd5\u540c\u3058\u3067\u3059\u3002 \u89aa\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u914d\u4e0b\u306b\u3001project1, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1314,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[298,286],"tags":[297,295,287,296],"class_list":["post-1332","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-js","category-sonarqube","tag-monorepo","tag-react-js","tag-sonarqube","tag-typescript"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1332"}],"version-history":[{"count":2,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1332\/revisions"}],"predecessor-version":[{"id":1339,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1332\/revisions\/1339"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/1314"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}