Showing 105 of 173 total issues
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;
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;
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) : '');
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;
Function tagcloudHelper
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
function tagcloudHelper(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;
}
Function postPermalinkFilter
has 54 lines of code (exceeds 25 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;
File post.ts
has 255 lines of code (exceeds 250 allowed). Consider refactoring. Open
import { toDate, timezone, isExcludedFile, isTmpFile, isHiddenFile, isMatch } from './common';
import Promise from 'bluebird';
import { parse as yfm } from 'hexo-front-matter';
import { extname, join, posix, sep } from 'path';
import { stat, listDir } from 'hexo-fs';
Consider simplifying this complex logical expression. Open
if (jsonMode || item.includes(':') || item.startsWith('#') || item.startsWith('!!')
|| item.includes('{') || item.includes('}') || item.includes('[') || item.includes(']')
|| item.includes('\'') || item.includes('"')) data[key] = `"${item.replace(/"/g, '\\"')}"`;
Function paginatorHelper
has 49 lines of code (exceeds 25 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/`,
Function multiConfigPath
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
export = (ctx: Hexo) => function multiConfigPath(base: string, configPaths?: string, outputDir?: string): string {
const { log } = ctx;
const defaultPath = join(base, '_config.yml');
if (!configPaths) {
Function listTagsHelper
has a Cognitive Complexity of 15 (exceeds 5 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;
}
- Read upRead up
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 parseFooter
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
const parseFooter = (args: string[], ctx: Hexo) => {
const str = args.join(' ');
if (!str) return '';
let author = '';
- Read upRead up
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 includeCodeTag
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
export = (ctx: Hexo) => function includeCodeTag(args: string[]) {
let codeDir = ctx.config.code_dir;
let arg = args.join(' ');
// Add trailing slash to codeDir
Function backtickCodeBlock
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
return function backtickCodeBlock(data: RenderData): void {
const dataContent = data.content;
if ((!dataContent.includes('```') && !dataContent.includes('~~~')) || !ctx.extend.highlight.query(ctx.config.syntax_highlighter)) return;
Function tagcloudHelper
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
function tagcloudHelper(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;
}
- Read upRead up
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 13 (exceeds 5 allowed). Consider refactoring. Open
register(name: string, fn: TagFunction, options?: RegisterOptions | boolean):void {
if (!name) throw new TypeError('name is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');
if (options == null || typeof options === 'boolean') {
- Read upRead up
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 13 (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).replace(/\\/g, '/');
const postAsset = PostAsset.findById(id);
- Read upRead up
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 content
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
data.content = dataContent.replace(rBacktick, ($0, start, $2, _args, _content, end) => {
let content = _content.replace(/\n$/, '');
// neither highlight or prismjs is enabled, return escaped content directly.
if (!ctx.extend.highlight.query(ctx.config.syntax_highlighter)) return escapeSwigTag($0);
Function deployConsole
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function deployConsole(this: Hexo, args: DeployArgs) {
let config = this.config.deploy;
const deployers = this.extend.deployer.list();
if (!config) {
Function publish
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
publish(data: PostData, replace?: boolean | NodeJSLikeCallback<Result>, callback?: NodeJSLikeCallback<Result>) {
if (!callback && typeof replace === 'function') {
callback = replace;
replace = false;
}