创建猫鼬模式的预钩时出现Airbnb掉毛错误

时间:2019-05-19 20:03:18

标签: node.js mongoose eslint bcrypt

我正在尝试使用bcrypt对用户架构上的密码进行哈希处理,并且我的linting配置抛出了一些我想修复的错误,但是现在我不知道该怎么做:

userSchema.pre('save', function (next) {
  const user = this;

  if (!user.isModified('password')) return next();

  bcrypt.genSalt(10, (genErr, salt) => {
    if (genErr) return next(genErr);
    bcrypt.hash(user.passowrd, salt, (hashErr, hash) => {
      if (hashErr) return next(hashErr);
      user.password = hash;
      next();
    });
  });
});

这是我的保存前钩子,这是the条在控制台上引发的错误:

  24:24  error    Expected to return a value at the end of function        consistent-return
  24:24  warning  Unexpected unnamed function                              func-names
  29:37  error    Expected to return a value at the end of arrow function  consistent-return
  31:54  error    Expected to return a value at the end of arrow function  consistent-return

我知道我可以禁用这些错误和警告,但是我更愿意修复它们。有办法吗?预先感谢!

0 个答案:

没有答案