lib/hexo/index.ts

Summary

Maintainability
D
2 days
Test Coverage

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

      constructor(base = process.cwd(), args: Args = {}) {
        super();
    
        this.base_dir = base + sep;
        this.public_dir = join(base, 'public') + sep;
    Severity: Major
    Found in lib/hexo/index.ts - About 2 hrs to fix

      Function _bindLocals has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _bindLocals(): void {
          const db = this.database;
          const { locals } = this;
      
          locals.set('posts', () => {
      Severity: Minor
      Found in lib/hexo/index.ts - About 1 hr to fix

        Function createLoadThemeRoute has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const createLoadThemeRoute = function(generatorResult: NormalPageGenerator | NormalPostGenerator, locals: LocalsType, ctx: Hexo) {
          const { log, theme } = ctx;
          const { path, cache: useCache } = locals;
        
          const layout: string[] = [...new Set(castArray(generatorResult.layout))];
        Severity: Minor
        Found in lib/hexo/index.ts - About 1 hr to fix

          Function _generateLocals has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _generateLocals() {
              const { config, env, theme, theme_dir } = this;
              const ctx = { config: { url: this.config.url } };
              const localsObj = this.locals.toObject() as SiteLocals;
          
          
          Severity: Minor
          Found in lib/hexo/index.ts - About 1 hr to fix

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

                return loadDatabase(this).then(() => {
                  this.log.info('Start processing');
            
                  return Promise.all([
                    this.source.process(),
            Severity: Major
            Found in lib/hexo/index.ts and 1 other location - About 1 hr to fix
            lib/hexo/index.ts on lines 530..547

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

            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 loadDatabase(this).then(() => {
                  this.log.info('Start processing');
            
                  return Promise.all([
                    this.source.watch(),
            Severity: Major
            Found in lib/hexo/index.ts and 1 other location - About 1 hr to fix
            lib/hexo/index.ts on lines 504..514

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

            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

                locals.set('categories', () => {
                  // Ignore categories with zero posts
                  return db.model('Category').filter(category => category.length);
                });
            Severity: Minor
            Found in lib/hexo/index.ts and 1 other location - About 35 mins to fix
            lib/hexo/index.ts on lines 394..397

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

            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

                locals.set('tags', () => {
                  // Ignore tags with zero posts
                  return db.model('Tag').filter(tag => tag.length);
                });
            Severity: Minor
            Found in lib/hexo/index.ts and 1 other location - About 35 mins to fix
            lib/hexo/index.ts on lines 389..392

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

            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

            There are no issues that match your filters.

            Category
            Status