qiu8310/serpent

View on GitHub

Showing 28 of 52 total issues

Function make has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function make(options: {
  /** 项目的 package.json 内容 */
  pkg: any
  /** 入口文件 */
  entry: string
Severity: Major
Found in projects/serpent-rollup-kits/src/make.ts - About 2 hrs to fix

Function makeCli has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function makeCli(
  srcKeys: string[] = [],
  options: Omit<RollupOptions, 'input' | 'plugins'> & { plugins?: Parameters<typeof getPlugins>[0] } = {}
) {
  const { plugins, ...restOptions } = options
Severity: Major
Found in projects/serpent-rollup-kits/src/makeCli.ts - About 2 hrs to fix

Function getPlugins has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

export function getPlugins(
  options: {
    tsConfigPaths?: boolean | Parameters<typeof tsConfigPaths>[0]
    run?: boolean | Parameters<typeof run>[0]
    replace?: boolean | Parameters<typeof replace>[0]
Severity: Minor
Found in projects/serpent-rollup-kits/src/base.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 makeLib has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function makeLib(options: Omit<RollupOptions, 'input'> & { modules?: Record<string, string> } = {}) {
  const { modules, ...rest } = options
  const rootDir = getRootDir()
  const srcDir = path.join(rootDir, 'src')
  const pkg = require(path.join(rootDir, 'package.json'))
Severity: Minor
Found in projects/serpent-rollup-kits/src/makeLib.ts - About 2 hrs to fix

Function run has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

export function run(args: string | string[], options: any = {}): any {
  const { debug, output, ...opts } = options
  // 开启 debug 后还需要将环境变量 DURKA_NODE_DEBUG 设置成 true
  if (debug && process.env[typeof debug === 'string' ? debug : 'DURKA_NODE_DEBUG']) {
    return runNodeDebug(args, opts)
Severity: Minor
Found in projects/serpent-common-cli/src/run/index.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 tryGetProjectBinFile has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

export function tryGetProjectBinFile(rootDir: string, cmdName?: string) {
  let bin = ''
  let file = ''

  try {
Severity: Minor
Found in projects/serpent-common-cli/src/fs/project.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 cmd has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function cmd<Opts, Env>(
  params: {
    /**
     * **字符串的表示法:**
     * ```
Severity: Minor
Found in projects/serpent-common-cli/src/cmder/cmd.ts - About 1 hr to fix

Function installDurkaScript has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export function installDurkaScript(options: {
  name: string
  subname: string
  content: string
  devOnly?: boolean
Severity: Minor
Found in projects/serpent-common-cli/src/npm/durkaScript.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 runNodeDebug has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export function runNodeDebug(args: string | string[], options: runTypes.Options & SilentOptions = {}) {
  const { silent, ...opts } = options
  if (typeof args === 'string') {
    let cmd = args
    if (/^\s*node\s/.test(cmd)) {
Severity: Minor
Found in projects/serpent-common-cli/src/run/index.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 fetch has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function fetch(url) {
  return new Promise((resolve, reject) => {
    const isHTTPS = url.startsWith('https:')
    let client
    if (isHTTPS) {
Severity: Minor
Found in projects/serpent-common-cli/src/npm/test.js - About 1 hr to fix

Function fetch has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function fetch(url: string) {
  return new Promise<{ status?: number; message?: string; data?: any }>((resolve, reject) => {
    const isHTTPS = url.startsWith('https:')
    let client: http.ClientRequest
    if (isHTTPS) {
Severity: Minor
Found in projects/serpent-common-cli/src/npm/getPackageDetail.ts - About 1 hr to fix

Function _getRemotePackageDetail has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

async function _getRemotePackageDetail(name: string, registry?: string, retryCount = 0): Promise<Detail> {
  const pkgUrl = url.resolve(registry || getDurkaRegistry(), name)

  try {
    const { timeout, data: res = {} } = await wait(fetch(pkgUrl), 5000)
Severity: Minor
Found in projects/serpent-common-cli/src/npm/getPackageDetail.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 installDurkaScript has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function installDurkaScript(options: {
  name: string
  subname: string
  content: string
  devOnly?: boolean
Severity: Minor
Found in projects/serpent-common-cli/src/npm/durkaScript.ts - About 1 hr to fix

Function filterVersions has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function filterVersions(versions: string[], mode: VERSION_FILTER_MODE = 'all') {
  const map = new Map<string, string>()
  let maxMajor = -1
  const targets = versions.map(v => parseVersion(v)).filter(t => t != null) as VERSION_INSTANCE[]

Severity: Minor
Found in projects/serpent-common-cli/src/version.ts - About 1 hr to fix

Function walk has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function walk(result: copy.Result, dir: string, walkOptions: copy.WalkOptions) {
  const { fromDir, distDir } = walkOptions
  const { includes, excludes, duplicate, rename } = walkOptions.options
  fs.readdirSync(dir).forEach(name => {
    const srcFile = path.join(dir, name)
Severity: Minor
Found in projects/serpent-cli/src/copy.ts - About 1 hr to fix

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

export function getPlugins(
  options: {
    tsConfigPaths?: boolean | Parameters<typeof tsConfigPaths>[0]
    run?: boolean | Parameters<typeof run>[0]
    replace?: boolean | Parameters<typeof replace>[0]
Severity: Minor
Found in projects/serpent-rollup-kits/src/base.ts - About 1 hr to fix

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

export function copy(fromDir: string, distDir: string, options: copy.Options = {}) {
  const requiredOptions: copy.RequiredOptions = {
    includes,
    excludes,
    rename,
Severity: Minor
Found in projects/serpent-cli/src/copy.ts - About 1 hr to fix

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

export function tryGetProjectBinFile(rootDir: string, cmdName?: string) {
  let bin = ''
  let file = ''

  try {
Severity: Minor
Found in projects/serpent-common-cli/src/fs/project.ts - About 1 hr to fix

Function runDurkaScript has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

export async function runDurkaScript(options: { name: string; subname?: string; args?: string[] }) {
  const { name, args = [], subname: onlyRunSubname } = options

  const root = tryGetProjectRootDir()
  if (!root) throw new Error(`Not a valid node project, can not run durka script.`)
Severity: Minor
Found in projects/serpent-common-cli/src/npm/durkaScript.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 getEnvSingly has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

export function getEnvSingly<T>(key: string, options: env.Options<T>) {
  const prefixedKey = options.prefix + key
  const value = process.env[prefixedKey]
  const defaultEnv = options.defaultEnv as any

Severity: Minor
Found in projects/serpent-common-cli/src/env/getEnv.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