Showing 175 of 175 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

class Migrator {
  public store: Store;

  constructor() {
    this.store = {};
Severity: Major
Found in lib/extend/migrator.ts and 1 other location - About 1 day to fix
lib/extend/deployer.ts on lines 14..41

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 204.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

class Deployer {
  public store: Store;

  constructor() {
    this.store = {};
Severity: Major
Found in lib/extend/deployer.ts and 1 other location - About 1 day to fix
lib/extend/migrator.ts on lines 12..39

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 204.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    function listTagsHelperFactory(tags?: Query<TagSchema> | Options, options?: Options) {
      const transformArgs = () => {
        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 and 1 other location - About 6 hrs to fix
    lib/plugins/helper/tagcloud.ts on lines 99..115

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 156.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    function tagcloudHelperFactory(this: LocalsType, tags?: Query<TagSchema> | Options, options?: Options) {
      const transformArgs = () => {
        if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) {
          options = tags as Options;
          tags = this.site.tags;
    Severity: Major
    Found in lib/plugins/helper/tagcloud.ts and 1 other location - About 6 hrs to fix
    lib/plugins/helper/list_tags.ts on lines 106..122

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 156.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    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

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

        return data.replace(rATag, (str, href) => {
          if (!isExternalLink(href, url, external_link.exclude as any) || rTargetAttr.test(str)) return str;
      
          if (rRelAttr.test(str)) {
            str = str.replace(rRelStrAttr, (relStr, rel) => {
      Severity: Major
      Found in lib/plugins/filter/after_render/external_link.ts and 1 other location - About 4 hrs to fix
      lib/plugins/filter/after_post_render/external_link.ts on lines 21..32

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 133.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

        data.content = data.content.replace(rATag, (str, href) => {
          if (!isExternalLink(href, url, external_link.exclude as any) || rTargetAttr.test(str)) return str;
      
          if (rRelAttr.test(str)) {
            str = str.replace(rRelStrAttr, (relStr, rel) => {
      Severity: Major
      Found in lib/plugins/filter/after_post_render/external_link.ts and 1 other location - About 4 hrs to fix
      lib/plugins/filter/after_render/external_link.ts on lines 20..31

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 133.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          Tag.virtual('posts').get(function() {
            const PostTag = ctx.model('PostTag');
        
            const ids = PostTag.find({tag_id: this._id}).map(item => item.post_id);
        
        
        Severity: Major
        Found in lib/models/tag.ts and 1 other location - About 4 hrs to fix
        lib/models/category.ts on lines 43..51

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 115.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          Category.virtual('posts').get(function() {
            const PostCategory = ctx.model('PostCategory');
        
            const ids = PostCategory.find({category_id: this._id}).map(item => item.post_id);
        
        
        Severity: Major
        Found in lib/models/category.ts and 1 other location - About 4 hrs to fix
        lib/models/tag.ts on lines 34..42

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 115.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              Post.virtual('categories').get(function() {
                const PostCategory = ctx.model('PostCategory');
                const Category = ctx.model('Category');
            
                const ids = PostCategory.find({post_id: this._id}, {lean: true}).map(item => item.category_id);
            Severity: Major
            Found in lib/models/post.ts and 1 other location - About 3 hrs to fix
            lib/models/post.ts on lines 66..73

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 105.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                return tagsGetterCache.apply(this._id, () => {
                  const PostTag = ctx.model('PostTag');
                  const Tag = ctx.model('Tag');
            
                  const ids = PostTag.find({post_id: this._id}, {lean: true}).map(item => item.tag_id);
            Severity: Major
            Found in lib/models/post.ts and 1 other location - About 3 hrs to fix
            lib/models/post.ts on lines 125..132

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 105.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Severity
            Category
            Status
            Source
            Language