Submission information specifications
Team collaboration standards and commit message standards are indispensable parts of front-end development. Good collaboration standards can improve team efficiency and reduce communication costs, while standardized commit messages facilitate code review, issue tracking, and version management. The following content will delve into these two aspects in detail.
Team Collaboration Standards
Unified Code Style
Team members should adhere to a unified code style, including indentation, naming, comments, etc. Tools like ESLint and Prettier can be used for automatic code formatting.
// Bad example
function getUserInfo(userId){return fetch(`/api/users/${userId}`).then(res=>res.json())}
// Good example
function getUserInfo(userId) {
return fetch(`/api/users/${userId}`)
.then((res) => res.json());
}
Branch Management Strategy
Adopt Git Flow or a similar branch management strategy:
main
/master
: Production codedevelop
: Development branchfeature/xxx
: Feature branchhotfix/xxx
: Hotfix branch
# Example of creating a feature branch
git checkout -b feature/user-authentication develop
Code Review Process
All code changes must go through a Pull Request review:
- Developers complete work on a feature branch.
- Create a PR to the target branch (usually
develop
). - At least one team member must approve before merging.
- Resolve review comments before merging the branch.
Documentation Standards
Each project should include:
- README.md: Project overview, environment setup, startup commands.
- CHANGELOG.md: Version change history.
- API.md: API documentation (if backend interaction exists).
Commit Message Standards
Commit Message Structure
Follow the Conventional Commits specification:
<type>(<scope>): <subject>
<blank line>
<body>
<blank line>
<footer>
Commit Types (type)
Common types include:
feat
: New feature.fix
: Bug fix.docs
: Documentation changes.style
: Code style adjustments.refactor
: Code refactoring.test
: Test-related changes.chore
: Build process or auxiliary tool changes.
Examples
# Feature commit example
git commit -m "feat(user): add login functionality
- implement email/password login
- add form validation
- setup auth store
Closes #123"
# Bug fix example
git commit -m "fix(api): handle null response in user profile
When the API returns null for user profile, the app was crashing.
Now it shows a proper error message.
Fixes #456"
Commit Message Best Practices
- Keep the title under 50 characters.
- Limit body lines to 72 characters.
- Use present tense ("add" instead of "added").
- Do not capitalize the first letter.
- Do not end the title with a period.
- Reference issue numbers (e.g., Fixes #123).
Automated Validation
Use husky + commitlint for automatic commit message validation:
// package.json
{
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
Tools and Configurations
ESLint Configuration Example
// .eslintrc.js
module.exports = {
extends: ['airbnb', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
'import/prefer-default-export': 'off'
}
};
Prettier Configuration Example
// .prettierrc
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid"
}
Git Hook Configuration
# Install husky
npm install husky --save-dev
# Install commitlint
npm install @commitlint/{config-conventional,cli} --save-dev
# Create commitlint config file
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
Common Issues and Solutions
Handling Code Conflicts
When multiple people modify the same file:
- Frequently pull the latest code.
- Use
git rebase
instead ofgit merge
. - Make small, incremental commits to avoid large-scale changes.
# Conflict resolution example
git fetch origin
git rebase origin/develop
# After resolving conflicts
git add .
git rebase --continue
Modifying Commit Messages
If a commit message does not meet standards:
# Amend the last commit
git commit --amend
# Modify historical commits (use with caution)
git rebase -i HEAD~3
Large File Commits
Avoid committing large files to the repository:
- Use
.gitignore
to exclude build artifacts. - For already committed large files, use
git filter-branch
or BFG to clean up.
# Example of removing large files from history
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch path/to/large/file" \
--prune-empty --tag-name-filter cat -- --all
Continuous Integration and Automation
CI/CD Integration
Add standards checks to the CI pipeline:
# .github/workflows/ci.yml example
name: CI
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npm run lint
- run: npm run test
Automated Version Releases
Use semantic-release to automate versioning and changelog generation:
// package.json
{
"release": {
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
"@semantic-release/github"
]
}
}
Team Collaboration Tools
Project Management
Recommended tools:
- Jira: Comprehensive project management.
- Trello: Lightweight Kanban management.
- GitHub Projects: Integrated with code repositories.
Code Collaboration Platforms
- GitHub: The most popular code hosting platform.
- GitLab: Built-in CI/CD functionality.
- Bitbucket: Suitable for small teams.
Communication Tools
- Slack: Team instant messaging.
- Discord: Community communication.
- Lark/DingTalk: Commonly used by domestic teams.
Code Quality Assurance
Unit Testing Standards
Test files should have the same name as the tested file, with a .test
suffix:
src/
components/
Button/
Button.js
Button.test.js
Testing example:
// Button.test.js
import React from 'react';
import { render, screen } from '@testing-library/react';
import Button from './Button';
test('renders button with text', () => {
render(<Button>Click me</Button>);
expect(screen.getByText('Click me')).toBeInTheDocument();
});
E2E Testing
Use Cypress for end-to-end testing:
// cypress/integration/login.spec.js
describe('Login', () => {
it('should login with valid credentials', () => {
cy.visit('/login');
cy.get('#email').type('user@example.com');
cy.get('#password').type('password123');
cy.get('button[type="submit"]').click();
cy.url().should('include', '/dashboard');
});
});
Performance Optimization Collaboration
Performance Checklist
Teams should share performance optimization knowledge:
- Image compression (use WebP format).
- Code splitting (React.lazy, dynamic import).
- Avoid unnecessary re-renders.
- Use memoization.
// Code splitting example
const LazyComponent = React.lazy(() => import('./LazyComponent'));
function MyComponent() {
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
);
}
Performance Monitoring
Integrate monitoring tools:
- Lighthouse CI.
- Web Vitals.
- Sentry.
// Monitor Web Vitals
import { getCLS, getFID, getLCP } from 'web-vitals';
getCLS(console.log);
getFID(console.log);
getLCP(console.log);
本站部分内容来自互联网,一切版权均归源网站或源作者所有。
如果侵犯了你的权益请来信告知我们删除。邮箱:cc@cccx.cn