Showing 25 of 41 total issues
Function createPolicyStore
has 129 lines of code (exceeds 25 allowed). Consider refactoring. Open
const createPolicyStore = (db: Loki) => {
const psCollection = db.getCollection<IPolicySetCollection>('policy-sets');
/**
* Returns all policy sets.
Function isRuleRelevant
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
const isRuleRelevant = (rule: IRule, req: IPermissionRequest, checkAction = true): boolean => {
if (rule.action && checkAction) {
if (!req.action || !((req.action & rule.action) === req.action)) { return false; }
}
if (rule.subject) {
- 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
File policy-store.ts
has 273 lines of code (exceeds 250 allowed). Consider refactoring. Open
import { Resource } from './../models/resource';
import { NOT_MODIFIED, CREATED, OK, NO_CONTENT } from 'http-status-codes';
import * as lokijs from 'lokijs';
import { IRule } from '../models/rule';
import { Subject } from '../models/subject';
Function createRoutes
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
function createRoutes(secretKey: string, options: INodeAuthOptions) {
const apiRoutes = express.Router();
loginRoute.init(options);
userRoute.init(options);
verifyRoute.init(options);
Function addExtraAttributesToRequest
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function addExtraAttributesToRequest(extraAttributes: IBaseRule, req: IPermissionRequest) {
if (!extraAttributes) { return; }
const subject = extraAttributes.subject;
if (subject) {
if (!req.subject) { req.subject = {}; }
- 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 matchProperties
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
const matchProperties = (ruleProp: boolean | string | number | string[] | number[], reqProp: boolean | string | number | string[] | number[]) => {
if (ruleProp instanceof Array) {
// ruleProp is an array
if (reqProp instanceof Array) {
// they are both arrays
- 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 createNewUser
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
function createNewUser(req: Request, res: Response) {
const name = req['body'].name;
const email = req['body'].email;
const password = req['body'].password;
const admin = req['body'].admin;
- 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 callback
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
const callback = (err: Error, ps: IPolicyStore) => {
if (err) { throw err; }
policyStore = ps;
const auth = NodeAuth(server, <INodeAuthOptions>{
Function createRoutes
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function createRoutes(secretKey: string, options: INodeAuthOptions) {
const apiRoutes = express.Router();
loginRoute.init(options);
userRoute.init(options);
verifyRoute.init(options);
- 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 getPolicyEditor
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
const getPolicyEditor = (policyName: string, policySetName: string) => {
const name = createPolicyName(policySetName, policyName);
const ruleCollection = db.getCollection<IRule>(name);
const getRules = (req: IPermissionRequest) => {
return ruleCollection
Function verifyEmail
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function verifyEmail(req: Request, res: Response) {
const id = req.params['id'];
const token = req.query['t'];
if (!id || !token) {
res.status(BAD_REQUEST).json({ success: false, message: 'Please create a valid request!' });
Function createApiRoute
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function createApiRoute(apiRoutes: express.Router, options: INodeAuthOptions) {
let routes = [];
const apiRoute = (options.api && typeof options.api === 'string') ? options.api : '/api';
Function login
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function login(req: Request, res: Response) {
const email = req['body'].email;
const pwd = req['body'].password;
const token = getToken(req);
Function authenticateUser
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function authenticateUser(secretKey: string, blockUnauthenticatedUser = true) {
const authnErrorHandler = blockUnauthenticatedUser
? (req: express.Request, res: express.Response, next: express.NextFunction, msg?: string) => {
// AuthN failed, so return an error.
res.status(UNAUTHORIZED).json({
Function updateUser
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function updateUser(req: Request, res: Response) {
const updatedUser: IUser = req['body'];
const id: string = req.params['id'];
const user: IUser = req['user'];
Function createPrivileges
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function createPrivileges(req: Request, res: Response) {
const handler = (newPrivilegeReq: IPrivilegeRequest) => {
return (msg: ResponseMessage) => {
if (msg.success) {
const ruleStatus = createPrivilege(newPrivilegeReq);
- 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 deletePrivileges
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function deletePrivileges(req: Request, res: Response) {
const handler = (newPrivilege: IPrivilegeRequest) => {
return (msg: ResponseMessage) => {
if (msg.success) {
const ruleStatus = deletePrivilege(newPrivilege);
- 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 updatePrivileges
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function updatePrivileges(req: Request, res: Response) {
const handler = (newPrivilege: IPrivilegeRequest) => {
return (msg: ResponseMessage) => {
if (msg.success) {
const ruleStatus = updatePrivilege(newPrivilege);
- 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 createApiRoute
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function createApiRoute(apiRoutes: express.Router, options: INodeAuthOptions) {
let routes = [];
const apiRoute = (options.api && typeof options.api === 'string') ? options.api : '/api';
- 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 getPolicyEditor
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function getPolicyEditor(newPrivilege: IPrivilegeRequest) {
const policy = newPrivilege.policy || -1;
if (typeof policy === 'number') {
const policySet = policyStore.getPolicySet(newPrivilege.policySet);
if (policy >= policySet.policies.length) { return null; }
- 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"