Showing 3 of 3 total issues
Function canMiddleware
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
ACL.prototype.canMiddleware = function canMiddleware(req, res, callback) {
let acl = req.acl || req.we.acl;
// aff method in request for check if current user can do something
req.can = acl.requestCan.bind({ req: req, res: res, acl: acl});
// user role names, add user roles here after load current request user
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function checkIfCanInRoles
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
ACL.prototype.checkIfCanInRoles = function checkIfCanInRoles(permissionName, roleNames) {
for (let i = roleNames.length - 1; i >= 0; i--) {
if (!this.roles[roleNames[i]]) continue; // role not exists
if (!this.roles[roleNames[i]].permissions) continue; // this role dont have permissions
// check if role have the permission
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function createRole
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
ACL.prototype.createRole = function createRole (data, cb){
const self = this;
if (typeof data === 'string') {
let name = data;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"