{"id":1793,"date":"2018-10-17T17:53:30","date_gmt":"2018-10-17T09:53:30","guid":{"rendered":"https:\/\/cowmanchiang.me\/wp\/?p=1793"},"modified":"2023-10-31T15:42:22","modified_gmt":"2023-10-31T07:42:22","slug":"intellij-checkstyle-and-code-style","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=1793","title":{"rendered":"[Intellij] Checkstyle and Code Style"},"content":{"rendered":"<h2 id=\"toc_0\">Checkstyle<\/h2>\n<h3 id=\"toc_1\">\u4ecb\u7d39<\/h3>\n<ol>\n<li>\u6839\u64da\u5b9a\u7fa9\u597d\u7684\u898f\u5247\u5c0d\u7a0b\u5f0f\u78bc\u9032\u884c\u6aa2\u67e5\uff0c\u4ee5\u78ba\u4fdd\u7a0b\u5f0f\u78bc\u7684 Style \u662f\u4e00\u81f4\u7684 (\u76e1\u529b&#8230;)<\/li>\n<li>Checkstyle <a href=\"https:\/\/github.com\/checkstyle\/checkstyle\/tree\/master\/src\/main\/resources\">GitHub<\/a> \u6709\u63d0\u4f9b\u5169\u7a2e\u898f\u5247\u7bc4\u4f8b\uff0c\u5f8c\u7e8c\u5957\u7528\u7684\u898f\u5247\u5373\u662f\u4f7f\u7528 &#8220;Google Checks&#8221; \u9032\u884c\u4fee\u6539\n<ul>\n<li>Sun Checks<\/li>\n<li>Google Checks<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3 id=\"toc_2\">\u5b89\u88dd Checkstyle<\/h3>\n<ol>\n<li>Preferences.. \u2794 Plugins \u2794 Browse repositories.. -&gt; \u641c\u5c0b &#8220;CheckStyle&#8221;<\/li>\n<li>\u5b89\u88dd &#8220;CheckStyle-IDEA&#8221;<\/li>\n<\/ol>\n<h3 id=\"toc_3\">Checkstyle \u898f\u5247\u6587\u4ef6\u8aaa\u660e<\/h3>\n<ol>\n<li>checkstyle\/qmi_checks.xml \u70ba Checkstyle \u4e3b\u898f\u5247\u6a94\u6848\n<ul>\n<li>\u5b9a\u7fa9\u6aa2\u67e5\u7684\u6a94\u6848\u683c\u5f0f\u3001\u7bc4\u570d<\/li>\n<li>\u5b9a\u7fa9\u6392\u9664\u7684\u898f\u5247\u6a94\u6848\u4f4d\u7f6e (\u901a\u5e38\u70ba suppressions.xml)<\/li>\n<li>\u5b9a\u7fa9\u6aa2\u67e5\u7684\u9805\u76ee\uff0c\u6bcf\u4e00\u500b\u9805\u76ee\u53ef\u5b9a\u7fa9\u7684\u5c6c\u6027\u4e0d\u56fa\u5b9a\uff0c\u9700\u6aa2\u8996 <a href=\"http:\/\/checkstyle.sourceforge.net\/checks.html\">\u5b98\u65b9\u8aaa\u660e\u6587\u4ef6<\/a><\/li>\n<\/ul>\n<\/li>\n<li>checkstyle\/suppressions.xml \u70ba Checkstyle \u7684\u4f8b\u5916\u8a2d\u5b9a\n<ul>\n<li>\u91dd\u5c0d\u7279\u5b9a\u6aa2\u67e5\u898f\u5247\u5b9a\u7fa9\u6392\u9664\u6aa2\u67e5\u7684\u6a94\u6848<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3 id=\"toc_4\">\u5957\u7528 Checkstyle\u898f\u5247<\/h3>\n<ol>\n<li>\u9078\u64c7 Checkstyle version: 8.12 (\u81f3\u5c118.11, \u56e0\u6709 LambdaParameterName \u8a2d\u5b9a)<\/li>\n<li>Preferences.. \u2794 Other Settings \u2794 Checkstyle \u2794 Add Configuration File<\/li>\n<li>\u532f\u5165\u5f8c\u8a2d\u5b9a\u70ba Active<\/li>\n<\/ol>\n<h3 id=\"toc_5\">\u555f\u7528 Checkstyle \u5373\u6642\u6aa2\u67e5<\/h3>\n<ol>\n<li>Preferences.. \u2794 Editor \u2794 Inspections \u2794 Checkstyle \u2794 Checkstyle real-time scan<\/li>\n<li>\u9810\u8a2d\u70ba\u958b\u555f<\/li>\n<\/ol>\n<h3 id=\"toc_6\">\u7522\u751f Checkstyle \u6aa2\u67e5\u5831\u544a<\/h3>\n<ol>\n<li>\u4e0b\u8f09\u6a94\u6848\n<ul>\n<li><a href=\"https:\/\/github.com\/checkstyle\/checkstyle\/releases\/download\/checkstyle-8.12\/checkstyle-8.12-all.jar\">checkstyle command \u7a0b\u5f0f<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/checkstyle\/contribution\/raw\/master\/xsl\/checkstyle-noframes-severity-sorted.xsl\">checkstyle xsl\u5b9a\u7fa9\u6a94\u6848<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\u7522\u751fXML\u683c\u5f0f\u5831\u544a\n<div>\n<pre><code class=\"language-none\">java -jar checkstyle-8.12-all.jar -c qmi_checks.xml {Qmi_Project} -f xml -o report.xml<\/code><\/pre>\n<\/div>\n<\/li>\n<li>\u4f7f\u7528 Mac \u5167\u5efa\u7a0b\u5f0f &#8220;xsltproc&#8221; \u5c07 XML \u5831\u8868\u8f49\u6210 HTML \u683c\u5f0f\n<div>\n<pre><code class=\"language-none\">xsltproc -o output.html checkstyle-noframes-severity-sorted.xsl input.xml<\/code><\/pre>\n<\/div>\n<\/li>\n<\/ol>\n<h2 id=\"toc_7\">Code Style<\/h2>\n<h3 id=\"toc_8\">\u4ecb\u7d39<\/h3>\n<ol>\n<li>Intellij \u7de8\u8f2f\u5668\u5167\u5efa\u529f\u80fd\uff0c\u6839\u64da\u5b9a\u7fa9\u597d\u7684 Schema \u9032\u884c\u6aa2\u67e5<\/li>\n<li><a href=\"https:\/\/www.jetbrains.com\/help\/idea\/settings-code-style.html\">\u5b98\u7db2\u4ecb\u7d39<\/a><\/li>\n<li>\u53ef\u900f\u904e &#8220;Save Actions&#8221; \u8a2d\u5b9a\u7576\u6a94\u6848\u5132\u5b58\u6642\u81ea\u52d5\u57f7\u884c Reformat Code \u53ca Optimize Imports \u4ee5\u7b26\u5408 Code Style \u898f\u5247<\/li>\n<\/ol>\n<h3 id=\"toc_9\">\u532f\u5165 Code Style \u8a2d\u5b9a\u6a94\u6848<\/h3>\n<ol>\n<li>\u6a94\u6848\u4f4d\u7f6e: checkstyle\/qmi<em>code<\/em>format.xml<\/li>\n<li>Preferences.. \u2794 Editor \u2794 Code Style \u2794 Java \u2794 Schema \u2794 Import Schema \u2794 IntelliJ IDEA code style XML<\/li>\n<\/ol>\n<h3 id=\"toc_10\">\u5b89\u88dd Save Actions<\/h3>\n<ol>\n<li>Preferences.. \u2794 Plugins \u2794 Browse repositories.. -&gt; \u641c\u5c0b &#8220;Save Actions&#8221;<\/li>\n<li>\u5b89\u88dd &#8220;Save Actions&#8221;<\/li>\n<\/ol>\n<h3 id=\"toc_11\">\u8a2d\u5b9a Save Actions<\/h3>\n<ol>\n<li>Preferences.. \u2794 Other Settings \u2794 Save Action \u2794 General \u2794\u52fe\u9078 &#8220;Activate save actions on save (before saving each file, performs the configured actions below)&#8221;<\/li>\n<li>Preferences.. \u2794 Other Settings \u2794 Save Action \u2794 General \u2794\u52fe\u9078 &#8220;Optimize Imports&#8221;, &#8220;Reformat file&#8221;, &#8220;Rearrange fields and methods&#8221;<\/li>\n<\/ol>\n<h3 id=\"toc_12\">\u5099\u8a3b\u8aaa\u660e<\/h3>\n<ol>\n<li>\u56e0 Code Style \u7684 Arrangement \u529f\u80fd\u5bb9\u6613\u8ddf Checkstyle \u7684\u898f\u5247\u62b5\u89f8\uff0c\u4f30\u6703\u5c07 Arrangement \u7684\u529f\u80fd\u95dc\u9589<\/li>\n<li>JavaDoc \u4e2d\u5b9a\u7fa9 Map \u6642\uff0c\u5207\u52ff\u4f7f\u7528 &#8220;Map&lt;Object, Object&gt;&#8221; \u7b49\u5f62\u5f0f\u7de8\u5beb\uff0c\u6b64\u6703\u9020\u6210 Code Style \u8aa4\u5224\u800c\u5c0d\u9f4a\u8abf\u6574\u683c\u5f0f\uff0c\u5c0e\u81f4\u6bcf\u6b21\u5132\u5b58\u90fd\u6703\u51fa\u73fe\u8b8a\u52d5<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Checkstyle \u4ecb\u7d39 \u6839\u64da\u5b9a\u7fa9\u597d\u7684\u898f\u5247\u5c0d\u7a0b\u5f0f\u78bc\u9032\u884c\u6aa2\u67e5\uff0c\u4ee5\u78ba\u4fdd\u7a0b\u5f0f\u78bc\u7684 Style \u662f\u4e00\u81f4\u7684 (\u76e1\u529b&#8230;) Checkstyle GitHub \u6709\u63d0\u4f9b\u5169\u7a2e\u898f\u5247\u7bc4\u4f8b\uff0c\u5f8c\u7e8c\u5957\u7528\u7684\u898f\u5247\u5373\u662f\u4f7f\u7528 &#8220;Google Checks&#8221; \u9032\u884c\u4fee\u6539 Sun Checks Google Checks \u5b89\u88dd Checkstyle Preferences.. \u2794 Plugins \u2794 Browse repositories.. -&gt; \u641c\u5c0b &#8220;CheckStyle&#8221; \u5b89\u88dd &#8220;CheckStyle-IDEA&#8221; Checkstyle \u898f\u5247\u6587\u4ef6\u8aaa\u660e checkstyle\/qmi_checks.xml \u70ba Checkstyle \u4e3b\u898f\u5247\u6a94\u6848 \u5b9a\u7fa9\u6aa2\u67e5\u7684\u6a94\u6848\u683c\u5f0f\u3001\u7bc4\u570d \u5b9a\u7fa9\u6392\u9664\u7684\u898f\u5247\u6a94\u6848\u4f4d\u7f6e (\u901a\u5e38\u70ba suppressions.xml) \u5b9a\u7fa9\u6aa2\u67e5\u7684\u9805\u76ee\uff0c\u6bcf\u4e00\u500b\u9805\u76ee\u53ef\u5b9a\u7fa9\u7684\u5c6c\u6027\u4e0d\u56fa\u5b9a\uff0c\u9700\u6aa2\u8996 &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=1793\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-1793","post","type-post","status-publish","format-standard","hentry","category-intellij"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1793"}],"version-history":[{"count":2,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1793\/revisions"}],"predecessor-version":[{"id":1795,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1793\/revisions\/1795"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}