CN111427769A - Code quality detection method, equipment, server and readable storage medium - Google Patents

Code quality detection method, equipment, server and readable storage medium Download PDF

Info

Publication number
CN111427769A
CN111427769A CN202010128292.2A CN202010128292A CN111427769A CN 111427769 A CN111427769 A CN 111427769A CN 202010128292 A CN202010128292 A CN 202010128292A CN 111427769 A CN111427769 A CN 111427769A
Authority
CN
China
Prior art keywords
project
codes
code
module
tree
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010128292.2A
Other languages
Chinese (zh)
Inventor
周志龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Life Insurance Company of China Ltd
Original Assignee
Ping An Life Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Life Insurance Company of China Ltd filed Critical Ping An Life Insurance Company of China Ltd
Priority to CN202010128292.2A priority Critical patent/CN111427769A/en
Publication of CN111427769A publication Critical patent/CN111427769A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the invention discloses a code quality detection method, equipment, a server and a readable storage medium, wherein the method comprises the following steps: acquiring a project tree corresponding to a project source code to be tested, wherein the project tree comprises a plurality of module files; filtering codes in each module file in the project tree, and determining the association relationship among the module files according to the filtered codes in each module file in the project tree; determining a target module file with the association degree larger than a preset association degree threshold value from the project tree according to the association relation among the module files; analyzing the codes in the target module file, and determining the quality of the project source codes according to the analysis result. By the implementation mode, the code can be automatically and intelligently analyzed, and the efficiency of code quality detection is improved.

Description

Code quality detection method, equipment, server and readable storage medium
Technical Field
The present invention relates to the field of code quality detection technologies, and in particular, to a code quality detection method, device, server, and readable storage medium.
Background
Currently, for the quality detection of project codes, after a project code to be detected is acquired, the project code needs to be manually analyzed to distinguish the structure of the project code and designate a module area to be analyzed in the project code, so that the quality of the project code is detected according to the manually determined structure of the project code and the module area to be analyzed. However, when a plurality of projects are faced, a great deal of labor is required to analyze a plurality of project codes, the workload is high, the efficiency is low, and the efficiency of detecting the quality of the project codes is affected. Therefore, how to more efficiently and quickly perform code analysis to improve the efficiency of project code quality detection is an urgent problem to be solved.
Disclosure of Invention
The embodiment of the invention provides a code quality detection method, equipment, a server and a readable storage medium, which can automatically and intelligently analyze codes and are beneficial to improving the efficiency of code quality detection.
In a first aspect, an embodiment of the present invention provides a code quality detection method, including:
acquiring a project tree corresponding to a project source code to be tested, wherein the project tree comprises a plurality of module files;
filtering codes in each module file in the project tree, and determining the association relationship among the module files according to the filtered codes in each module file in the project tree;
determining a target module file with the association degree larger than a preset association degree threshold value from the project tree according to the association relation among the module files;
analyzing the codes in the target module file, and determining the quality of the project source codes according to the analysis result.
Further, the filtering the codes in the module files in the project tree includes:
acquiring the syntactic format of codes in each module file in the project tree;
determining a general syntactic relation according to the syntactic formats of codes in all module files in the project tree;
and filtering the codes in each module file in the project tree according to the general syntax relation.
Further, the filtering the codes in each module file in the project tree according to the general syntax relationship includes:
determining a syntax tree corresponding to codes in each module file in the project tree according to the general syntax relation;
and traversing the syntax tree to obtain a traversal result, and deleting redundant codes which do not meet preset quality conditions from codes of each module file of the project tree according to the traversal result.
Further, the deleting, according to the traversal result, redundant codes that do not satisfy a preset quality condition from codes of each module file of the project tree includes:
establishing a grammatical normative detection model according to the item source code to be tested;
detecting the item source code to be tested according to the grammatical normative detection model to obtain a detection result;
and comparing the traversal result with the detection result, and deleting redundant codes which do not meet the preset quality condition from the codes of each module file of the project tree according to the comparison result.
Further, the deleting, according to the comparison result, redundant codes that do not satisfy a preset quality condition from codes of each module file of the project tree includes:
if the comparison result is that the redundant code inconsistent with the detection result exists in the traversal result, determining that the redundant code does not meet the preset quality condition;
and deleting the redundant code from the codes of the module files of the project tree.
Further, the determining the association relationship between the module files according to the filtered codes in the module files in the project tree includes:
calculating the association degree between the module files according to the codes in the module files in the project tree after filtering;
and determining the association relation among the module files according to the association degree among the module files.
Further, the obtaining of the project tree corresponding to the project source code to be tested includes:
acquiring a project source code to be tested;
analyzing the project source code to be tested and determining a project structure of the project source code to be tested;
and determining the project tree corresponding to the project source code to be tested according to the project structure.
In a second aspect, an embodiment of the present invention provides a code quality detection apparatus, which includes a unit configured to execute the code quality detection method of the first aspect.
In a third aspect, an embodiment of the present invention provides a server, including a processor, an input device, an output device, and a memory, where the processor, the input device, the output device, and the memory are connected to each other, where the memory is used to store a computer program that supports a code quality detection device to execute the above method, and the computer program includes a program, and the processor is configured to call the program to execute the method of the first aspect.
In a fourth aspect, the present invention provides a computer-readable storage medium, which stores a computer program, where the computer program is executed by a processor to implement the method of the first aspect.
According to the method and the device for analyzing the project source codes, the project tree corresponding to the project source codes to be tested is obtained, the codes in each module file in the project tree are filtered, the association relation among the module files is determined according to the codes in each module file in the filtered project tree, the target module file with the association degree larger than a preset association degree threshold value is determined from the project tree according to the association relation among the module files, and therefore the codes in the target module file are analyzed, and the quality of the project source codes is determined according to the analysis result. By the implementation mode, the code can be automatically and intelligently analyzed, and the efficiency of code quality detection is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic flow chart diagram of a code quality detection method provided by an embodiment of the invention;
FIG. 2 is a schematic block diagram of a code quality detection apparatus provided by an embodiment of the present invention;
fig. 3 is a schematic block diagram of a server according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The code quality detection method provided by the embodiment of the invention can be executed by a code quality detection device, wherein the code quality detection device can be arranged on a server. In some embodiments, the code quality detection device may be installed on a server; in some embodiments, the code quality detection device may be spatially independent of the server; in some embodiments, the code quality detection device may be a component of the server, i.e. the server comprises a code quality detection device.
The code quality detection method provided by the embodiment of the invention can obtain the target module file to be scanned by analyzing the project source code before automatic construction, and calls the code quality scanning tool to scan the code in the target module file so as to determine the quality of the project source code according to the scanning result, thereby greatly shortening the construction process and the quality scanning process.
In an embodiment, the code quality detection device may obtain a project tree corresponding to a project source code to be tested, where the project tree includes a plurality of module files, and filter codes in each module file in the project tree, so as to determine an association relationship between each module file according to the filtered codes in each module file in the project tree. The code quality detection device may determine, according to the association relationship between the module files, a target module file whose association degree is greater than a preset association degree threshold from the project tree, and analyze the code in the target module file to determine the quality of the project source code according to the analysis result. By the implementation mode, the code can be automatically and intelligently analyzed, and the efficiency of code quality detection is improved.
The following describes schematically a code quality detection method according to an embodiment of the present invention with reference to the drawings.
Referring to fig. 1, fig. 1 is a schematic flowchart of a code quality detection method according to an embodiment of the present invention, and as shown in fig. 1, the method may be executed by a code quality detection device, and a specific explanation of the code quality detection device is as described above, and is not described herein again. Specifically, the method of the embodiment of the present invention includes the following steps.
S101: and acquiring a project tree corresponding to a project source code to be tested, wherein the project tree comprises a plurality of module files.
In the embodiment of the invention, the code quality detection equipment can acquire the project tree corresponding to the project source code to be tested, wherein the project tree comprises a plurality of module files. In some embodiments, each of the plurality of module files includes different code therein.
In an embodiment, when acquiring a project tree corresponding to a project source code to be tested, a code quality detection device may acquire the project source code to be tested, analyze the project source code to be tested, determine a project structure of the project source code to be tested, and determine the project tree corresponding to the project source code to be tested according to the project structure. In some embodiments, the project structure includes, but is not limited to, a project source code module, a project build tool, a project build configuration, a project auto-compile file, and the like. Therefore, by determining the project structure of the project source code to be tested, the project source code can be analyzed according to modules, tools, configurations, files and the like in the project structure, so as to accurately position and analyze the position of the code required by analysis in the project structure.
In an embodiment, when the code quality detection device analyzes the item source code to be tested and determines the item structure of the item source code to be tested, a preset item structure scanning tool may be called to scan the item source code to be tested to determine the item structure of the item source code to be tested.
S102: and filtering codes in each module file in the project tree, and determining the association relationship among the module files according to the filtered codes in each module file in the project tree.
In the embodiment of the present invention, the code quality detection device may filter codes in each module file in the project tree, and determine the association relationship between each module file according to the filtered codes in each module file in the project tree.
In an embodiment, when filtering the codes in each module file in the project tree, the code quality detection device may obtain a syntax format of the codes in each module file in the project tree, determine a general syntax relationship according to the syntax format of the codes in each module file in the project tree, and filter the codes in each module file in the project tree according to the general syntax relationship.
In some embodiments, the machine languages C, C + +, Java, JS, and the like have specific general grammars and grammar formats, and each machine language can be divided into general grammar relationships similar to the division of the principal and predicate object according to the grammars and grammar formats, and different application programs can be written according to the grammars, grammar formats and corresponding general grammar relationships of the machine languages. In some embodiments, the syntax of the machine language includes any one or more of a method name, a return value, a modifier, a constructor, an operation rule, a code block, and the like, and the syntax format of each machine language are not particularly limited in the embodiments of the present invention.
In an embodiment, when the code quality detection device filters the codes in each module file in the project tree according to the general syntax relationship, the code quality detection device may determine a syntax tree corresponding to the codes in each module file in the project tree according to the general syntax relationship, traverse the syntax tree to obtain a traversal result, and delete redundant codes that do not satisfy a preset quality condition from the codes in each module file in the project tree according to the traversal result.
For example, a file path is introduced into the syntax normalization detection model, the code quality detection device may obtain the item source code to be tested according to the file path, if the method name, the return value, the modifier, the constructor, the code block, and the like are obtained from the item source code to be tested, the top level of the syntax tree may be determined according to the method name, the return value, the modifier, the constructor, and the code block according to a general syntax relationship, each node (such as MethodTree, class tree, blockatree, expressonstatementtree, and the like) of one syntax tree is obtained by filtering the top level syntax tree, and then the syntax tree is determined according to the item source code logic.
In one embodiment, the code quality detection device may perform traversal check on the code of each node in the syntax tree during traversal of the syntax tree to obtain a traversal result obtained by traversing the code of each node in the syntax tree. In some embodiments, the traversal result is a code statement obtained by traversing the code of each node in the syntax tree.
In an embodiment, when the code quality detection device deletes the redundant codes which do not satisfy the preset quality condition from the codes of each module file of the project tree according to the traversal result, a grammatical normative detection model may be established according to the project source codes to be tested, the project source codes to be tested may be detected according to the grammatical normative detection model to obtain a detection result, the traversal result is compared with the detection result, and the redundant codes which do not satisfy the preset quality condition may be deleted from the codes of each module file of the project tree according to the comparison result. In some embodiments, the detection result is a code statement detected according to a normative detection model.
In an embodiment, the code quality detection apparatus may compare a code statement obtained by performing traversal check on a code of each node in a syntax tree with a code statement obtained by detecting the item source code to be tested through the regulatory normative detection model, determine that a code statement obtained by the traversal check and a code statement obtained by detecting the item source code to be tested through the regulatory normative detection model are inconsistent as a redundant code, and delete the redundant code from codes of each module file of the item tree.
In some embodiments, the grammar specification is a reasonable description specification in the code that developers make when writing code using the language of Java or the like. For example, company abbreviations are added to the names of the items in the common development, and the development specifications are arranged to generate a grammatical normative detection model of the source code.
In one embodiment, when the code quality detection device deletes the redundant codes which do not satisfy the preset quality condition from the codes of each module file of the project tree according to the comparison result, if the comparison result indicates that the redundant codes which are inconsistent with the detection result exist in the traversal result, it may be determined that the redundant codes do not satisfy the preset quality condition, and the redundant codes are deleted from the codes of each module file of the project tree.
In an embodiment, when the code quality detection device detects the item source code to be tested according to the grammatical normative detection model, the code quality detection device may check the item source code to be tested by one sentence according to the grammatical normative detection model, and if it is checked that the grammatical normative detection model in the item source code to be tested is inconsistent with the traversal result, it may be determined that a redundant code inconsistent with the detection result exists in the traversal result.
Therefore, by the implementation mode, redundant codes can be deleted, and the efficiency and the accuracy of code quality detection are improved.
In an embodiment, when the code quality detection device determines the association relationship between the module files according to the filtered codes in the module files in the project tree, the code quality detection device may calculate the association degree between the module files according to the filtered codes in the module files in the project tree, and determine the association relationship between the module files according to the association degree between the module files.
In some embodiments, there are association relations such as related usage between each module file of the project source code, and the association relations between each module file are determined according to the association degrees between each module file, so that which module files are constructed when the project is constructed can be determined, and construction time is saved.
In an embodiment, when determining the association relationship between the module files according to the filtered codes in the module files in the project tree, the code quality detection device may analyze the code structure points in the module files in the project tree to determine the programming language of the codes in the module files in the project tree, and select a corresponding language analysis tool to analyze the codes in the module files according to the coding language of the codes in the module files, so as to determine the association relationship between the module files according to an analysis result obtained by analyzing the codes in the module files. In some embodiments, the code structure point refers to a designated folder in each module file of the project source code, and in one example, the code structure point may be an src folder in each module file of the project source code, where the src folder is a source code file.
In an example, the code quality detection device may analyze code structure points in each module file in the project tree, and if the code quality detection device determines that the programming language of the code in each module file in the project tree is C language, a corresponding C language analysis tool may be selected according to the coding language C language of the code in each module file to analyze the code of each module file, so as to determine an association relationship between each module file according to an analysis result obtained by analyzing the code in each module file.
S103: and determining a target module file with the association degree larger than a preset association degree threshold value from the project tree according to the association relation among the module files.
In the embodiment of the present invention, the code quality detection device may determine, from the project tree, a target module file whose association degree is greater than a preset association degree threshold according to the association relationship among the module files. In some embodiments, the object module file includes one or more object modules, and embodiments of the present invention are not specifically limited herein.
In an embodiment, when the code quality detection device determines, according to the association relationship between the module files, a target module file whose association degree is greater than a preset association degree threshold from the project tree, if it is determined that the association degree is less than or equal to the preset association degree threshold and the module files are identified by a code analysis tool to determine a module file matching a preset format, the module file whose association degree is less than or equal to the preset association degree threshold and matching the preset format may be deleted to obtain the target module file to be scanned.
For example, the module file in the arr format is automatically identified through a preset automatic identification script, and if the association degree between the module file in the arr format and other modules is smaller than or equal to a preset association degree threshold value, the module file can be accurately positioned for deletion, so that the scanning range is reduced, the scanning time is shortened, the time for code quality analysis is favorably shortened, and the analysis efficiency of the code quality is improved.
Therefore, through the implementation mode, unnecessary files can be filtered when being determined, useless module files can be deleted, and target module files to be analyzed can be obtained, so that the scanning range is reduced, and the scanning time is shortened.
In one embodiment, after determining the one or more object module files, the code quality detection device may send the one or more object module files to the automated construction platform, so that the automated construction platform constructs the one or more object module files to obtain the application program composed of the one or more object module files.
S104: analyzing the codes in the target module file, and determining the quality of the project source codes according to the analysis result.
In the embodiment of the invention, the code quality detection device can analyze the codes in the target module file and determine the quality of the project source codes according to the analysis result.
In one embodiment, the code quality detection device may determine an analysis rule according to a machine language of the code in the target module file, and analyze the code in the target module file according to the analysis rule, thereby determining the quality of the project source code according to the analysis result. In some embodiments, the analysis rules may include, but are not limited to, rules that are specified in various machine languages for which code composition should be avoided, or user-defined rules, etc.
In some embodiments, the code quality detection device may obtain codes meeting analysis rules determined when the target module file is analyzed, and determine the quality of the project source code according to the category and the number of the codes meeting the analysis rules. In one embodiment, the code quality detection device may determine the quality of the project source code by determining a quality score corresponding to the category and the number of codes satisfying the analysis rule in the project source code according to a preset correspondence between the category and the number and the quality score.
In one example, the parsing rule may include detecting whether expressions of statements such as if statements, for loops, while loops, etc. are used { }, and detecting whether the depth of nesting of if statements is greater than a preset depth threshold (e.g., the depth of nesting of if statements is not greater than 2 layers); detecting whether an empty statement appears in the code; detecting whether repeated codes appear; detect whether private members are included that are not used, local variables, private methods, method parameters (as defined by the parameters, but not used within the method), and so forth. The embodiments of the present invention are not particularly limited herein.
For example, when the code quality detection device analyzes the code in the target module file according to the analysis rule, if the analysis result obtained by the analysis includes that the number of "empty" statements in the code in the target module file is n, and the number of if statement nesting layers is greater than the preset depth threshold 2 is m, the quality of the project source code may be determined according to the number n of "empty" statements in the code and the number m of if statement nesting layers is greater than the preset depth threshold 2.
In one embodiment, the code quality detection device may invoke a preset code quality scanning tool to scan the code in the target module file, and determine the quality of the project source code according to the scanning result. In some embodiments, the code quality check tool may be embedded in the code library and may be continuously updated, may be statically analyzed, or may report errors without running the program. In some embodiments, the preset code quality scanning tools may include code quality scanning tools of different machine languages; in one example, a code quality scan tool for the Java language includes checkstyle. The embodiment of the present invention is not limited to the code quality scanning tool for each machine language.
In one embodiment, after determining the quality of the project source code according to the analysis result, if it is determined that there is a code with a code quality less than a preset threshold, the code quality detection device may determine to add an identifier to the code with a code quality less than the preset threshold. By the implementation, the method is beneficial for repairing the code added with the identification by a subsequent developer so as to enhance the quality of the project source code.
In the embodiment of the invention, the code quality detection equipment can acquire a project tree corresponding to a project source code to be tested, the project tree comprises a plurality of module files, codes in each module file in the project tree are filtered, the association relationship among the module files is determined according to the codes in each module file in the filtered project tree, and a target module file with the association degree larger than a preset association degree threshold value is determined from the project tree according to the association relationship among the module files, so that the codes in the target module file are analyzed, and the quality of the project source code is determined according to the analysis result. By the implementation mode, the code can be automatically and intelligently analyzed, and the efficiency of code quality detection is improved.
The embodiment of the invention also provides a code quality detection device, which is used for executing the unit of the method in any one of the preceding claims. Specifically, referring to fig. 2, fig. 2 is a schematic block diagram of a code quality detection apparatus provided in an embodiment of the present invention. The code quality detection apparatus of the present embodiment includes: an acquisition unit 201, a filtering unit 202, a determination unit 203, and a scanning unit 204.
An obtaining unit 201, configured to obtain a project tree corresponding to a project source code to be tested, where the project tree includes a plurality of module files;
a filtering unit 202, configured to filter codes in each module file in the project tree, and determine an association relationship between the module files according to the filtered codes in each module file in the project tree;
a determining unit 203, configured to determine, according to the association relationship between the module files, a target module file with an association degree greater than a preset association degree threshold from the project tree;
and the scanning unit 204 is configured to analyze the codes in the target module file, and determine the quality of the project source code according to an analysis result.
Further, when the filtering unit 202 filters the codes in each module file in the project tree, it is specifically configured to:
acquiring the syntactic format of codes in each module file in the project tree;
determining a general syntactic relation according to the syntactic formats of codes in all module files in the project tree;
and filtering the codes in each module file in the project tree according to the general syntax relation.
Further, when the filtering unit 202 performs filtering processing on the codes in each module file in the project tree according to the general syntax relationship, the filtering unit is specifically configured to:
determining a syntax tree corresponding to codes in each module file in the project tree according to the general syntax relation;
and traversing the syntax tree to obtain a traversal result, and deleting redundant codes which do not meet preset quality conditions from codes of each module file of the project tree according to the traversal result.
Further, when the filtering unit 202 deletes the redundant code that does not satisfy the preset quality condition from the codes of each module file of the project tree according to the traversal result, it is specifically configured to:
establishing a grammatical normative detection model according to the item source code to be tested;
detecting the item source code to be tested according to the grammatical normative detection model to obtain a detection result;
and comparing the traversal result with the detection result, and deleting redundant codes which do not meet the preset quality condition from the codes of each module file of the project tree according to the comparison result.
Further, when the filtering unit 202 deletes the redundant code that does not satisfy the preset quality condition from the codes of each module file of the project tree according to the comparison result, it is specifically configured to:
if the comparison result is that the redundant code inconsistent with the detection result exists in the traversal result, determining that the redundant code does not meet the preset quality condition;
and deleting the redundant code from the codes of the module files of the project tree.
Further, when the filtering unit 202 determines the association relationship between the module files according to the codes in the module files in the filtered project tree, the method is specifically configured to:
calculating the association degree between the module files according to the codes in the module files in the project tree after filtering;
and determining the association relation among the module files according to the association degree among the module files.
Further, when the obtaining unit 201 obtains the item tree corresponding to the item source code to be tested, it is specifically configured to:
acquiring a project source code to be tested;
analyzing the project source code to be tested and determining a project structure of the project source code to be tested;
and determining the project tree corresponding to the project source code to be tested according to the project structure.
In the embodiment of the invention, the code quality detection equipment can acquire a project tree corresponding to a project source code to be tested, the project tree comprises a plurality of module files, codes in each module file in the project tree are filtered, the association relationship among the module files is determined according to the codes in each module file in the filtered project tree, and a target module file with the association degree larger than a preset association degree threshold value is determined from the project tree according to the association relationship among the module files, so that the codes in the target module file are analyzed, and the quality of the project source code is determined according to the analysis result. By the implementation mode, the code can be automatically and intelligently analyzed, and the efficiency of code quality detection is improved.
Referring to fig. 3, fig. 3 is a schematic block diagram of a server according to an embodiment of the present invention. The server in this embodiment as shown in the figure may include: one or more processors 301; one or more input devices 302, one or more output devices 303, and memory 304. The processor 301, the input device 302, the output device 303, and the memory 304 are connected by a bus 305. The memory 304 is used for storing computer programs, including programs, and the processor 301 is used for executing the programs stored in the memory 304. Wherein the processor 301 is configured to invoke the program to perform:
acquiring a project tree corresponding to a project source code to be tested, wherein the project tree comprises a plurality of module files;
filtering codes in each module file in the project tree, and determining the association relationship among the module files according to the filtered codes in each module file in the project tree;
determining a target module file with the association degree larger than a preset association degree threshold value from the project tree according to the association relation among the module files;
analyzing the codes in the target module file, and determining the quality of the project source codes according to the analysis result.
Further, when the processor 301 filters the codes in each module file in the project tree, it is specifically configured to:
acquiring the syntactic format of codes in each module file in the project tree;
determining a general syntactic relation according to the syntactic formats of codes in all module files in the project tree;
and filtering the codes in each module file in the project tree according to the general syntax relation.
Further, when the processor 301 performs filtering processing on the codes in each module file in the project tree according to the general syntax relationship, the method is specifically configured to:
determining a syntax tree corresponding to codes in each module file in the project tree according to the general syntax relation;
and traversing the syntax tree to obtain a traversal result, and deleting redundant codes which do not meet preset quality conditions from codes of each module file of the project tree according to the traversal result.
Further, when the processor 301 deletes the redundant code that does not satisfy the preset quality condition from the codes of each module file of the project tree according to the traversal result, the processor is specifically configured to:
establishing a grammatical normative detection model according to the item source code to be tested;
detecting the item source code to be tested according to the grammatical normative detection model to obtain a detection result;
and comparing the traversal result with the detection result, and deleting redundant codes which do not meet the preset quality condition from the codes of each module file of the project tree according to the comparison result.
Further, when the processor 301 deletes the redundant code that does not satisfy the preset quality condition from the codes of each module file of the project tree according to the comparison result, the processor is specifically configured to:
if the comparison result is that the redundant code inconsistent with the detection result exists in the traversal result, determining that the redundant code does not meet the preset quality condition;
and deleting the redundant code from the codes of the module files of the project tree.
Further, when the processor 301 determines the association relationship between the module files according to the filtered codes in the module files in the project tree, the processor is specifically configured to:
calculating the association degree between the module files according to the codes in the module files in the project tree after filtering;
and determining the association relation among the module files according to the association degree among the module files.
Further, when the processor 301 obtains the item tree corresponding to the item source code to be tested, it is specifically configured to:
acquiring a project source code to be tested;
analyzing the project source code to be tested and determining a project structure of the project source code to be tested;
and determining the project tree corresponding to the project source code to be tested according to the project structure.
In the embodiment of the invention, a server can obtain a project tree corresponding to a project source code to be tested, the project tree comprises a plurality of module files, codes in each module file in the project tree are filtered, the association relationship among the module files is determined according to the filtered codes in each module file in the project tree, and a target module file with the association degree larger than a preset association degree threshold value is determined from the project tree according to the association relationship among the module files, so that the codes in the target module file are analyzed, and the quality of the project source code is determined according to the analysis result. By the implementation mode, the code can be automatically and intelligently analyzed, and the efficiency of code quality detection is improved.
It should be understood that, in the embodiment of the present invention, the Processor 301 may be a Central Processing Unit (CPU), and the Processor may also be other general processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable gate arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The input device 302 may include a touch pad, microphone, etc., and the output device 303 may include a display (L CD, etc.), speakers, etc.
The memory 304 may include a read-only memory and a random access memory, and provides instructions and data to the processor 301. A portion of the memory 304 may also include non-volatile random access memory. For example, the memory 304 may also store device type information.
In a specific implementation, the processor 301, the input device 302, and the output device 303 described in this embodiment of the present invention may execute the implementation manner described in the method embodiment shown in fig. 1 or fig. 2 of the code quality detection method provided in this embodiment of the present invention, and may also execute the implementation manner of the code quality detection device described in fig. 3 in this embodiment of the present invention, which is not described herein again.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the method for detecting code quality described in the embodiment corresponding to fig. 1 or fig. 2 is implemented, and a device for detecting code quality according to the embodiment corresponding to fig. 3 of the present invention may also be implemented, which is not described herein again.
The computer readable storage medium may be an internal storage unit of the code quality detection device according to any of the foregoing embodiments, for example, a hard disk or a memory of the code quality detection device. The computer readable storage medium may also be an external storage device of the code quality detection device, such as a plug-in hard disk, a Smart Memory Card (SMC), a Secure Digital (SD) Card, a flash Card (FlashCard), and the like provided on the code quality detection device. Further, the computer-readable storage medium may also include both an internal storage unit and an external storage device of the code quality detection apparatus. The computer-readable storage medium is used for storing the computer program and other programs and data required by the code quality detection apparatus. The computer readable storage medium may also be used to temporarily store data that has been output or is to be output.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a computer-readable storage medium, which includes several instructions for causing a computer device (which may be a personal computer, a terminal, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned computer-readable storage media comprise: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only a part of the embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive various equivalent modifications or substitutions within the technical scope of the present invention, and these modifications or substitutions should be covered within the scope of the present invention.

Claims (10)

1. A method for code quality detection, comprising:
acquiring a project tree corresponding to a project source code to be tested, wherein the project tree comprises a plurality of module files;
filtering codes in each module file in the project tree, and determining the association relationship among the module files according to the filtered codes in each module file in the project tree;
determining a target module file with the association degree larger than a preset association degree threshold value from the project tree according to the association relation among the module files;
analyzing the codes in the target module file, and determining the quality of the project source codes according to the analysis result.
2. The method of claim 1, wherein filtering the code in each module file in the project tree comprises:
acquiring the syntactic format of codes in each module file in the project tree;
determining a general syntactic relation according to the syntactic formats of codes in all module files in the project tree;
and filtering the codes in each module file in the project tree according to the general syntax relation.
3. The method according to claim 2, wherein said filtering the codes in the module files in the project tree according to the general syntax relationship comprises:
determining a syntax tree corresponding to codes in each module file in the project tree according to the general syntax relation;
and traversing the syntax tree to obtain a traversal result, and deleting redundant codes which do not meet preset quality conditions from codes of each module file of the project tree according to the traversal result.
4. The method according to claim 3, wherein the deleting redundant codes which do not satisfy a preset quality condition from codes of each module file of the project tree according to the traversal result comprises:
establishing a grammatical normative detection model according to the item source code to be tested;
detecting the item source code to be tested according to the grammatical normative detection model to obtain a detection result;
and comparing the traversal result with the detection result, and deleting redundant codes which do not meet the preset quality condition from the codes of each module file of the project tree according to the comparison result.
5. The method according to claim 4, wherein the deleting redundant codes which do not satisfy a preset quality condition from the codes of the respective module files of the project tree according to the comparison result comprises:
if the comparison result is that the redundant code inconsistent with the detection result exists in the traversal result, determining that the redundant code does not meet the preset quality condition;
and deleting the redundant code from the codes of the module files of the project tree.
6. The method according to any one of claims 1 to 5, wherein the determining the association relationship between the module files according to the filtered codes in the module files in the project tree comprises:
calculating the association degree between the module files according to the codes in the module files in the project tree after filtering;
and determining the association relation among the module files according to the association degree among the module files.
7. The method of claim 1, wherein the obtaining the project tree corresponding to the project source code to be tested comprises:
acquiring a project source code to be tested;
analyzing the project source code to be tested and determining a project structure of the project source code to be tested;
and determining the project tree corresponding to the project source code to be tested according to the project structure.
8. A code quality detection device, characterized by comprising means for performing the method of any one of claims 1-7.
9. A server comprising a processor, an input device, an output device and a memory, the processor, the input device, the output device and the memory being interconnected, wherein the memory is configured to store a computer program, the computer program comprising a program, the processor being configured to invoke the program to perform the method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which is executed by a processor to implement the method of any one of claims 1-7.
CN202010128292.2A 2020-02-27 2020-02-27 Code quality detection method, equipment, server and readable storage medium Pending CN111427769A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010128292.2A CN111427769A (en) 2020-02-27 2020-02-27 Code quality detection method, equipment, server and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010128292.2A CN111427769A (en) 2020-02-27 2020-02-27 Code quality detection method, equipment, server and readable storage medium

Publications (1)

Publication Number Publication Date
CN111427769A true CN111427769A (en) 2020-07-17

Family

ID=71547998

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010128292.2A Pending CN111427769A (en) 2020-02-27 2020-02-27 Code quality detection method, equipment, server and readable storage medium

Country Status (1)

Country Link
CN (1) CN111427769A (en)

Similar Documents

Publication Publication Date Title
CN110688307B (en) JavaScript code detection method, device, equipment and storage medium
CN107045477B (en) Quality assessment platform capable of carrying out multi-dimensional detection
JP2018026135A (en) System and method for cause point analysis for effective handling of static analysis alarms
CN114968807A (en) Code detection method and device, electronic equipment and readable storage medium
CN112131573A (en) Method and device for detecting security vulnerability and storage medium
CN111190807A (en) Buried point testing method and device
CN113434395B (en) Automatic generation method, device, equipment and medium for test cases
CN108897678B (en) Static code detection method, static code detection system and storage device
CN111767213B (en) Database check point testing method and device, electronic equipment and storage medium
CN113778852A (en) Code analysis method based on regular expression
CN112540925A (en) New characteristic compatibility detection system and method, electronic device and readable storage medium
US10782942B1 (en) Rapid onboarding of data from diverse data sources into standardized objects with parser and unit test generation
CN111258562A (en) Java code quality inspection method, device, equipment and storage medium
CN111966578A (en) Automatic evaluation method for android compatibility defect repair effect
CN115269444B (en) Code static detection method and device and server
CN112084108A (en) Test script generation method and device and related components
CN111427769A (en) Code quality detection method, equipment, server and readable storage medium
CN115438341A (en) Method and device for extracting code loop counter, storage medium and electronic equipment
CN113392016A (en) Protocol generation method, device, equipment and medium for processing program abnormal condition
CN114625633A (en) Method, system and storage medium for interface testing
CN113434430A (en) SQL query statement performance detection method and device
CN110321130B (en) Non-repeatable compiling and positioning method based on system call log
CN112631944A (en) Source code detection method and device based on abstract syntax tree and computer storage medium
CN113051262A (en) Data quality inspection method, device, equipment and storage medium
CN111782220A (en) File detection method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination