qiu8310/serpent

View on GitHub

Showing 52 of 52 total issues

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

export function findupFile(name: string, refRootPath?: string) {
  const ref = refRootPath || process.cwd()
  try {
    return _findup.file(ref, name)
  } catch (e) {
Severity: Major
Found in projects/serpent-common-cli/src/fs/context.ts and 1 other location - About 2 hrs to fix
projects/serpent-common-cli/src/fs/context.ts on lines 20..27

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

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

  test('duplicate:ignore', () => {
    createSameFileInSrcAndDistDir('a2', 'new', 'old')
    const { ignored, copied } = runCopy({ duplicate: 'ignore' })
    testFile('a2', 'old')
    expect(ignored).toHaveLength(1)
Severity: Major
Found in projects/serpent-cli/src/__tests__/copy.test.ts and 1 other location - About 2 hrs to fix
projects/serpent-cli/src/__tests__/copy.test.ts on lines 120..126

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

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

  test('duplicate:overwrite', () => {
    createSameFileInSrcAndDistDir('a3', 'new', 'old')
    const { overwritten, copied } = runCopy({ duplicate: 'overwrite' })
    testFile('a3', 'new')
    expect(overwritten).toHaveLength(1)
Severity: Major
Found in projects/serpent-cli/src/__tests__/copy.test.ts and 1 other location - About 2 hrs to fix
projects/serpent-cli/src/__tests__/copy.test.ts on lines 112..118

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

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 function findupDir(name: string, refRootPath?: string) {
  const ref = refRootPath || process.cwd()
  try {
    return _findup.dir(ref, name)
  } catch (e) {
Severity: Major
Found in projects/serpent-common-cli/src/fs/context.ts and 1 other location - About 2 hrs to fix
projects/serpent-common-cli/src/fs/context.ts on lines 10..17

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

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 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
Severity
Category
Status
Source
Language