Front-end engineering-multi-dimensional detection of duplicate codes

For more articles, please follow my personal blog: https://seven777777.github.io/myblog/

1. Detect duplicate codes in projects

1.1 Detection solution: jscpd

method one:

  • Install jscpd dependencies globallynpm i -g jscpd
  • Project root path execution:jscpd -p "src/**/*.js" -k 15 -l 5

Method 2: Node API

Install jscpd dependencies in the project

Visual reporting

Installation: @jscpd/html-reporter

1.2 Hazardousness

  1. Poor readability
  2. Difficult to maintain

1.3 Solutions

  1. Encapsulated components
  2. Extract function
  3. Method hoisting (creating a class)

2. Cyclomatic complexity detection

Metrics for measuring code quality

Definition: The possible path from the beginning to the end of code execution

2.1 How to detect

ESLint——complexity

2.2 Main idea

Separate complex logic, abstract the logic that can be abstracted into a pure function, and call it in the main process

3. Code coverage

How to analyze?

  • Istanbul tool
    unit testing: Jest+Chai automatically counts code coverage

  • assets-retry
    disaster recovery solution

Picking up dreams
Welcome to pay attention to my personal public account [搴Fang Shimeng]

Guess you like

Origin blog.csdn.net/Seven521m/article/details/128776175