Showing 105 of 173 total issues

Function firstGenerate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  firstGenerate(): Promise<void> {
    const { concurrency } = this;
    const { route, log } = this.context;
    const publicDir = this.context.public_dir;
    const Cache = this.context.model('Cache');
Severity: Minor
Found in lib/plugins/console/generate.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 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 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

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

                  function linkTag(args: string[]) {
                    let url = '';
                    const text = [];
                    let external = false;
                    let title = '';
                  Severity: Minor
                  Found in lib/plugins/tag/link.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

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

                  const prepareFrontMatter = (data: any, jsonMode: boolean) => {
                    for (const [key, item] of Object.entries(data)) {
                      if (moment.isMoment(item)) {
                        data[key] = item.utc().format('YYYY-MM-DD HH:mm:ss');
                      } else if (moment.isDate(item)) {
                  Severity: Minor
                  Found in lib/hexo/post.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 externalLinkFilter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function externalLinkFilter(this: Hexo, data: RenderData): void {
                    if (!EXTERNAL_LINK_POST_ENABLED) return;
                  
                    const { external_link, url } = this.config;
                  
                  
                  Severity: Minor
                  Found in lib/plugins/filter/after_post_render/external_link.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

                  Avoid deeply nested control flow statements.
                  Open

                        } else if (state === STATE_SWIG_COMMENT) { // From swig back to plain text
                          if (char === '#' && next_char === '}') {
                            idx++;
                            state = STATE_PLAINTEXT;
                            buffer = '';
                  Severity: Major
                  Found in lib/hexo/post.ts - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                for (; a <= b; a++) {
                                  mark.push(a);
                                }
                    Severity: Major
                    Found in lib/plugins/tag/code.ts - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                if (swig_tag_name !== '' && str.includes(`end${swig_tag_name}`)) {
                                  state = STATE_SWIG_FULL_TAG;
                                } else {
                                  swig_tag_name = '';
                                  state = STATE_PLAINTEXT;
                      Severity: Major
                      Found in lib/hexo/post.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                    if (b < a) { // switch a & b
                                      const temp = a;
                                      a = b;
                                      b = temp;
                                    }
                        Severity: Major
                        Found in lib/plugins/tag/code.ts - About 45 mins to fix

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

                          const paginationPartShow = (tags, options, ctx: LocalsType) => {
                            const {
                              current,
                              total,
                              space,
                          Severity: Minor
                          Found in lib/plugins/helper/paginator.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

                          Avoid deeply nested control flow statements.
                          Open

                                    if (!reservedKeys[key]) filenameData[key] = data[key];
                          Severity: Major
                          Found in lib/plugins/filter/new_post_path.ts - About 45 mins to fix
                            Severity
                            Category
                            Status
                            Source
                            Language