Showing 172 of 172 total issues

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

Avoid too many return statements within this function.
Open

  return [];
Severity: Major
Found in lib/plugins/renderer/nunjucks.ts - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

      return result;
    Severity: Major
    Found in lib/hexo/render.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          return Object.values(value);
      Severity: Major
      Found in lib/plugins/renderer/nunjucks.ts - About 30 mins to fix

        Function getMoment has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        function getMoment(date: moment.MomentInput | moment.Moment, lang: string, timezone: string): moment.Moment {
          if (date == null) date = moment();
          if (!isMoment(date)) date = moment(isDate(date) ? <Date>date : new Date(<string | number>date));
          lang = _toMomentLocale(lang);
        
        
        Severity: Minor
        Found in lib/plugins/helper/date.ts - About 25 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

        Function exports has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        module.exports = function(code, options) {
          const prismjsCfg = this.config.prismjs || {};
          const line_threshold = options.line_threshold || prismjsCfg.line_threshold || 0;
          const shouldUseLineNumbers = typeof options.line_number === 'undefined' ? prismjsCfg.line_number : options.line_number;
          const surpassesLineThreshold = options.lines_length > line_threshold;
        Severity: Minor
        Found in lib/plugins/highlight/prism.ts - About 25 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

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

          register(pattern: patternType | StoreFunction, fn?: StoreFunction): void {
            if (!fn) {
              if (typeof pattern === 'function') {
                fn = pattern;
                pattern = /(.*)/;
        Severity: Minor
        Found in lib/extend/processor.ts - About 25 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

        Function shouldSkipAsset has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        function shouldSkipAsset(ctx: Hexo, post, asset) {
          if (!ctx._showDrafts()) {
            if (post.published === false && asset) {
              // delete existing draft assets if draft posts are hidden
              asset.remove();
        Severity: Minor
        Found in lib/plugins/processor/post.ts - About 25 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

        Function processAsset has a Cognitive Complexity of 6 (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 doc = PostAsset.findById(id);
        Severity: Minor
        Found in lib/plugins/processor/post.ts - About 25 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

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

          register(type: string | StoreFunction, fn?: StoreFunction | number, priority?: number): void {
            if (!priority) {
              if (typeof type === 'function') {
                priority = fn as number;
                fn = type;
        Severity: Minor
        Found in lib/extend/filter.ts - About 25 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

        Function _injector has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          _injector(input: string, pattern: string | RegExp, flag: Entry, isBegin = true, currentType: string): string {
            if (input.includes(`hexo injector ${flag}`)) return input;
        
            const code = this.cache.apply(`${flag}-${currentType}-code`, () => {
              const content = currentType === 'default' ? this.getText(flag, 'default') : this.getText(flag, currentType) + this.getText(flag, 'default');
        Severity: Minor
        Found in lib/extend/injector.ts - About 25 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

        Function render has a Cognitive Complexity of 6 (exceeds 5 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 25 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

        Severity
        Category
        Status
        Source
        Language