I am using JSCS with Google preset style rules to check my code and I have a method in a DAO class defined like so:
/**
* Inserts a new user into database.
*
* @param {User} user User to insert.
* @return {User} Last inserted user. // Redundant return statement
* @throws Error if query fails.
* @since 1.0
*/
add(user) {
this.pool.getConnection((err, conn) => {
conn.query('INSERT INTO users SET ?', user, (err, rows) => {
if (err) {
throw err;
}
conn.release();
return this.getById(rows.insertId);
});
});
}
JSCS marks JSDoc @return
tag as redundant because it can't find a return statement inside add(user)
function scope, but it actually resides inside the anonymous callback (err, rows) => { ... }
.
How can I correctly document that return statement? Is my approach wrong or bad in some way?