Showing 23 of 54 total issues
File common.ts
has 451 lines of code (exceeds 250 allowed). Consider refactoring. Open
import Notation from 'notation';
import Matcher from 'matcher';
import { ArrayUtil } from './array';
import { ConditionUtil } from '../conditions';
import { AccessControlError, IQueryInfo, IAccessInfo, ICondition } from '../core';
CommonUtil
has 43 functions (exceeds 20 allowed). Consider refactoring. Open
export class CommonUtil {
public static isStringOrArray(value: any): boolean {
return typeof value === 'string' || ArrayUtil.isFilledStringArray(value);
}
AccessControl
has 31 functions (exceeds 20 allowed). Consider refactoring. Open
class AccessControl {
/**
* @private
*/
private _grants: any;
Function getFlatRolesSync
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public static getFlatRolesSync(grants: any, roles: string | string[], context?: any, skipConditions?: boolean): string[] {
roles = ArrayUtil.toStringArray(roles);
if (!roles) throw new AccessControlError(`Invalid role(s): ${JSON.stringify(roles)}`);
let arr: string[] = roles.slice();
for (let roleName of roles) {
- 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 getFlatRoles
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public static async getFlatRoles(grants: any, roles: string | string[], context?: any, skipConditions?: boolean): Promise<string[]> {
roles = ArrayUtil.toStringArray(roles);
if (!roles) throw new AccessControlError(`Invalid role(s): ${JSON.stringify(roles)}`);
let arr: string[] = roles.slice();
for (let roleName of roles) {
- 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 evaluate
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static evaluate(
condition: ICondition,
context: any
): boolean | Promise<boolean> {
if (!condition) {
- 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 filterGrantsAllowingSync
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static filterGrantsAllowingSync(grants: IAccessInfo[], query: IQueryInfo): IAccessInfo[] {
if (query.skipConditions) {
return grants;
} else {
const matchingGrants = [];
- 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 evaluate
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static evaluate(
condition: ICondition,
context: any
): boolean | Promise<boolean> {
if (!condition) {
Function validateCondition
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static validateCondition(condition) {
if (!condition) {
return;
}
- 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
Avoid deeply nested control flow statements. Open
if (typeof (conditionResult) !== 'boolean') {
throw new AccessControlError(`Expected the condition function should return boolean, but returning ${conditionResult}`);
} else if (conditionResult === true) {
rolesMetCondition.push(extendedRoleName);
}
Avoid deeply nested control flow statements. Open
if (await ConditionUtil.evaluate(roleItem.$extend[extendedRoleName].condition,
context)) {
rolesMetCondition.push(extendedRoleName);
}
Function isAllowed
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
AccessControl.isAllowed = function (account, user, resource, action, context) {
Function getAllowedAttributes
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
AccessControl.getAllowedAttributes = function (account, user, resource, action, context) {
Function normalizeQueryInfo
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static normalizeQueryInfo(query: IQueryInfo): IQueryInfo {
// clone the object
const newQuery: IQueryInfo = this.clone(query);
// validate and normalize role(s)
newQuery.role = ArrayUtil.toStringArray(newQuery.role);
- 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 filterGrantsAllowing
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static async filterGrantsAllowing(grants: IAccessInfo[], query: IQueryInfo): Promise<IAccessInfo[]> {
if (query.skipConditions) {
return grants;
} else {
const matchingGrants = [];
- 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
Avoid too many return
statements within this function. Open
return ConditionUtil._customConditionFunctions[condition.Fn](context, condition.args);
Avoid too many return
statements within this function. Open
return false;
Function evaluate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
evaluate(args?: any, context?: any): boolean | Promise<boolean> {
if (!args) {
return true;
}
- 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 evaluate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
evaluate(args?: any, context?: any): boolean | Promise<boolean> {
if (!args) {
return true;
}
- 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 areExtendingRolesAllowingSync
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static areExtendingRolesAllowingSync(roleExtensionObject: any, allowingRoles: any, query: IQueryInfo): boolean {
if (!roleExtensionObject) {
return false;
}
let result = false;
- 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"