scripts/apps/authoring-react/toolbar/template-helpers.ts
Function applyMiddleware
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
export function applyMiddleware(_item: IArticle): Promise<IArticle> {
// Custom field types with `onTemplateCreate` defined. From all extensions.
const fieldTypes: {[id: string]: ICustomFieldType<any, any, any, any>} = {};
Object.values(extensions).forEach((ext) => {
Function cleanData
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
export function cleanData<T>(data: Partial<T>): Partial<T> {
[
'_type',
'_status',
'_updated',
Avoid too many return
statements within this function. Open
Open
return privileges.userHasPrivileges({personal_template: 1}); // can edit templates of other users
Function canEdit
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
export function canEdit(template: ITemplate, isPublic: boolean): boolean {
const privileges = ng.get('privileges');
if (template == null) {
return 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"