Showing 175 of 175 total issues

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

  Post.pre('remove', data => {
    const PostCategory = ctx.model('PostCategory');
    return PostCategory.remove({post_id: data._id});
  });
Severity: Major
Found in lib/models/post.ts and 1 other location - About 1 hr to fix
lib/models/post.ts on lines 208..211

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

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

const parseFooter = (args: string[], ctx: Hexo) => {
  const str = args.join(' ');
  if (!str) return '';

  let author = '';
Severity: Minor
Found in lib/plugins/tag/blockquote.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

      Function set has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        set(path: string, data: any): this {
          if (typeof path !== 'string') throw new TypeError('path must be a string!');
          if (data == null) throw new TypeError('data is required!');
      
          let obj: Data;
      Severity: Minor
      Found in lib/hexo/router.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 addHierarchy has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          const addHierarchy = (catHierarchy: string | string[]) => {
            const parentIds = [];
            if (!Array.isArray(catHierarchy)) catHierarchy = [catHierarchy];
            // Don't use "Promise.map". It doesn't run in series.
            // MUST USE "Promise.each".
      Severity: Minor
      Found in lib/models/post.ts - About 1 hr to fix

        Function _renderScaffold has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _renderScaffold(data: PostData) {
            const { tag } = this.context.extend;
            let splitted;
        
            return this._getScaffold(data.layout).then(scaffold => {
        Severity: Minor
        Found in lib/hexo/post.ts - About 1 hr to fix

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

            Category.pre('remove', data => {
              const PostCategory = ctx.model('PostCategory');
              return PostCategory.remove({category_id: data._id});
            });
          Severity: Major
          Found in lib/models/category.ts and 2 other locations - About 1 hr to fix
          lib/models/post.ts on lines 220..223
          lib/models/tag.ts on lines 66..69

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

          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 3 locations. Consider refactoring.
          Open

            Post.pre('remove', data => {
              const PostAsset = ctx.model('PostAsset');
              return PostAsset.remove({post: data._id});
            });
          Severity: Major
          Found in lib/models/post.ts and 2 other locations - About 1 hr to fix
          lib/models/category.ts on lines 76..79
          lib/models/tag.ts on lines 66..69

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

          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 3 locations. Consider refactoring.
          Open

            Tag.pre('remove', data => {
              const PostTag = ctx.model('PostTag');
              return PostTag.remove({tag_id: data._id});
            });
          Severity: Major
          Found in lib/models/tag.ts and 2 other locations - About 1 hr to fix
          lib/models/category.ts on lines 76..79
          lib/models/post.ts on lines 220..223

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

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

          function parseFilename(config: string, path: string) {
            config = config.substring(0, config.length - extname(config).length);
            path = path.substring(0, path.length - extname(path).length);
          
            if (!permalink || permalink.rule !== config) {
          Severity: Minor
          Found in lib/plugins/processor/post.ts - About 1 hr to fix

            Function scanAssetDir has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function scanAssetDir(ctx: Hexo, post) {
              if (!ctx.config.post_asset_folder) return;
            
              const assetDir = post.asset_dir;
              const baseDir = ctx.base_dir;
            Severity: Minor
            Found in lib/plugins/processor/post.ts - About 1 hr to fix

              Function postLinkTag has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                return function postLinkTag(args: string[]) {
                  let slug = args.shift();
                  if (!slug) {
                    throw new Error(`Post not found: "${slug}" doesn't exist for {% post_link %}`);
                  }
              Severity: Minor
              Found in lib/plugins/tag/post_link.ts - About 1 hr to fix

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

                          const data = Category.findOne({
                            name: cat,
                            parent: i ? parentIds[i - 1] : {$exists: false}
                          }, {lean: true});
                Severity: Major
                Found in lib/models/post.ts and 1 other location - About 1 hr to fix
                lib/models/post.ts on lines 160..163

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

                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

                        const data = Category.findOne({
                          name: cat,
                          parent: i ? parentIds[i - 1] : {$exists: false}
                        }, {lean: true});
                Severity: Major
                Found in lib/models/post.ts and 1 other location - About 1 hr to fix
                lib/models/post.ts on lines 177..180

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

                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

                  console.register('config', 'Get or set configurations.', {
                    usage: '[name] [value]',
                    arguments: [
                      {name: 'name', desc: 'Setting name. Leave it blank if you want to show all configurations.'},
                      {name: 'value', desc: 'New value of a setting. Leave it blank if you just want to show a single configuration.'}
                Severity: Minor
                Found in lib/plugins/console/index.ts and 1 other location - About 55 mins to fix
                lib/plugins/console/index.ts on lines 62..68

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

                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

                  console.register('publish', 'Moves a draft post from _drafts to _posts folder.', {
                    usage: '[layout] <filename>',
                    arguments: [
                      {name: 'layout', desc: 'Post layout. Use post, page, draft or whatever you want.'},
                      {name: 'filename', desc: 'Draft filename. "hello-world" for example.'}
                Severity: Minor
                Found in lib/plugins/console/index.ts and 1 other location - About 55 mins to fix
                lib/plugins/console/index.ts on lines 8..14

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

                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 (data.date) {
                      if (timezoneCfg) data.date = timezone(data.date, timezoneCfg);
                    } else {
                      data.date = stats.birthtime;
                    }
                Severity: Minor
                Found in lib/plugins/processor/post.ts and 1 other location - About 55 mins to fix
                lib/plugins/processor/asset.ts on lines 63..67

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

                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 (data.date) {
                      if (timezoneCfg) data.date = timezone(data.date, timezoneCfg);
                    } else {
                      data.date = stats.ctime;
                    }
                Severity: Minor
                Found in lib/plugins/processor/asset.ts and 1 other location - About 55 mins to fix
                lib/plugins/processor/post.ts on lines 123..127

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

                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 newConsole has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                function newConsole(this: Hexo, args: NewArgs) {
                  const path = args.p || args.path;
                  let title: string;
                  if (args._.length) {
                    title = args._.pop();
                Severity: Minor
                Found in lib/plugins/console/new.ts - About 55 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 paginatorHelper has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                function paginatorHelper(this: LocalsType, options: Options = {}) {
                  options = Object.assign({
                    base: this.page.base || '',
                    current: this.page.current || 0,
                    format: `${this.config.pagination_dir}/%d/`,
                Severity: Minor
                Found in lib/plugins/helper/paginator.ts - About 55 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