Function escapeAllSwigTags
has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring. Open
escapeAllSwigTags(str: string) {
if (!/(\{\{.+?\}\})|(\{#.+?#\})|(\{%.+?%\})/s.test(str)) {
return str;
}
let state = STATE_PLAINTEXT;
- 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 post.ts
has 372 lines of code (exceeds 250 allowed). Consider refactoring. Open
import assert from 'assert';
import moment from 'moment';
import Promise from 'bluebird';
import { join, extname, basename } from 'path';
import { magenta } from 'picocolors';
Function escapeAllSwigTags
has 107 lines of code (exceeds 25 allowed). Consider refactoring. Open
escapeAllSwigTags(str: string) {
if (!/(\{\{.+?\}\})|(\{#.+?#\})|(\{%.+?%\})/s.test(str)) {
return str;
}
let state = STATE_PLAINTEXT;
Function render
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
render(source: string, data: RenderData = {}, callback?: NodeJSLikeCallback<never>) {
const ctx = this.context;
const { config } = ctx;
const { tag } = ctx.extend;
const ext = data.engine || (source ? extname(source) : '');
Consider simplifying this complex logical expression. Open
if (jsonMode || item.includes(':') || item.startsWith('#') || item.startsWith('!!')
|| item.includes('{') || item.includes('}') || item.includes('[') || item.includes(']')
|| item.includes('\'') || item.includes('"')) data[key] = `"${item.replace(/"/g, '\\"')}"`;
Function publish
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
publish(data: PostData, replace?: boolean | NodeJSLikeCallback<Result>, callback?: NodeJSLikeCallback<Result>) {
if (!callback && typeof replace === 'function') {
callback = replace;
replace = false;
}
Function _renderScaffold
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
_renderScaffold(data: PostData) {
const { tag } = this.context.extend;
let splitted;
return this._getScaffold(data.layout).then(scaffold => {
Function prepareFrontMatter
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
const prepareFrontMatter = (data: any, jsonMode: boolean) => {
for (const [key, item] of Object.entries(data)) {
if (moment.isMoment(item)) {
data[key] = item.utc().format('YYYY-MM-DD HH:mm:ss');
} else if (moment.isDate(item)) {
- 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 (swig_tag_name !== '' && str.includes(`end${swig_tag_name}`)) {
state = STATE_SWIG_FULL_TAG;
} else {
swig_tag_name = '';
state = STATE_PLAINTEXT;
Avoid deeply nested control flow statements. Open
if (isNonWhiteSpaceChar(char)) {
if (!swig_tag_name_begin && !swig_tag_name_end) {
swig_tag_name_begin = true;
}
Avoid deeply nested control flow statements. Open
} else if (state === STATE_SWIG_COMMENT) { // From swig back to plain text
if (char === '#' && next_char === '}') {
idx++;
state = STATE_PLAINTEXT;
buffer = '';
Avoid deeply nested control flow statements. Open
if (char === '}' && next_char === '}') {
idx++;
state = STATE_PLAINTEXT;
output += PostRenderEscape.escapeContent(this.stored, 'swig', `{{${buffer}}}`);
buffer = '';
Function render
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
render(source: string, data: RenderData = {}, callback?: NodeJSLikeCallback<never>) {
const ctx = this.context;
const { config } = ctx;
const { tag } = ctx.extend;
const ext = data.engine || (source ? extname(source) : '');
- 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"