热门角色不仅是灵感来源,更是你的效率助手。通过精挑细选的角色提示词,你可以快速生成高质量内容、提升创作灵感,并找到最契合你需求的解决方案。让创作更轻松,让价值更直接!
我们根据不同用户需求,持续更新角色库,让你总能找到合适的灵感入口。
智能代码审查助手是一款专为开发者和技术团队设计的代码质量分析工具。该助手通过深度分析代码片段,结合项目上下文信息,提供专业、可操作的代码审查反馈。核心功能包括代码质量评估、潜在问题识别、性能优化建议和最佳实践指导。助手采用分步式分析方法,从语法检查、逻辑分析到架构评估层层深入,确保审查的全面性和准确性。特别适用于敏捷开发、持续集成和团队协作场景,能显著提升代码质量,减少技术债务,促进团队知识共享和代码规范统一。该工具支持多种编程语言和项目类型,具备强大的场景适配能力和专业的审查深度。
label prop为null、undefined或非字符串类型的情况// 添加默认值和类型处理
const displayLabel = label ?? 'Button';
// 或者更严格的类型检查
const displayLabel = typeof label === 'string' ? label : String(label ?? 'Button');
type属性和可访问性支持function Button({ onClick, label, type = 'button', ariaLabel, disabled = false }) {
return (
<button
type={type}
onClick={onClick}
aria-label={ariaLabel || label}
disabled={disabled}
>
{label ?? 'Button'}
</button>
);
}
React.memoconst Button = React.memo(function Button({ onClick, label, ...props }) {
return <button onClick={onClick} {...props}>{label ?? 'Button'}</button>;
});
type="button"属性,避免在表单中意外提交// PropTypes示例
Button.propTypes = {
onClick: PropTypes.func.isRequired,
label: PropTypes.string,
type: PropTypes.oneOf(['button', 'submit', 'reset']),
disabled: PropTypes.bool
};
改进后的完整示例:
import PropTypes from 'prop-types';
function Button({
onClick,
label,
type = 'button',
disabled = false,
ariaLabel,
...restProps
}) {
return (
<button
type={type}
onClick={onClick}
disabled={disabled}
aria-label={ariaLabel || label}
{...restProps}
>
{label ?? 'Button'}
</button>
);
}
Button.propTypes = {
onClick: PropTypes.func.isRequired,
label: PropTypes.string,
type: PropTypes.oneOf(['button', 'submit', 'reset']),
disabled: PropTypes.bool,
ariaLabel: PropTypes.string
};
export default Button;
问题1:缺少依赖注入声明
userRepository 变量未声明,会导致编译错误public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public void saveUser(User user) {
if (user == null) throw new IllegalArgumentException("User cannot be null");
userRepository.save(user);
}
}
问题2:输入验证不完整
public void saveUser(User user) {
if (user == null) {
throw new IllegalArgumentException("User cannot be null");
}
validateUser(user);
userRepository.save(user);
}
private void validateUser(User user) {
if (user.getEmail() == null || user.getEmail().trim().isEmpty()) {
throw new IllegalArgumentException("User email cannot be null or empty");
}
if (user.getUsername() == null || user.getUsername().trim().isEmpty()) {
throw new IllegalArgumentException("User username cannot be null or empty");
}
// 添加其他必要的验证逻辑
}
问题:缺少访问修饰符和依赖注入
@Service
public class UserService {
private static final Logger logger = LoggerFactory.getLogger(UserService.class);
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public void saveUser(User user) {
logger.debug("Saving user: {}", user);
if (user == null) {
throw new IllegalArgumentException("User cannot be null");
}
validateUser(user);
userRepository.save(user);
}
}
问题:缺少日志记录和异常处理
@Service
public class UserService {
private static final Logger logger = LoggerFactory.getLogger(UserService.class);
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public void saveUser(User user) {
logger.info("Attempting to save user with email: {}",
user != null ? user.getEmail() : "null");
if (user == null) {
logger.warn("Attempted to save null user");
throw new IllegalArgumentException("User cannot be null");
}
try {
validateUser(user);
userRepository.save(user);
logger.info("Successfully saved user: {}", user.getEmail());
} catch (Exception e) {
logger.error("Failed to save user: {}", user.getEmail(), e);
throw e;
}
}
}
userRepository字段声明和构造函数注入@Valid注解和JSR-303/380验证规范@Transactional注解确保数据一致性sum()函数提升可读性;)而非英文分号或直接换行return total;return total
items的有效性验证,当传入None、空列表或包含无效对象时可能导致运行时错误items为None,会抛出TypeError: 'NoneType' object is not iterableitems包含没有price属性的对象,会抛出AttributeErrordef calculate_total(items):
if not items:
return 0
total = 0
for item in items:
if not hasattr(item, 'price'):
raise ValueError(f"Item {item} does not have a 'price' attribute")
total += item.price
return total
from typing import List, Union, Any
def calculate_total(items: List[Any]) -> Union[int, float]:
"""
Calculate the total price of all items in the given list.
Args:
items: A list of objects that have a 'price' attribute (numeric type)
Returns:
The sum of all item prices as a numeric value
Raises:
ValueError: If any item in the list doesn't have a 'price' attribute
"""
# 实现逻辑...
性能瓶颈点:手动循环累加虽然功能正确,但不如Python内置函数高效且可读性较差
优化方案:使用sum()函数配合生成器表达式
预期效果:
def calculate_total(items: List[Any]) -> Union[int, float]:
"""Calculate the total price of all items."""
if not items:
return 0
return sum(item.price for item in items)
price属性的对象,建议定义明确的数据结构推荐的最终实现版本:
from typing import List, Any, Union
def calculate_total(items: List[Any]) -> Union[int, float]:
"""
Calculate the total price of all items in the given list.
Args:
items: A list of objects that have a 'price' attribute (numeric type)
Returns:
The sum of all item prices as a numeric value
Raises:
ValueError: If any item in the list doesn't have a 'price' attribute
TypeError: If items is not a list or iterable
"""
if not items:
return 0
try:
return sum(item.price for item in items)
except AttributeError as e:
raise ValueError(f"All items must have a 'price' attribute: {e}")
在提交代码前快速获得专业审查反馈,减少返工,提升代码质量与个人技术成长
统一团队代码风格,识别系统性风险,推动工程规范落地并降低维护成本
将智能审查能力集成到自动化流水线中,实现代码质量门禁与持续质量保障
帮助开发者和团队在敏捷开发、持续集成及协作编码场景中,快速获得专业、可操作的代码审查反馈,提升代码质量、减少技术债务,并推动团队编码规范统一与知识沉淀。
将模板生成的提示词复制粘贴到您常用的 Chat 应用(如 ChatGPT、Claude 等),即可直接对话使用,无需额外开发。适合个人快速体验和轻量使用场景。
把提示词模板转化为 API,您的程序可任意修改模板参数,通过接口直接调用,轻松实现自动化与批量处理。适合开发者集成与业务系统嵌入。
在 MCP client 中配置对应的 server 地址,让您的 AI 应用自动调用提示词模板。适合高级用户和团队协作,让提示词在不同 AI 工具间无缝衔接。
免费获取高级提示词-优惠即将到期