Showing 103 of 172 total issues

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 index.ts has 500 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Promise from 'bluebird';
import { sep, join, dirname } from 'path';
import tildify from 'tildify';
import Database from 'warehouse';
import { magenta, underline } from 'picocolors';
Severity: Minor
Found in lib/hexo/index.ts - About 1 day to fix

    Function openGraphHelper has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

    function openGraphHelper(this: LocalsType, options: Options = {}) {
      const { config, page } = this;
      const { content } = page;
      let images = options.image || options.images || page.photos || [];
      let description = options.description || page.description || page.excerpt || content || config.description;
    Severity: Minor
    Found in lib/plugins/helper/open_graph.ts - About 6 hrs 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

    Function parseArgs has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

    function parseArgs(args: string[]): HighlightOptions {
      const _else = [];
      const len = args.length;
      let lang: string, language_attr: boolean,
        line_number: boolean, line_threshold: number, wrap: boolean;
    Severity: Minor
    Found in lib/plugins/tag/code.ts - About 6 hrs 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

    Function listArchivesHelper has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

    function listArchivesHelper(this: LocalsType, options: Options = {}) {
      const { config } = this;
      const archiveDir = config.archive_dir;
      const { timezone } = config;
      const lang = toMomentLocale(this.page.lang || this.page.language || config.language);
    Severity: Minor
    Found in lib/plugins/helper/list_archives.ts - About 5 hrs 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 tocHelper has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

      function tocHelper(str: string, options: Options = {}) {
        options = Object.assign({
          min_depth: 1,
          max_depth: 6,
          class: 'toc',
      Severity: Minor
      Found in lib/plugins/helper/toc.ts - About 4 hrs 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

      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 openGraphHelper has 97 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function openGraphHelper(this: LocalsType, options: Options = {}) {
          const { config, page } = this;
          const { content } = page;
          let images = options.image || options.images || page.photos || [];
          let description = options.description || page.description || page.excerpt || content || config.description;
        Severity: Major
        Found in lib/plugins/helper/open_graph.ts - About 3 hrs to fix

          Function processPost has 94 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function processPost(ctx: Hexo, file: _File) {
            const Post = ctx.model('Post');
            const { path } = file.params;
            const doc = Post.findOne({source: file.path});
            const { config } = ctx;
          Severity: Major
          Found in lib/plugins/processor/post.ts - About 3 hrs to fix

            Function postPermalinkFilter has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
            Open

            function postPermalinkFilter(this: Hexo, data: PostSchema): string {
              const { config } = this;
              const { id, _id, slug, title, date } = data;
              let { __permalink } = data;
              const { post_asset_folder } = config;
            Severity: Minor
            Found in lib/plugins/filter/post_permalink.ts - About 3 hrs 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

            Function parseArgs has 78 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function parseArgs(args: string[]): HighlightOptions {
              const _else = [];
              const len = args.length;
              let lang: string, language_attr: boolean,
                line_number: boolean, line_threshold: number, wrap: boolean;
            Severity: Major
            Found in lib/plugins/tag/code.ts - About 3 hrs to fix

              Function makeFeedTag has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
              Open

              function makeFeedTag(this: LocalsType, path?: string, options: Options = {}, configFeed?: any, configTitle?: string) {
                const title = options.title || configTitle;
              
                if (path) {
                  if (typeof path !== 'string') throw new TypeError('path must be a string!');
              Severity: Minor
              Found in lib/plugins/helper/feed_tag.ts - About 3 hrs 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

              Function listCategoriesHelper has 77 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function listCategoriesHelper(this: LocalsType, categories?: Query<CategorySchema> | Options, options?: Options) {
                if (!options && (!categories || !Object.prototype.hasOwnProperty.call(categories, 'length'))) {
                  options = categories as Options;
                  categories = this.site.categories;
                }
              Severity: Major
              Found in lib/plugins/helper/list_categories.ts - About 3 hrs to fix

                Function listArchivesHelper has 75 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function listArchivesHelper(this: LocalsType, options: Options = {}) {
                  const { config } = this;
                  const archiveDir = config.archive_dir;
                  const { timezone } = config;
                  const lang = toMomentLocale(this.page.lang || this.page.language || config.language);
                Severity: Major
                Found in lib/plugins/helper/list_archives.ts - About 3 hrs to fix

                  Function numberFormatHelper has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function numberFormatHelper(num: number, options: Options = {}) {
                    const split = num.toString().split('.');
                    let before = split.shift();
                    let after = split.length ? split[0] : '';
                    const delimiter = options.delimiter || ',';
                  Severity: Minor
                  Found in lib/plugins/helper/number_format.ts - About 2 hrs 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

                  Function register has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                  Open

                    register(name: string, desc: string | Option | AnyFn, options?: Option | AnyFn, fn?: AnyFn): void {
                      if (!name) throw new TypeError('name is required');
                  
                      if (!fn) {
                        if (options) {
                  Severity: Minor
                  Found in lib/extend/console.ts - About 2 hrs 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

                  Function tocHelper has 68 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function tocHelper(str: string, options: Options = {}) {
                    options = Object.assign({
                      min_depth: 1,
                      max_depth: 6,
                      class: 'toc',
                  Severity: Major
                  Found in lib/plugins/helper/toc.ts - About 2 hrs to fix

                    Function listTagsHelper has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function listTagsHelper(this: LocalsType, tags?: Query<TagSchema> | Options, options?: Options) {
                      if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) {
                        options = tags as Options;
                        tags = this.site.tags;
                      }
                    Severity: Major
                    Found in lib/plugins/helper/list_tags.ts - About 2 hrs to fix

                      Function newPostPathFilter has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function newPostPathFilter(this: Hexo, data: PostSchema = {}, replace?: boolean): Promise<string> {
                        const sourceDir = this.source_dir;
                        const draftDir = join(sourceDir, '_drafts');
                        const postDir = join(sourceDir, '_posts');
                        const { config } = this;
                      Severity: Minor
                      Found in lib/plugins/filter/new_post_path.ts - About 2 hrs 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

                      Severity
                      Category
                      Status
                      Source
                      Language