Showing 175 of 175 total issues

Function processAsset has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function processAsset(ctx: Hexo, file: _File) {
  const PostAsset = ctx.model('PostAsset');
  const Post = ctx.model('Post');
  const id = file.source.substring(ctx.base_dir.length);
  const postAsset = PostAsset.findById(id);
Severity: Minor
Found in lib/plugins/processor/post.ts - About 1 hr 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 tagcloudHelper has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function tagcloudHelper(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: Minor
Found in lib/plugins/helper/tagcloud.ts - About 1 hr 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 content has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    data.content = dataContent.replace(rBacktick, ($0, start, $2, _args, _content, end) => {
      let content = _content.replace(/\n$/, '');

      // neither highlight or prismjs is enabled, return escaped content directly.
      if (!ctx.extend.highlight.query(ctx.config.syntax_highlighter)) return escapeSwigTag($0);
Severity: Minor
Found in lib/plugins/filter/before_post_render/backtick_code_block.ts - About 1 hr to fix

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

        if (doc) {
          if (file.type !== 'update') {
            ctx.log.warn(`Trying to "create" ${magenta(file.path)}, but the file already exists!`);
          }
          return doc.replace(data);
    Severity: Major
    Found in lib/plugins/processor/post.ts and 1 other location - About 1 hr to fix
    lib/plugins/processor/asset.ts on lines 100..105

    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 65.

    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

        if (doc) {
          if (file.type !== 'update') {
            ctx.log.warn(`Trying to "create" ${magenta(file.path)}, but the file already exists!`);
          }
          return doc.replace(data);
    Severity: Major
    Found in lib/plugins/processor/asset.ts and 1 other location - About 1 hr to fix
    lib/plugins/processor/post.ts on lines 171..176

    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 65.

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

    function deployConsole(this: Hexo, args: DeployArgs) {
      let config = this.config.deploy;
      const deployers = this.extend.deployer.list();
    
      if (!config) {
    Severity: Minor
    Found in lib/plugins/console/deploy.ts - About 1 hr 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

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

        export = (ctx: Hexo) => {
          const { filter } = ctx.extend;
        
          filter.register('after_render:html', require('./external_link'));
          filter.register('after_render:html', require('./meta_generator'));
        Severity: Major
        Found in lib/plugins/filter/after_render/index.ts and 1 other location - About 1 hr to fix
        lib/plugins/filter/after_post_render/index.ts on lines 3..8

        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 64.

        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

        export = (ctx: Hexo) => {
          const { filter } = ctx.extend;
        
          filter.register('after_post_render', require('./external_link'));
          filter.register('after_post_render', require('./excerpt'));
        Severity: Major
        Found in lib/plugins/filter/after_post_render/index.ts and 1 other location - About 1 hr to fix
        lib/plugins/filter/after_render/index.ts on lines 3..8

        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 64.

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

          return function imgTag(args: string[]) {
            const classes = [];
            let src, width, height, title, alt;
        
            // Find image URL and class name
        Severity: Minor
        Found in lib/plugins/tag/img.ts - About 1 hr to fix

          Function listCategoriesHelper has a Cognitive Complexity of 12 (exceeds 5 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: Minor
          Found in lib/plugins/helper/list_categories.ts - About 1 hr 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 listPostsHelper has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function listPostsHelper(this: LocalsType, posts?: Query<PostSchema> | Options, options?: Options) {
            if (!options && (!posts || !Object.prototype.hasOwnProperty.call(posts, 'length'))) {
              options = posts as Options;
              posts = this.site.posts;
            }
          Severity: Minor
          Found in lib/plugins/helper/list_posts.ts - About 1 hr to fix

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

              return exists(dbPath).then(exist => {
                if (!exist) return;
            
                return unlink(dbPath).then(() => {
                  ctx.log.info('Deleted database.');
            Severity: Major
            Found in lib/plugins/console/clean.ts and 1 other location - About 1 hr to fix
            lib/plugins/console/clean.ts on lines 28..34

            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 63.

            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 exists(publicDir).then(exist => {
                if (!exist) return;
            
                return rmdir(publicDir).then(() => {
                  ctx.log.info('Deleted public folder.');
            Severity: Major
            Found in lib/plugins/console/clean.ts and 1 other location - About 1 hr to fix
            lib/plugins/console/clean.ts on lines 16..22

            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 63.

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

              render(data: StoreFunctionData, options?: any | NodeJSLikeCallback<any>, callback?: NodeJSLikeCallback<any>): Promise<any> {
                if (!callback && typeof options === 'function') {
                  callback = options;
                  options = {};
                }
            Severity: Minor
            Found in lib/hexo/render.ts - About 1 hr to fix

              Function register has 34 lines of code (exceeds 25 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 1 hr to fix

                Function numberFormatHelper has 34 lines of code (exceeds 25 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 1 hr to fix

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

                    if (updated) {
                      if ((isMoment(updated) || isDate(updated)) && !isNaN(updated.valueOf())) {
                        result += og('article:modified_time', updated.toISOString());
                      }
                    }
                  Severity: Major
                  Found in lib/plugins/helper/open_graph.ts and 1 other location - About 1 hr to fix
                  lib/plugins/helper/open_graph.ts on lines 144..148

                  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 62.

                  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

                    if (date) {
                      if ((isMoment(date) || isDate(date)) && !isNaN(date.valueOf())) {
                        result += og('article:published_time', date.toISOString());
                      }
                    }
                  Severity: Major
                  Found in lib/plugins/helper/open_graph.ts and 1 other location - About 1 hr to fix
                  lib/plugins/helper/open_graph.ts on lines 150..154

                  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 62.

                  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

                  Consider simplifying this complex logical expression.
                  Open

                      } else if (info && info.year && (info.month || info.i_month) && (info.day || info.i_day)) {
                        data.date = new Date(
                          info.year,
                          parseInt(info.month || info.i_month, 10) - 1,
                          parseInt(info.day || info.i_day, 10)
                  Severity: Critical
                  Found in lib/plugins/processor/post.ts - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language