Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

18 Commits

Repository files navigation

Limit Lab Practice Standard - Limit 实验室实践标准

开发与审核标准 LPS-1

适用于开发活动与审核。审核时确保需审核内容完全遵循 LPS-1 标准。

编码约定 LPS-1000

格式化 LPS-1001: Format

在执行审计时,需确保代码使用约束工具执行格式化或确保目前认定的编码约定。

编程语言约束工具/编码约定
Rustrustfmt —check
JS/TSESLint & Prettier
ElixirElixir Phoenix 最佳实践

对于 Rust,需确保使用本 repo 中的 rustfmt.toml 进行格式化;对于 JS/TS,需确保使用本 repo 中的 prettierrc.config.js 进行格式化。

大函数拆分 LPS-1002: Large Function

除此之外还需要将超越长度超越特定行数的函数或方法执行拆分,如无法拆分需要在函数或方法前使用注释标注 FIXME: large function

LANGLINES
Elixir20
Rust40

E.g.

// FIXME: large functionfnfoo(){// 45 lines of code}

文档 LPS-1003: Documentation

对于拥有 pubpublic 等公开修饰符或公开的函数、方法、成员、属性等需要标注完整文档。 对于非公开函数、方法,如其长度超过 10 行则需要标注完整文档。

AccessDocumentation
publicFull
otherwiseif over 10 lines, full

模块化 LPS-1004: Module

对于前端项目,不要使用默认导出,使用命名导出。

// True ✅exportconstComponentA=()=>{return<div>Component A</div>}// True ✅// vite.config.tsexportdefaultdefineConfig({// ...})// False ❌exportdefault()=>{return<div>Component A</div>}

类型 LPS-1005: Type

对于 TypeScript,如非必要,不要使用 any 类型。

原始数据类型尽量让 TypeScript 自己推断,对于对象和函数,需显式声明类型。

// True ✅constname='Limit'// False ❌constname: string='Limit'// True ✅constnames: Array<string>=[]// False ❌constnames=[]// Oops, never[] 😨// True ✅consthandler: ChangeEventHandler<HTMLInputElement>=(e)=>{e.target// e.target is HTMLInputElement}// False ❌consthandler=(e)=>{e.target// e is any 😨}

提交代码前需要确保代码通过(Pass) tsc 检查。

React LPS-1006: React

用于 React 的大部分类型声明都可以从 @types/react 取到,如无特殊情况,不要自己声明类型。如果不清楚相关类型,可以翻阅 React TypeScript Cheatsheets

对于函数组件,使用箭头函数和 React.FC 声明类型。

import{FC,PropsWithChildren}from'react'// True ✅constComponentA: FC<PropsWithChildren>=props=>{return<div>Component A</div>}// False ❌constComponentA=(props: PropsWithChildren)=>{return<div>Component A</div>}

对于 Props 有多个属性的组件,需将 Props 用 interface 声明。

interfaceComponentAPropsextendsPropsWithChildren{name: stringlink: stringdescription: string}// True ✅constComponentA: FC<ComponentAProps>=props=>{return<div>Component A</div>}// False ❌constComponentA: FC<PropsWithChildren<{name: string}>>=props=>{return<div>Component A</div>}

CSS LPS-1007: CSS

一个项目中最好只使用一种样式方案,如 tailwindCSS Modules 不要混用。

不要使用任何方式拼接 CSS 类名,对于 tailwind 项目,可以使用 tailwind-merge,对于其他样式方案,可以使用 clsx,如果能拿到 DOM 节点,请使用 classList

// True ✅import{twJoin}from'tailwind-merge'exportconstComponentA=props=>{constclassName=twJoin('text-color-500',props.className)return<divclassName={className}></div>}// True ✅importclsxfrom'clsx'exportconstComponentA=props=>{constclassName=clsx('homepage__button',props.className)return<divclassName={className}></div>}// True ✅ constbutton=document.querySelector('.homepage__button')button.classList.add('text-color-500')// False ❌exportconstComponentA=props=>{constclassName='text-color-500'+` ${props.className}`return<divclassName={className}></div>}

版本管理约定 LPS-1100

分支名 LPS-1101

分支名应当全部使用形如 {category}/{name} 的名字,其中 category 为此分支对应的类型,同 commit 类型(feat, fix, refactor)等,name 为此分支的主题,如 card, pipeline 等。

  • True ✅
    • feat/pipeline
    • refactor/card
  • False ❌
    • lemon-nb
    • tHiSiSsOmEbRaNcH

版本发布标准 LPS-2

合并 LPS-2000

合并小提交 LPS-2001: Merge Small Commit

在发布对应版本前,需使用 git rebase -i 合并针对于同功能修改的小提交

测试 LPS-2100

测试覆盖率 LPS-2101: Test Coverage

在发布稳定版本(release)时,需保证测试覆盖率须保证测试覆盖率不能降低超过 5% 在发布预览版本(preview)时,需保证测试覆盖率须保证测试覆盖率不能降低超过 10%

PublishTest Converage
Release> -5%
Preview> -10%

About

Limit Lab Practice Standard - Limit实验室实践标准

Resources

Stars

5 stars

Watchers

2 watching

Forks

Contributors

Languages