Showing 105 of 173 total issues

Avoid deeply nested control flow statements.
Open

            if (Number.isNaN(a) || Number.isNaN(b)) continue;
Severity: Major
Found in lib/plugins/tag/code.ts - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

              if (isNonWhiteSpaceChar(char)) {
                if (!swig_tag_name_begin && !swig_tag_name_end) {
                  swig_tag_name_begin = true;
                }
    
    
    Severity: Major
    Found in lib/hexo/post.ts - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

              if (char === '}' && next_char === '}') {
                idx++;
                state = STATE_PLAINTEXT;
                output += PostRenderEscape.escapeContent(this.stored, 'swig', `{{${buffer}}}`);
                buffer = '';
      Severity: Major
      Found in lib/hexo/post.ts - About 45 mins to fix

        Function localeToTerritory has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        const localeToTerritory = moize.shallow(str => {
          if (str.length === 2 && localeMap[str]) return localeMap[str];
        
          if (str.length === 5) {
            let territory = [];
        Severity: Minor
        Found in lib/plugins/helper/open_graph.ts - About 45 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

        Consider simplifying this complex logical expression.
        Open

          if (typeof options.class !== 'undefined') {
            if (typeof options.class === 'string') {
              className = options.class;
            } else {
              className = 'tag';
        Severity: Major
        Found in lib/plugins/helper/list_tags.ts - About 40 mins to fix

          Function readDirWalker has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function readDirWalker(ctx: Hexo, base: string, results: any[], ignore: any, prefix: string): BlueBirdPromise<any> {
          Severity: Minor
          Found in lib/box/index.ts - About 35 mins to fix

            Function makeFeedTag has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function makeFeedTag(this: LocalsType, path?: string, options: Options = {}, configFeed?: any, configTitle?: string) {
            Severity: Minor
            Found in lib/plugins/helper/feed_tag.ts - About 35 mins to fix

              Function toArray has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function toArray(value) {
                if (Array.isArray(value)) {
                  // Return if given value is an Array
                  return value;
                } else if (typeof value.toArray === 'function') {
              Severity: Minor
              Found in lib/plugins/renderer/nunjucks.ts - About 35 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 i18nLocalsFilter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function i18nLocalsFilter(this: Hexo, locals: LocalsType): void {
                const { i18n } = this.theme;
                const { config } = this;
                const i18nDir = config.i18n_dir;
                const { page } = locals;
              Severity: Minor
              Found in lib/plugins/filter/template_locals/i18n.ts - About 35 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 listPostsHelper has a Cognitive Complexity of 7 (exceeds 5 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 35 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 process has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              const process = (name: string, ctx: Hexo) => {
                return Promise.filter(ctx.model(name).toArray(), (asset: Document<AssetSchema>) => exists(asset.source).tap(exist => {
                  if (!exist) return asset.remove();
                })).map((asset: Document<AssetSchema>) => {
                  const { source } = asset;
              Severity: Minor
              Found in lib/plugins/generator/asset.ts - About 35 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 _getPageType has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                _getPageType(pageLocals): string {
                  let currentType = 'default';
                  if (pageLocals.__index) currentType = 'home';
                  if (pageLocals.__post) currentType = 'post';
                  if (pageLocals.__page) currentType = 'page';
              Severity: Minor
              Found in lib/extend/injector.ts - About 35 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 7 (exceeds 5 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: Minor
              Found in lib/hexo/post.ts - About 35 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 7 (exceeds 5 allowed). Consider refactoring.
              Open

                register(name: string, output: string, fn: StoreFunction | StoreSyncFunction, sync?: boolean) {
                  if (!name) throw new TypeError('name is required');
                  if (!output) throw new TypeError('output is required');
                  if (typeof fn !== 'function') throw new TypeError('fn must be a function');
              
              
              Severity: Minor
              Found in lib/extend/renderer.ts - About 35 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

              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

                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 postAsset.remove();
                    Severity: Major
                    Found in lib/plugins/processor/post.ts - About 30 mins to fix

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

                      Severity
                      Category
                      Status
                      Source
                      Language