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 globally
npm 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
- Poor readability
- Difficult to maintain
1.3 Solutions
- Encapsulated components
- Extract function
- 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——complexity2.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