Showing 175 of 175 total issues

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

    if (data.updated) {
      if (timezoneCfg) data.updated = timezone(data.updated, timezoneCfg);
    } else if (updated_option === 'date') {
      data.updated = data.date;
    } else if (updated_option === 'empty') {
Severity: Major
Found in lib/plugins/processor/asset.ts and 1 other location - About 3 hrs to fix
lib/plugins/processor/post.ts on lines 131..139

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

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 (data.updated) {
      if (timezoneCfg) data.updated = timezone(data.updated, timezoneCfg);
    } else if (updated_option === 'date') {
      data.updated = data.date;
    } else if (updated_option === 'empty') {
Severity: Major
Found in lib/plugins/processor/post.ts and 1 other location - About 3 hrs to fix
lib/plugins/processor/asset.ts on lines 71..79

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

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

function postPermalinkFilter(this: Hexo, data: PostSchema): string {
  const { config } = this;
  const { id, _id, slug, title, date } = data;
  let { __permalink } = data;
  const { post_asset_folder } = config;
Severity: Minor
Found in lib/plugins/filter/post_permalink.ts - About 3 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 78 lines of code (exceeds 25 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: Major
Found in lib/plugins/tag/code.ts - About 3 hrs to fix

    Function makeFeedTag has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    function makeFeedTag(this: LocalsType, path?: string, options: Options = {}, configFeed?: any, configTitle?: string) {
      const title = options.title || configTitle;
    
      if (path) {
        if (typeof path !== 'string') throw new TypeError('path must be a string!');
    Severity: Minor
    Found in lib/plugins/helper/feed_tag.ts - About 3 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 listCategoriesHelper has 77 lines of code (exceeds 25 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: Major
    Found in lib/plugins/helper/list_categories.ts - About 3 hrs to fix

      Function listArchivesHelper has 75 lines of code (exceeds 25 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: Major
      Found in lib/plugins/helper/list_archives.ts - About 3 hrs to fix

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

        function timeHelper(this: LocalsType, date?: moment.Moment | moment.MomentInput, format?: string) {
          const { config } = this;
          const moment = getMoment(date, getLanguage(this), config.timezone);
          return moment.format(format || config.time_format);
        }
        Severity: Major
        Found in lib/plugins/helper/date.ts and 1 other location - About 2 hrs to fix
        lib/plugins/helper/date.ts on lines 32..36

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

        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 dateHelper(this: LocalsType, date?: moment.Moment | moment.MomentInput, format?: string) {
          const { config } = this;
          const moment = getMoment(date, getLanguage(this), config.timezone);
          return moment.format(format || config.date_format);
        }
        Severity: Major
        Found in lib/plugins/helper/date.ts and 1 other location - About 2 hrs to fix
        lib/plugins/helper/date.ts on lines 38..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 93.

        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 register has a Cognitive Complexity of 20 (exceeds 5 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 2 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

        export = (ctx: Hexo) => {
          const PostCategory = new warehouse.Schema({
            post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'},
            category_id: {type: warehouse.Schema.Types.CUID, ref: 'Category'}
          });
        Severity: Major
        Found in lib/models/post_category.ts and 1 other location - About 2 hrs to fix
        lib/models/post_tag.ts on lines 4..11

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

        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 PostTag = new warehouse.Schema({
            post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'},
            tag_id: {type: warehouse.Schema.Types.CUID, ref: 'Tag'}
          });
        Severity: Major
        Found in lib/models/post_tag.ts and 1 other location - About 2 hrs to fix
        lib/models/post_category.ts on lines 4..11

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

        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 numberFormatHelper has a Cognitive Complexity of 20 (exceeds 5 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 2 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 tocHelper has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function tocHelper(str: string, options: Options = {}) {
          options = Object.assign({
            min_depth: 1,
            max_depth: 6,
            class: 'toc',
        Severity: Major
        Found in lib/plugins/helper/toc.ts - About 2 hrs to fix

          Function listTagsHelper has 66 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function listTagsHelper(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: Major
          Found in lib/plugins/helper/list_tags.ts - About 2 hrs to fix

            Function newPostPathFilter has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

            function newPostPathFilter(this: Hexo, data: PostSchema = {}, replace?: boolean): Promise<string> {
              const sourceDir = this.source_dir;
              const draftDir = join(sourceDir, '_drafts');
              const postDir = join(sourceDir, '_posts');
              const { config } = this;
            Severity: Minor
            Found in lib/plugins/filter/new_post_path.ts - About 2 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 newPostPathFilter has 64 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function newPostPathFilter(this: Hexo, data: PostSchema = {}, replace?: boolean): Promise<string> {
              const sourceDir = this.source_dir;
              const draftDir = join(sourceDir, '_drafts');
              const postDir = join(sourceDir, '_posts');
              const { config } = this;
            Severity: Major
            Found in lib/plugins/filter/new_post_path.ts - About 2 hrs to fix

              Function processPage has 62 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function processPage(ctx: Hexo, file: _File) {
                const Page = ctx.model('Page');
                const { path } = file;
                const doc = Page.findOne({source: path});
                const { config } = ctx;
              Severity: Major
              Found in lib/plugins/processor/asset.ts - About 2 hrs to fix

                Function render has 57 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  render(source: string, data: RenderData = {}, callback?: NodeJSLikeCallback<never>) {
                    const ctx = this.context;
                    const { config } = ctx;
                    const { tag } = ctx.extend;
                    const ext = data.engine || (source ? extname(source) : '');
                Severity: Major
                Found in lib/hexo/post.ts - About 2 hrs 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
                    Severity
                    Category
                    Status
                    Source
                    Language