| <!DOCTYPE html> |
| <html lang="cn" class="js csstransforms3d"> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> |
| <meta name="generator" content="Hugo 0.70.0" /> |
| <meta name="description" content=""> |
| <meta name="buildDate" content="2022-08-11 16:02:48"> |
| |
| |
| <link rel="shortcut icon" href="https://shardingsphere.apache.org/document/current/img/favicon.png" type="image/x-icon" /> |
| |
| <title>开发规范 :: ShardingSphere</title> |
| |
| |
| <link href="https://shardingsphere.apache.org/community/css/nucleus.css?1660204968" rel="stylesheet"> |
| <link href="https://shardingsphere.apache.org/community/css/font-awesome.min.css?1660204968" rel="stylesheet"> |
| <link href="https://shardingsphere.apache.org/community/css/hybrid.css?1660204968" rel="stylesheet"> |
| <link href="https://shardingsphere.apache.org/community/css/featherlight.min.css?1660204968" rel="stylesheet"> |
| <link href="https://shardingsphere.apache.org/community/css/perfect-scrollbar.min.css?1660204968" rel="stylesheet"> |
| <link href="https://shardingsphere.apache.org/community/css/auto-complete.css?1660204968" rel="stylesheet"> |
| <link href="https://shardingsphere.apache.org/community/css/theme.css?1660204968" rel="stylesheet"> |
| <link href="https://shardingsphere.apache.org/community/css/hugo-theme.css?1660204968" rel="stylesheet"> |
| |
| <link href="https://shardingsphere.apache.org/community/css/theme-white.css?1660204968" rel="stylesheet"> |
| |
| |
| <script src="https://shardingsphere.apache.org/community/js/jquery-2.x.min.js?1660204968"></script> |
| |
| <script> |
| var _hmt = _hmt || []; |
| (function() { |
| var hm = document.createElement("script"); |
| hm.src = "https://hm.baidu.com/hm.js?d5a1dc8dcf63a64ee55b80de01c7fb1a"; |
| var s = document.getElementsByTagName("script")[0]; |
| s.parentNode.insertBefore(hm, s); |
| })(); |
| </script> |
| |
| <script async src="https://www.googletagmanager.com/gtag/js?id=G-HPVGEN405S"></script> |
| <script> |
| window.dataLayer = window.dataLayer || []; |
| function gtag(){window.dataLayer.push(arguments);} |
| gtag('js', new Date()); |
| |
| gtag('config', 'G-HPVGEN405S'); |
| </script> |
| |
| <style type="text/css"> |
| :root #header + #content > #left > #rlblock_left{ |
| display:none !important; |
| } |
| |
| |
| |
| </style> |
| |
| |
| </head> |
| <body class="" data-url="/cn/contribute/code-conduct/"> |
| <div class="change-theme"> |
| <div class="wrap"> |
| |
| <span data-item="retro"> |
| <svg t="1649761460834" class="icon" viewBox="0 0 1243 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2052" width="16" height="16"><path d="M755.093336 61.436797a511.973304 511.973304 0 1 0 207.495466 693.650688l-99.615377-53.757197a398.827204 398.827204 0 1 1-161.637286-540.351253l53.757197-99.615378z" fill="#ffffff" p-id="2053"></path><path d="M1204.971593 188.84501L534.652259 736.217612l-285.242269-364.086159 86.304071-67.653615 216.199012 275.953611 583.649567-476.574007 69.335813 84.987568z" fill="#ffffff" p-id="2054"></path></svg> |
| 复古 |
| </span> |
| <span data-item="eyehelp"> |
| <svg t="1649761460834" class="icon" viewBox="0 0 1243 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2052" width="16" height="16"><path d="M755.093336 61.436797a511.973304 511.973304 0 1 0 207.495466 693.650688l-99.615377-53.757197a398.827204 398.827204 0 1 1-161.637286-540.351253l53.757197-99.615378z" fill="#ffffff" p-id="2053"></path><path d="M1204.971593 188.84501L534.652259 736.217612l-285.242269-364.086159 86.304071-67.653615 216.199012 275.953611 583.649567-476.574007 69.335813 84.987568z" fill="#ffffff" p-id="2054"></path></svg> |
| 护眼 |
| </span> |
| <span data-item="haitian"> |
| <svg t="1649761460834" class="icon" viewBox="0 0 1243 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2052" width="16" height="16"><path d="M755.093336 61.436797a511.973304 511.973304 0 1 0 207.495466 693.650688l-99.615377-53.757197a398.827204 398.827204 0 1 1-161.637286-540.351253l53.757197-99.615378z" fill="#ffffff" p-id="2053"></path><path d="M1204.971593 188.84501L534.652259 736.217612l-285.242269-364.086159 86.304071-67.653615 216.199012 275.953611 583.649567-476.574007 69.335813 84.987568z" fill="#ffffff" p-id="2054"></path></svg> |
| 海天 |
| </span> |
| <span data-item="deep"> |
| <svg t="1649761460834" class="icon" viewBox="0 0 1243 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2052" width="16" height="16"><path d="M755.093336 61.436797a511.973304 511.973304 0 1 0 207.495466 693.650688l-99.615377-53.757197a398.827204 398.827204 0 1 1-161.637286-540.351253l53.757197-99.615378z" fill="#ffffff" p-id="2053"></path><path d="M1204.971593 188.84501L534.652259 736.217612l-285.242269-364.086159 86.304071-67.653615 216.199012 275.953611 583.649567-476.574007 69.335813 84.987568z" fill="#ffffff" p-id="2054"></path></svg> |
| 深邃 |
| </span> |
| <span data-item="dark"> |
| <svg t="1649761460834" class="icon" viewBox="0 0 1243 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2052" width="16" height="16"><path d="M755.093336 61.436797a511.973304 511.973304 0 1 0 207.495466 693.650688l-99.615377-53.757197a398.827204 398.827204 0 1 1-161.637286-540.351253l53.757197-99.615378z" fill="#ffffff" p-id="2053"></path><path d="M1204.971593 188.84501L534.652259 736.217612l-285.242269-364.086159 86.304071-67.653615 216.199012 275.953611 583.649567-476.574007 69.335813 84.987568z" fill="#ffffff" p-id="2054"></path></svg> |
| 暗黑 |
| </span> |
| <span class="active"> |
| <svg t="1649761460834" class="icon" viewBox="0 0 1243 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2052" width="16" height="16"><path d="M755.093336 61.436797a511.973304 511.973304 0 1 0 207.495466 693.650688l-99.615377-53.757197a398.827204 398.827204 0 1 1-161.637286-540.351253l53.757197-99.615378z" fill="#ffffff" p-id="2053"></path><path d="M1204.971593 188.84501L534.652259 736.217612l-285.242269-364.086159 86.304071-67.653615 216.199012 275.953611 583.649567-476.574007 69.335813 84.987568z" fill="#ffffff" p-id="2054"></path></svg> |
| 默认 |
| </span> |
| |
| </div> |
| </div> |
| |
| |
| |
| <header> |
| <div class="wrap"> |
| <a href="https://shardingsphere.apache.org/"><img src="https://shardingsphere.apache.org/document/current/img/logo_v3.png" /></a> |
| |
| |
| |
| |
| |
| <section id="prefooter"> |
| |
| <ul> |
| |
| <li> |
| <a class="padding"> |
| <i class="fa fa-fw fa-language"></i> |
| <div class="select-style"> |
| <select id="select-language" onchange="location = this.value;"> |
| |
| |
| |
| |
| |
| |
| |
| |
| <option id="en" value="/community/en/contribute/code-conduct/">English</option> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <option id="cn" value="/community/cn/contribute/code-conduct/" selected>简体中文</option> |
| |
| |
| |
| |
| </select> |
| <svg t="1645437162166" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2449" width="32" height="32"><path d="M483.072 714.496l30.165333 30.208 415.957334-415.829333a42.837333 42.837333 0 0 0 0-60.288 42.538667 42.538667 0 0 0-60.330667-0.042667l-355.541333 355.413333-355.242667-355.413333a42.496 42.496 0 0 0-60.288 0 42.837333 42.837333 0 0 0-0.085333 60.330667l383.701333 383.872 1.706667 1.749333z" fill="#3D3D3D" p-id="2450"></path></svg> |
| </div> |
| </a> |
| </li> |
| |
| |
| |
| </ul> |
| </section> |
| |
| </div> |
| </header> |
| <div class="wrap"> |
| <nav id="sidebar" class=""> |
| |
| |
| |
| <div id="header-wrapper"> |
| |
| |
| <div class="searchbox"> |
| <label for="search-by"><i class="fa fa-search"></i></label> |
| <input data-search-input id="search-by" type="text" placeholder="Search..."> |
| <span data-search-clear=""><i class="fa fa-close"></i></span> |
| </div> |
| |
| <script type="text/javascript" src="https://shardingsphere.apache.org/community/js/lunr.min.js?1660204968"></script> |
| <script type="text/javascript" src="https://shardingsphere.apache.org/community/js/auto-complete.js?1660204968"></script> |
| <script type="text/javascript"> |
| |
| var baseurl = "\/cn"; |
| |
| </script> |
| <script type="text/javascript" src="https://shardingsphere.apache.org/community/js/search.js?1660204968"></script> |
| |
| |
| </div> |
| |
| <div class="highlightable"> |
| <div class="leftMenu"> |
| <ul class="topics"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/" title="参与和贡献" class="dd-item |
| parent |
| |
| |
| "> |
| |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/"> |
| <i class="collapse" style="display:inline; font-family:'courier';"> |
| |
| <svg class="icon icon-down" |
| style="display: inline-block;" |
| viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="#777"> |
| <path d="M500.8 604.778667L267.306667 371.392l-45.226667 45.269333 278.741333 278.613334 278.485334-278.613334-45.248-45.248z" p-id="5376" ></path> |
| </svg> |
| <svg class="icon icon-right" |
| style="display: none;" |
| viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="#777"> |
| <path d="M593.450667 512.128L360.064 278.613333l45.290667-45.226666 278.613333 278.762666L405.333333 790.613333l-45.226666-45.269333z" p-id="5605" ></path> |
| </svg> |
| |
| </i> |
| <b>1. </b>参与和贡献 |
| |
| </a> |
| |
| |
| <ul> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/subscribe/" title="订阅指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/subscribe/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 订阅指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/establish-project/" title="开发环境指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/establish-project/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 开发环境指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/contributor/" title="贡献者指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/contributor/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 贡献者指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/committer/" title="提交者指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/committer/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 提交者指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/code-conduct/" title="开发规范" class="dd-item active"> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/code-conduct/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 开发规范 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/issue-conduct/" title="Issue 提交与处理规范" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/issue-conduct/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| Issue 提交与处理规范 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/document-conduct/" title="文档规范" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/document-conduct/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 文档规范 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/document-contributor/" title="官方文档贡献指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/document-contributor/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 官方文档贡献指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/release/" title="ShardingSphere 发布指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/release/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| ShardingSphere 发布指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/release-elasticjob/" title="ElasticJob 发布指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/release-elasticjob/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| ElasticJob 发布指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/release-elasticjob-ui/" title="ElasticJob-UI 发布指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/release-elasticjob-ui/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| ElasticJob-UI 发布指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/2fa/" title="2FA" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/2fa/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 2FA |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/icla/" title="签署 iCLA 指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/icla/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 签署 iCLA 指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/contribute/vote/" title="提交者选举流程指南" class="dd-item "> |
| <a href="https://shardingsphere.apache.org/community/cn/contribute/vote/"> |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| 提交者选举流程指南 |
| |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| </ul> |
| |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/powered-by/" title="采用公司" class="dd-item |
| |
| |
| |
| "> |
| |
| <a href="https://shardingsphere.apache.org/community/cn/powered-by/"> |
| <i class="collapse" style="display:inline; font-family:'courier';"> |
| |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| |
| </i> |
| <b>2. </b>采用公司 |
| |
| </a> |
| |
| |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/team/" title="团队" class="dd-item |
| |
| |
| |
| "> |
| |
| <a href="https://shardingsphere.apache.org/community/cn/team/"> |
| <i class="collapse" style="display:inline; font-family:'courier';"> |
| |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| |
| </i> |
| <b>3. </b>团队 |
| |
| </a> |
| |
| |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li data-nav-id="/cn/security/" title="安全" class="dd-item |
| |
| |
| |
| "> |
| |
| <a href="https://shardingsphere.apache.org/community/cn/security/"> |
| <i class="collapse" style="display:inline; font-family:'courier';"> |
| |
| <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5375" width="20" height="20"></svg> |
| |
| </i> |
| <b>4. </b>安全 |
| |
| </a> |
| |
| |
| </li> |
| |
| |
| |
| |
| |
| </ul> |
| |
| |
| |
| </div> |
| |
| |
| |
| |
| |
| <a class="padding" href="https://shardingsphere.apache.org/pdf/shardingsphere_docs_cn.pdf"> |
| 下载PDF文档 |
| |
| </a> |
| |
| <section id="footer"> |
| <p></p> |
| |
| </section> |
| </div> |
| </nav> |
| |
| |
| |
| |
| |
| <section id="body"> |
| <div id="overlay"></div> |
| <div class="padding highlightable"> |
| |
| <div> |
| <div id="top-bar"> |
| |
| |
| |
| |
| <div id="top-github-link"> |
| <a class="github-link" title='Edit this page' href="https://github.com/apache/shardingsphere/tree/master/docs/community/content/contribute/code-conduct.cn.md" target="blank"> |
| <i class="fa fa-code-fork"></i> |
| <span id="top-github-link-text">Edit this page</span> |
| </a> |
| </div> |
| |
| |
| |
| <div id="breadcrumbs" itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"> |
| <span id="sidebar-toggle-span"> |
| <a href="#" id="sidebar-toggle" data-sidebar-toggle=""> |
| <i class="fa fa-bars"></i> |
| </a> |
| </span> |
| |
| <span class="links"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <a href='https://shardingsphere.apache.org/community/cn/'>ShardingSphere</a> > <a href='https://shardingsphere.apache.org/community/cn/contribute/'>参与和贡献</a> > 开发规范 |
| |
| |
| |
| |
| |
| |
| </span> |
| </div> |
| |
| </div> |
| </div> |
| |
| |
| |
| <div id="chapter"> |
| |
| <div id="body-inner"> |
| |
| |
| |
| |
| |
| <nav id="TableOfContents"> |
| <ul> |
| <li><a href="#开发理念">开发理念</a></li> |
| <li><a href="#代码提交行为规范">代码提交行为规范</a></li> |
| <li><a href="#编码规范">编码规范</a></li> |
| <li><a href="#单元测试规范">单元测试规范</a></li> |
| <li><a href="#g4-编码规范">G4 编码规范</a></li> |
| </ul> |
| </nav> |
| |
| <p>以下行为准则以完全遵循 <a href="https://www.apache.org/foundation/policies/conduct.html">Apache软件基金会行为准则</a>为前提。</p> |
| <h2 id="开发理念">开发理念</h2> |
| <ul> |
| <li><strong>用心</strong> 保持责任心和敬畏心,以工匠精神持续雕琢。</li> |
| <li><strong>可读</strong> 代码无歧义,通过阅读而非调试手段浮现代码意图。</li> |
| <li><strong>整洁</strong> 认同《重构》和《代码整洁之道》的理念,追求整洁优雅代码。</li> |
| <li><strong>一致</strong> 代码风格、命名以及使用方式保持完全一致。</li> |
| <li><strong>精简</strong> 极简代码,以最少的代码表达最正确的意思。高度复用,无重复代码和配置。及时删除无用代码。</li> |
| <li><strong>抽象</strong> 层次划分清晰,概念提炼合理。保持方法、类、包以及模块处于同一抽象层级。</li> |
| <li><strong>极致</strong> 拒绝随意,保证任何一行代码、任何一个字母、任何一个空格都有其存在价值。</li> |
| </ul> |
| <h2 id="代码提交行为规范">代码提交行为规范</h2> |
| <ul> |
| <li>确保构建流程中的各个步骤都成功完成,包括:Apache 协议文件头检查、Checkstyle 检查、编译、单元测试等。构建流程启动命令:<code>mvn -T 1C clean install</code> 或者 <code>./mvnw -T 1C clean install</code>。执行目录有 2 种选择,根据自己的熟悉程度做选择:1)对项目还不太熟悉,在项目根目录执行构建,所有模块都会执行构建,2)明确知道这次改动会影响到哪些模块,在这些模块执行构建,可以大大缩短构建时间。</li> |
| <li>确保覆盖率不低于 master 分支。</li> |
| <li>应尽量将设计精细化拆分;做到小幅度修改,多次数提交,但应保证提交的完整性。</li> |
| <li>确保遵守编码规范。</li> |
| <li>如果您使用 IDEA,可导入推荐的 <code>src/resources/code-style-idea.xml</code>。</li> |
| <li>通过 Spotless 统一代码风格,执行 <code>mvn spotless:apply</code> 格式化代码。</li> |
| </ul> |
| <h2 id="编码规范">编码规范</h2> |
| <ul> |
| <li>使用 linux 换行符。</li> |
| <li>不应有无意义的空行。请提炼私有方法,代替方法体过长或代码段逻辑闭环而采用的空行间隔。</li> |
| <li>类、方法和变量的命名要做到顾名思义,避免使用缩写。</li> |
| <li>返回值变量使用 <code>result</code> 命名;循环中使用 <code>each</code> 命名循环变量;map 中使用 <code>entry</code> 代替 <code>each</code>。</li> |
| <li>捕获的异常名称命名为 <code>ex</code> ;捕获异常且不做任何事情,异常名称命名为 <code>ignored</code>。</li> |
| <li>配置文件使用 <code>Spinal Case</code> 命名(一种使用 <code>-</code> 分割单词的特殊 <code>Snake Case</code>)。</li> |
| <li>需要注释解释的代码尽量提成小方法,用方法名称解释。</li> |
| <li><code>equals</code> 和 <code>==</code> 条件表达式中,常量在左,变量在右;大于小于等条件表达式中,变量在左,常量在右。</li> |
| <li>除了构造器入参与全局变量名称相同的赋值语句外,避免使用 <code>this</code> 修饰符。</li> |
| <li>除了用于继承的抽象类之外,尽量将类设计为 <code>final</code>。</li> |
| <li>嵌套循环尽量提成方法。</li> |
| <li>成员变量定义顺序以及参数传递顺序在各个类和方法中保持一致。</li> |
| <li>优先使用卫语句。</li> |
| <li>类和方法的访问权限控制为最小。</li> |
| <li>方法所用到的私有方法应紧跟该方法,如果有多个私有方法,书写私有方法应与私有方法在原方法的出现顺序相同。</li> |
| <li>方法入参和返回值不允许为 <code>null</code>。</li> |
| <li>优先使用三目运算符代替 if else 的返回和赋值语句。</li> |
| <li>优先使用 lombok 代替构造器,getter, setter 方法和 log 变量。</li> |
| <li>优先考虑使用 <code>LinkedList</code>,只有在需要通过下标获取集合中元素值时再使用 <code>ArrayList</code>。</li> |
| <li><code>ArrayList</code>,<code>HashMap</code> 等可能产生扩容的集合类型必须指定集合初始大小,避免扩容。</li> |
| <li>日志与注释一律使用英文。</li> |
| <li>注释只能包含 javadoc,todo 和 fixme。</li> |
| <li>公开的类和方法必须有 javadoc,其他类和方法以及覆盖自父类的方法无需 javadoc。</li> |
| <li>条件运算符(<表达式1> ? <表达式2> : <表达式3>)禁止 <code>嵌套使用</code>。</li> |
| <li>热点方法内应避免使用 Java Stream,除非该场景下使用 Stream 的性能优于普通循环。</li> |
| </ul> |
| <h2 id="单元测试规范">单元测试规范</h2> |
| <ul> |
| <li>测试代码和生产代码需遵守相同代码规范。</li> |
| <li>单元测试需遵循 AIR(Automatic, Independent, Repeatable)设计理念。 |
| <ul> |
| <li>自动化(Automatic):单元测试应全自动执行,而非交互式。禁止人工检查输出结果,不允许使用 <code>System.out</code>,<code>log</code> 等,必须使用断言进行验证。</li> |
| <li>独立性(Independent):禁止单元测试用例间的互相调用,禁止依赖执行的先后次序。每个单元测试均可独立运行。</li> |
| <li>可重复执行(Repeatable):单元测试不能受到外界环境的影响,可以重复执行。</li> |
| </ul> |
| </li> |
| <li>单元测试需遵循 BCDE(Border, Correct, Design, Error)设计原则。 |
| <ul> |
| <li>边界值测试(Border):通过循环边界、特殊数值、数据顺序等边界的输入,得到预期结果。</li> |
| <li>正确性测试(Correct):通过正确的输入,得到预期结果。</li> |
| <li>合理性设计(Design):与生产代码设计相结合,设计高质量的单元测试。</li> |
| <li>容错性测试(Error):通过非法数据、异常流程等错误的输入,得到预期结果。</li> |
| </ul> |
| </li> |
| <li>除去简单的 <code>getter /setter</code> 方法,以及声明 SPI 的静态代码,如:<code>getType / getOrder</code>,单元测试需全覆盖。</li> |
| <li>每个测试用例需精确断言。</li> |
| <li>准备环境的代码和测试代码分离。</li> |
| <li>只有 junit <code>Assert</code>,hamcrest <code>CoreMatchers</code>,Mockito 相关可以使用 static import。</li> |
| <li>单数据断言,应使用 <code>assertTrue</code>,<code>assertFalse</code>,<code>assertNull</code> 和 <code>assertNotNull</code>。</li> |
| <li>多数据断言,应使用 <code>assertThat</code>。</li> |
| <li>精确断言,尽量不使用 <code>not</code>,<code>containsString</code> 断言。</li> |
| <li>测试用例的真实值应名为为 actual XXX,期望值应命名为 expected XXX。</li> |
| <li>测试类和 <code>@Test</code> 标注的方法无需 javadoc。</li> |
| <li>使用 Mockito mockStatic 和 mockConstruction 方法必须搭配 try-with-resource 或在清理方法中关闭,避免泄漏。</li> |
| </ul> |
| <h2 id="g4-编码规范">G4 编码规范</h2> |
| <ul> |
| <li>公共规范 |
| <ul> |
| <li>每行长度不超过 <code>200</code> 个字符,保证每一行语义完整以便于理解。</li> |
| </ul> |
| </li> |
| <li>词法解析规范 |
| <ul> |
| <li>每个规则一行,规则间无需空行。</li> |
| <li>规则名称使用大写字母。如果名称由多个单词组成,用 <code>下划线</code> 间隔。<code>DataType</code> 和 <code>Symbol</code> 的规则命名以 <code>下划线</code> 结尾。与 ANTLR 内置变量或关键字重名的规则在结尾加 <code>下划线</code> 以示区分。</li> |
| <li>不对外暴露的规则使用 <code>fragment</code>,<code>fragment</code> 定义的规则需在其服务的规则之后声明。</li> |
| <li>公用规则定义放在 <code>Keyword.g4</code>,每个数据库可以有自己特有的规则定义。例如:<code>MySQLKeyword.g4</code>。</li> |
| </ul> |
| </li> |
| <li>语法解析规范 |
| <ul> |
| <li>每个规则结束后空一行,空行无需缩进。</li> |
| <li>规则名称前面不空格,<code>冒号</code> 后空一格再开始写规则,<code>分号</code> 在单独一行并保持和上一行相同缩进。</li> |
| <li>如果一个规则的分支超过 <code>5</code> 个,则每个分支一行。</li> |
| <li>规则命名采用 java 变量的驼峰形式。</li> |
| <li>为每种 SQL 语句类型定义一个独立的语法文件,文件名称由 <code>数据库名称</code> + <code>语句类型名称</code> + <code>Statement</code>。例如:<code>MySQLDQLStatement.g4</code>。</li> |
| <li>每个 <code>SQLStatement</code> 和 <code>SQLSegment</code> 实现类,必须添加 lombok <code>@ToString</code> 注解,如果实现类继承了某个父类,则需要添加 <code>callSuper = true</code> 参数。</li> |
| </ul> |
| </li> |
| </ul> |
| |
| |
| <footer class=" footline" > |
| |
| </footer> |
| |
| |
| |
| </div> |
| |
| </div> |
| |
| |
| </div> |
| |
| <div id="navigation" > |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <a class="nav nav-prev" href="https://shardingsphere.apache.org/community/cn/contribute/committer/" title="提交者指南"> <i class="fa fa-long-arrow-left fa-lg"></i> 上一篇</a> |
| |
| |
| |
| |
| <a class="nav nav-next" href="https://shardingsphere.apache.org/community/cn/contribute/issue-conduct/" title="Issue 提交与处理规范" style="margin-right: 0px;">下一篇 <i class="fa fa-long-arrow-right fa-lg"></i></a> |
| |
| |
| </div> |
| |
| </section> |
| </div> |
| <div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"> |
| <div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div> |
| </div> |
| |
| <script src="https://shardingsphere.apache.org/community/js/clipboard.min.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/perfect-scrollbar.min.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/perfect-scrollbar.jquery.min.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/jquery.sticky.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/featherlight.min.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/html5shiv-printshiv.min.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/highlight.pack.js?1660204968"></script> |
| <script>hljs.initHighlightingOnLoad();</script> |
| <script src="https://shardingsphere.apache.org/community/js/modernizr.custom.71422.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/learn.js?1660204968"></script> |
| <script src="https://shardingsphere.apache.org/community/js/hugo-learn.js?1660204968"></script> |
| <script> |
| try{ |
| |
| function log(fileName, category, locale){ |
| window._hmt.push(['_trackEvent', 'document', 'download', locale ? 'PDF_'+locale : fileName]); |
| |
| gtag('event', 'Downloads', { |
| 'event_category' : locale ? 'PDF' : category, |
| 'event_label' : locale ? locale+'.pdf' : fileName |
| }); |
| } |
| |
| $('.padding[href*=shardingsphere]').on('click', function(){ |
| var locale = /cn/.test(location.pathname) ?'cn':'en'; |
| log('','', locale) |
| }) |
| |
| function getFileName(str){ |
| var strs = str.split('/'); |
| return strs[strs.length - 1] |
| } |
| |
| $('a[href$="src.zip"]').on('click', function(){ |
| log(getFileName($(this).attr('href')), "SRC") |
| }) |
| |
| $('a[href$="zip.asc"]').on('click', function(){ |
| log(getFileName($(this).attr('href')), "ASC") |
| }) |
| |
| $('a[href$="zip.sha512"]').on('click', function(){ |
| log(getFileName($(this).attr('href')), "SHA512") |
| }) |
| |
| $('a[href$="tar.gz.asc"]').on('click', function(){ |
| log(getFileName($(this).attr('href')), "ASC") |
| }) |
| |
| $('a[href$="tar.gz.sha512"]').on('click', function(){ |
| log(getFileName($(this).attr('href')), "SHA512") |
| }) |
| |
| $('a[href$="tar.gz"]').on('click', function(){ |
| log(getFileName($(this).attr('href')), "TAR") |
| }) |
| |
| }catch(ex){} |
| </script> |
| |
| |
| </body> |
| </html> |
| |