lib/hexo/post.ts

Summary

Maintainability
F
4 days
Test Coverage

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;
Severity: Minor
Found in lib/hexo/post.ts - About 1 day to fix

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';
Severity: Minor
Found in lib/hexo/post.ts - About 4 hrs to fix

    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;
    Severity: Major
    Found in lib/hexo/post.ts - About 4 hrs to fix

      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) : '');
      Severity: Major
      Found in lib/hexo/post.ts - About 2 hrs to fix

        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, '\\"')}"`;
        Severity: Critical
        Found in lib/hexo/post.ts - About 2 hrs to fix

          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;
              }
          Severity: Minor
          Found in lib/hexo/post.ts - About 1 hr to fix

            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 => {
            Severity: Minor
            Found in lib/hexo/post.ts - About 1 hr to fix

              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)) {
              Severity: Minor
              Found in lib/hexo/post.ts - About 55 mins to fix

              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;
              Severity: Major
              Found in lib/hexo/post.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if (isNonWhiteSpaceChar(char)) {
                            if (!swig_tag_name_begin && !swig_tag_name_end) {
                              swig_tag_name_begin = true;
                            }
                
                
                Severity: Major
                Found in lib/hexo/post.ts - About 45 mins to fix

                  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 = '';
                  Severity: Major
                  Found in lib/hexo/post.ts - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            if (char === '}' && next_char === '}') {
                              idx++;
                              state = STATE_PLAINTEXT;
                              output += PostRenderEscape.escapeContent(this.stored, 'swig', `{{${buffer}}}`);
                              buffer = '';
                    Severity: Major
                    Found in lib/hexo/post.ts - About 45 mins to fix

                      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) : '');
                      Severity: Minor
                      Found in lib/hexo/post.ts - About 35 mins to fix

                      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

                      There are no issues that match your filters.

                      Category
                      Status