Code inspection method, code inspection device, electronic equipment and storage medium

CN115934552BActive Publication Date: 2026-09-04CHINA PING AN LIFE INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211634523.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-19
Publication Date
2026-09-04
Estimated Expiration
2042-12-19

AI Technical Summary

Technical Problem

[0003]相关技术中,以人工核查的方式来进行代码质量检测,受人力限制,难以高效地检测较大规模计算机程序,并且不同的软件工程师对于代码质量的评价标准存在差异,难以客观地评估代码质量

Benefits of technology

[0037] The code quality inspection method of this application is applied to a code quality inspection device, which includes a code management module, an event callback module, and a quality inspection module. First, the code management module acquires the target code and code extension instructions, and parses the code extension instructions to obtain code extension events. These code extension events are used to extend the original code based on the target code. The code management module transmits the code extension events to the event callback module. The event callback module then matches the corresponding extension callback interface from a pre-set interface database. Further, based on the event callback module and the extension callback interface, the target code is sent to the quality inspection module. Finally, the quality inspection module performs quality inspection on the target code and obtains the quality inspection result. The code quality inspection method of this application can automatically trigger quality inspection of the target code after acquiring the target code and code extension instructions, thus improving the efficiency of code quality inspection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115934552B_ABST
    Figure CN115934552B_ABST
Patent Text Reader

Abstract

The application relates to the computer technical field, in particular to a code quality inspection method, a code quality inspection device, an electronic device and a storage medium. The code quality inspection method is used for obtaining target code and a code expansion instruction based on a code management module, analyzing the code expansion instruction, and obtaining a code expansion event, wherein the code expansion event is used for expanding original code based on the target code, the code expansion event is transmitted from the code management module to an event callback module based on the code management module, an expansion callback interface corresponding to the code expansion event is matched from a preset interface database based on the event callback module, the target code is sent to a quality inspection module based on the event callback module and the expansion callback interface, and finally, quality detection is performed on the target code based on the quality inspection module to obtain a quality detection result. The code quality inspection method can automatically trigger quality detection on the target code, and the code quality detection efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a code quality inspection method, a code quality inspection device, an electronic device, and a storage medium. Background Technology

[0002] Code quality inspection refers to the inspection and testing of completed program code. The inspection typically includes checking the correctness of basic syntax, the existence of security issues, and the ease of review and maintenance. It's important to note that code quality inspection is a crucial part of software development and is usually triggered in two ways: first, manual review, where a professional software engineer reviews the code to ensure it conforms to coding standards; second, using plugins within development tools to perform code style checks automatically.

[0003] In related technologies, manual code quality inspection is limited by manpower and cannot efficiently inspect large-scale computer programs. Furthermore, different software engineers may have different evaluation standards for code quality, making objective assessment difficult. Integrating third-party plugins into the code may alter the programming architecture, similarly hindering accurate and rapid code quality inspection and resulting in low efficiency. Therefore, how to conduct efficient code quality inspection has become a pressing issue for the industry. Summary of the Invention

[0004] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes a code quality inspection method, a code quality inspection device, an electronic device, and a storage medium, which can efficiently perform code quality inspection.

[0005] The code quality inspection method according to a first aspect of this application is applied to a code quality inspection device, the code quality inspection device including a code management module, an event callback module, and a quality inspection module, including:

[0006] The target code and code extension instructions are obtained based on the code management module, and the code extension instructions are parsed to obtain code extension events. The code extension events are used to extend the original code based on the target code.

[0007] Based on the code management module, the code extension event is transmitted from the code management module to the event callback module;

[0008] Based on the event callback module, the extended callback interface corresponding to the code extension event is obtained from the preset interface database;

[0009] Based on the event callback module and the extended callback interface, the target code is sent to the quality inspection module;

[0010] The quality inspection module performs quality inspection on the target code to obtain the quality inspection results.

[0011] According to some embodiments of this application, the step of obtaining target code and code expansion instructions based on the code management module, and parsing the code expansion instructions to obtain code expansion events, includes:

[0012] The code extension instructions are parsed to obtain a code creation event, which is used to create the target code;

[0013] The code creation event is identified as the code expansion event.

[0014] According to some embodiments of this application, the step of obtaining the target code and code expansion instructions based on the code management module, and parsing the code expansion instructions to obtain code expansion events, further includes:

[0015] The code extension instructions are parsed to obtain a code update event, which is used to merge the target code into the original code.

[0016] The code update event is identified as the code expansion event.

[0017] According to some embodiments of this application, the step of matching the extended callback interface corresponding to the code extension event from a preset interface database based on the event callback module includes:

[0018] Configure a network hook mechanism for the event callback module;

[0019] The event callback module, based on the network hook mechanism, matches the extended callback interface corresponding to the code extended event from the interface database.

[0020] According to some embodiments of this application, the step of performing quality inspection on the target code based on the quality inspection module to obtain quality inspection results includes:

[0021] The quality inspection module parses the target code to obtain a target syntax tree corresponding to the target code.

[0022] The target syntax tree is subjected to quality detection based on preset code rules, and the quality detection result is obtained.

[0023] According to some embodiments of this application, the target syntax tree includes multiple branch nodes, each branch node corresponding to a syntax structure in the target code. The step of performing quality checks on the target syntax tree based on preset code specifications to obtain the quality check result includes:

[0024] Based on the preset code rules, rule comparison is performed on each branch node of the target syntax tree to obtain the comparison result;

[0025] Based on the comparison results, identify the problematic code in the target code that does not conform to the preset code rules, and the problem location information corresponding to the problematic code;

[0026] The quality inspection result is obtained based on the problem code and the problem location information.

[0027] According to some embodiments of this application, the step of performing quality inspection on the target code based on the quality inspection module to obtain quality inspection results includes:

[0028] Based on the quality inspection module, the target code is compared with the original code to obtain the incremental code;

[0029] The quality inspection is performed based on the incremental code to obtain the quality inspection result.

[0030] The code quality inspection apparatus according to a second aspect embodiment of this application includes:

[0031] The code management module is used to obtain target code and code extension instructions, parse the code extension instructions to obtain code extension events, the code extension events are used to extend the original code based on the target code, and the code extension events are transmitted to the event callback module;

[0032] The event callback module is used to match the extension callback interface corresponding to the code extension event from the preset interface database, and send the target code to the quality inspection module;

[0033] The quality inspection module is used to perform quality inspection on the target code and obtain the quality inspection results.

[0034] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the code quality inspection method as described in any one of the embodiments of the first aspect of this application.

[0035] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which is executed by a processor to implement the code quality inspection method as described in any one of the embodiments of the first aspect of this application.

[0036] The code quality inspection method, code quality inspection device, electronic device, and storage medium according to the embodiments of this application have at least the following beneficial effects:

[0037] The code quality inspection method of this application is applied to a code quality inspection device, which includes a code management module, an event callback module, and a quality inspection module. First, the code management module acquires the target code and code extension instructions, and parses the code extension instructions to obtain code extension events. These code extension events are used to extend the original code based on the target code. The code management module transmits the code extension events to the event callback module. The event callback module then matches the corresponding extension callback interface from a pre-set interface database. Further, based on the event callback module and the extension callback interface, the target code is sent to the quality inspection module. Finally, the quality inspection module performs quality inspection on the target code and obtains the quality inspection result. The code quality inspection method of this application can automatically trigger quality inspection of the target code after acquiring the target code and code extension instructions, thus improving the efficiency of code quality inspection.

[0038] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0039] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:

[0040] Figure 1 A flowchart illustrating the code quality inspection method provided in this application embodiment;

[0041] Figure 2 This is an optional flowchart of step S101 in an embodiment of this application;

[0042] Figure 3 This is another optional flowchart of step S101 in an embodiment of this application;

[0043] Figure 4 This is an optional flowchart illustrating step S103 in an embodiment of this application;

[0044] Figure 5 This is an optional flowchart of step S105 in an embodiment of this application;

[0045] Figure 6 This is an optional flowchart illustrating step S502 in an embodiment of this application;

[0046] Figure 7 This is another optional flowchart of step S105 in an embodiment of this application;

[0047] Figure 8This is a schematic diagram of the code quality inspection device provided in the embodiments of this application;

[0048] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0049] The embodiments of this application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0050] In the description of this application, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0051] In the description of this application, it should be understood that the orientation descriptions, such as up, down, left, right, front, and back, are based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0052] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0053] In the description of this application, it should be noted that, unless otherwise explicitly defined, terms such as "setting," "installation," and "connection" should be interpreted broadly. Those skilled in the art can reasonably determine the specific meaning of the above terms in this application based on the specific content of the technical solution. Furthermore, the identification of specific steps in the following text does not imply a limitation on the order of steps or execution logic. The execution order and logic between each step should be understood and inferred from the content described in the embodiments.

[0054] Code quality inspection refers to the inspection and testing of completed program code. The inspection typically includes checking the correctness of basic syntax, the existence of security issues, and the ease of review and maintenance. It's important to note that code quality inspection is a crucial part of software development and is usually triggered in two ways: first, manual review, where a professional software engineer reviews the code to ensure it conforms to coding standards; second, using plugins within development tools to perform code style checks automatically.

[0055] In related technologies, manual code quality inspection is limited by manpower and cannot efficiently inspect large-scale computer programs. Furthermore, different software engineers may have different evaluation standards for code quality, making objective assessment difficult. Integrating third-party plugins into the code may alter the programming architecture, similarly hindering accurate and rapid code quality inspection and resulting in low efficiency. Therefore, how to conduct efficient code quality inspection has become a pressing issue for the industry.

[0056] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes a code quality inspection method, electronic device, and computer storage medium capable of efficiently performing code quality inspection.

[0057] The following explanation is based on the accompanying drawings.

[0058] Figure 1 This is an optional flowchart illustrating the code quality inspection method provided in this application. The code quality inspection method of this application is applied to a code quality inspection device, which includes a code management module, an event callback module, and a quality inspection module. Figure 1 The method may include, but is not limited to, the following steps S101 to S105.

[0059] Step S101: Obtain the target code and code extension instructions based on the code management module, and parse the code extension instructions to obtain code extension events. The code extension events are used to extend the original code based on the target code.

[0060] Step S102: Based on the code management module, the code extension event is transmitted from the code management module to the event callback module;

[0061] Step S103: Based on the event callback module, the extended callback interface corresponding to the code extended event is obtained from the preset interface database;

[0062] Step S104: Based on the event callback module and the extended callback interface, send the target code to the quality inspection module;

[0063] Step S105: Perform quality inspection on the target code based on the quality inspection module to obtain the quality inspection results.

[0064] The code quality inspection method of this application, as shown in steps S101 to S105 above, is applied to a code quality inspection device. The code quality inspection device includes a code management module, an event callback module, and a quality inspection module. First, the target code and code extension instructions are obtained based on the code management module. The code extension instructions are then parsed to obtain code extension events. These code extension events are used to extend the original code based on the target code. The code management module transmits the code extension events to the event callback module. The event callback module then matches the corresponding extension callback interface from a preset interface database. Further, based on the event callback module and the extension callback interface, the target code is sent to the quality inspection module. Finally, the quality inspection module performs quality inspection on the target code to obtain the quality inspection result. The code quality inspection method of this application can automatically trigger quality inspection of the target code after obtaining the target code and code extension instructions, thus improving the efficiency of code quality inspection.

[0065] In step S101 of some embodiments of this application, it is necessary to obtain the target code and code extension instructions based on the code management module, and parse the code extension instructions to obtain code extension events. These code extension events are used to extend the original code based on the target code. It should be clarified that the code extension instructions reflect the processing requirements for the target code, such as creating new code, updating the original code, and other various requirements. The original code refers to code that has been pre-stored in the code management module. The code management module refers to the module used to manage the target code according to the code extension instructions. Managing the code can include various operations such as creating a new piece of code based on the target code according to the code extension instructions, merging the target code as a branch into the original code according to the code extension instructions, etc. In some embodiments, after parsing the code extension instructions, code extension events can be obtained. These code extension events are used to extend the original code based on the target code. Extending the original code can either involve creating new code based on the target code (where the original code is empty or the new code exists independently of the original code), or merging the target code into the original code (where the target code is a branch of the original code). According to some preferred embodiments provided in this application, after parsing and processing the code extension instructions, other information required for extending the original code, such as the location information and version information required for extending the original code, can also be obtained.

[0066] It should be understood that the target code and code extension instructions can be obtained by the user through an input device to the code quality inspection device, or by the code quality inspection device through various means such as the Internet, Bluetooth, and local area network. It should be noted that there are various ways to obtain the target code and code extension instructions based on the code management module, and to parse the code extension instructions to obtain code extension events, including but not limited to the specific embodiments mentioned above.

[0067] In some specific embodiments of this application, the code management module can be a distributed version control system, with Git being a preferred example. It should be noted that Git is an open-source distributed version control system that can effectively and quickly handle version management for projects ranging from very small to very large. It is also an open-source version control software that emerged to help manage Linux kernel development. Git is a version control tool developed based on the Linux kernel. Unlike commonly used version control tools such as CVS and Subversion, Git uses a distributed repository approach, eliminating the need for server-side software support, making source code distribution and exchange extremely convenient. Because Git is suitable for distributed development, emphasizes individual contributions, and minimizes the pressure and data volume on public servers, coupled with its speed and flexibility, conflicts can be easily resolved between any two developers, and it also supports offline work. Therefore, using Git as the code management module is a preferred embodiment of this application. It should be pointed out that the code management module can include, but is not limited to, the specific embodiments described above.

[0068] Reference Figure 2 In the code quality inspection method according to some embodiments of this application, step S101 may include, but is not limited to, the following steps S201 to S202.

[0069] Step S201: Parse the code extension instructions to obtain the code creation event, which is used to create the target code;

[0070] Step S202: The code creation event is identified as a code extension event.

[0071] According to steps S201 to S202 of some embodiments of this application, in order to obtain the code extension event, it is necessary to first parse the code extension instruction to obtain the code creation event, wherein the code creation event is used to create the target code, and the code creation event is determined as the code extension event. It should be noted that the code creation event is used to create the target code, that is, independent of the original code, and the target code is placed into the local code repository as an independent new code. In some exemplary embodiments, when the code extension instruction includes the git commit instruction, then after parsing it, the commit event as the code extension event can be obtained. Since git commit in Git means "git commit", it is a Git system command mainly used to commit the changes in the staging area to the local code repository, the commit event can be used as the code creation event in the embodiments of this application. It should be clarified that the purpose of parsing the code extension event in the embodiments of this application is so that the event callback module can match the extension callback interface corresponding to the code extension event from the preset interface database, so that the target code can be sent to the quality inspection module for quality inspection based on the event callback module and the extension callback interface. When the code extension event is a commit event, it means that the target code needs to be moved from the staging area into the local code repository. This could mean that a new, independent code has been created. In this case, there is no need to consider the compatibility between the target code and the original code. Instead, quality checks are performed on whether the basic syntax of the target code is used correctly, whether there are any data security issues, and whether the target code is easy to review and maintain.

[0072] As illustrated in steps S201 to S202, the code extension instructions are first parsed to obtain a code creation event. This code creation event is used to create the target code, and then it is identified as a code extension event. This facilitates the subsequent matching of the extension callback interface corresponding to the code extension event from a preset interface database based on the event callback module, thereby further improving the efficiency of code quality detection.

[0073] Reference Figure 3 In the code quality inspection method according to some embodiments of this application, step S101 may include, but is not limited to, the following steps S301 to S302.

[0074] Step S301: Parse the code extension instructions to obtain the code update event. The code update event is used to merge the target code into the original code.

[0075] Step S302: The code update event is identified as a code extension event.

[0076] According to steps S301 to S302 of some embodiments of this application, in order to obtain a code extension event, the code extension instruction needs to be parsed first to obtain a code update event. The code update event is used to merge the target code into the original code, and then the code update event is determined as a code extension event. It should be noted that the code update event is used to merge the target code into the original code, that is, based on the original code, the target code is merged into the original code as a branch to update the original code. In some exemplary embodiments, when the code extension instruction includes the git merge instruction, then after parsing it, the merge event as a code extension event can be obtained. In Git, the merge event is used to merge the content of branches together, while git merge can be used to integrate the branch previously created using the git branch command and the content independently developed on this branch into a single branch. git merge will merge multiple commit sequences into a unified commit history. Therefore, the merge event can be used as a code update event in the embodiments of this application. It should be clarified that the purpose of parsing the code extension event in this embodiment is to enable the event callback module to match the corresponding extension callback interface from the preset interface database. This allows the target code to be sent to the quality inspection module for quality inspection based on the event callback module and the extension callback interface. When the code extension event is a merge event, it means that the target code needs to be merged into the original code. Therefore, whether the target code matches the specifications of the original code is what needs to be evaluated during the quality inspection process. If the target code matches the specifications of the original code, it indicates that the target code has high quality; if the target code does not match the specifications of the original code, it indicates that the target code has low quality.

[0077] As illustrated in steps S301 to S302, the code extension instructions are first parsed to obtain a code update event. This code update event is used to merge the target code into the original code, and then the code update event is identified as a code extension event. This facilitates the subsequent matching of the extension callback interface corresponding to the code extension event from a preset interface database based on the event callback module, thereby further improving the efficiency of code quality detection.

[0078] In step S102 of some embodiments of this application, the code extension event is transmitted from the code management module to the event callback module based on the code management module. It should be noted that the code management module can be configured with execution switches corresponding to various types of code extension events. For example, when the code extension event is a code creation event, new code can be created based on the target code using the corresponding execution switch (the original code is empty, or the new code exists independently of the original code); or, for example, when the code extension event is a code update event, the target code can be merged into the original code using the corresponding execution switch (the target code becomes a branch of the original code). It should be pointed out that in some embodiments, whenever the code management module performs a management operation on the target code, it will correspondingly transmit the code extension event from the code management module to the event callback module, so that the event callback module can obtain the corresponding extension callback interface based on the code extension event, thereby sending the target code to the quality inspection module for quality inspection.

[0079] In steps S103 to S104 of some embodiments of this application, the event callback module matches the extension callback interface corresponding to the code extension event from a preset interface database, and then sends the target code to the quality inspection module based on the event callback module and the extension callback interface. It should be noted that the event callback module is configured with a preset interface database, which stores extension callback interfaces corresponding to various types of code extension events. The extension callback interfaces are used to send the target code to the quality inspection module.

[0080] In some specific embodiments of this application, if the Git server is used as the code management module, after obtaining the target code and code extension instructions from the Git server, the code extension instructions can be further parsed on the Git server. When the code extension instructions include the `git merge` instruction, parsing it will yield the `merge` event as a code extension event. Similarly, when the code extension instructions include the `git commit` instruction, parsing it will yield the `commit` event as a code extension event. The code extension events are used to extend the original code based on the target code. After the event callback module receives the code extension event, it immediately matches the extension callback interface corresponding to the code extension event from the preset interface database. When the event callback module calls the extension callback interface, it sends the content of the current operation request (i.e., the target code) to the extension callback interface. Since the extension callback interface matches the code extension event, when the target code is further transferred to the quality inspection module through the extension callback interface, the quality inspection module can perform quality inspection on the target code and obtain the quality inspection result. Specifically, in Git, the `merge` event is used to combine the contents of branches together, while `git merge` can be used to integrate a branch previously created using the `git branch` command with content independently developed on that branch into a single branch. `git merge` merges multiple commit sequences into a unified commit history. In some use cases, `git merge` can also be used to merge two branches. In Git, `git commit` means "git commit," a command used to commit changes from the staging area to the local repository. The syntax for `git commit` is "git commit -m [message]," where "-m" is the parameter for adding a commit message, and "[message]" can be a comment. It should be understood that code expansion events can include, but are not limited to, the specific examples mentioned above.

[0081] In some exemplary embodiments of this application, the event callback module can match the extension callback interface corresponding to the code extension event from a preset interface database based on the WebHooks mechanism.

[0082] It's important to note that web hooks are a method in web development for adding or changing webpage behavior through custom callback functions. These callbacks can be saved, modified, and managed by third-party users and developers associated with the original website or application. Webhooks are "user-defined HTTP callbacks" that can be activated by certain events, such as pushing code to a source or commenting on a blog. When this event occurs, the original website sends an HTTP request to the URL configured for the webhook. Users can configure them to trigger events on the webpage to invoke the behavior of another website; this can include triggering various types of events. Webhooks can also be used to activate build operations in continuous integration systems or to alert defect tracking management systems. Because webhooks use HTTP, they can be seamlessly integrated into web services without adding new infrastructure. Webhooks are sometimes referred to as "reverse APIs," where client applications call server-side applications. Unlike proactive request-response APIs, webhooks allow for real-time, passive reception of change information. This represents a reversal of the client-server model. In the traditional approach, the client requests data from the server, and the server then provides the data to the client (the client is essentially pulling data). In the WebHooks paradigm, the server updates the necessary resources and automatically sends these updates as updates to the specified configured clients (the server is actively pushing data). The client is not the requester but a passive receiver. This reversal of control can facilitate many communication requests that would otherwise require more complex requests and continuous polling on a remote server. By simply receiving resources instead of directly sending requests, we can update remote code repositories, easily allocate resources, and even integrate them into existing systems to update endpoints and related data according to API requirements. Therefore, based on the WebHooks mechanism, matching the extension callback interface corresponding to the code extension event from a pre-defined interface database, and then sending the target code to the quality inspection module for quality checks based on the event callback module and the extension callback interface, this approach achieves automatic triggering of the code quality inspection method without the need for third-party plugins, making it a preferred implementation of this application.

[0083] Reference Figure 4 In the code quality inspection method according to some embodiments of this application, step S103 may include, but is not limited to, the following steps S401 to S402.

[0084] Step S401: Configure a network hook mechanism for the event callback module;

[0085] In step S402, the event callback module uses a network hook mechanism to match the extended callback interface corresponding to the code extended event from the interface database.

[0086] In steps S401 to S402 of some embodiments of this application, a web hook mechanism needs to be configured for the event callback module. This enables the event callback module to match the extended callback interface corresponding to the code extension event from the interface database based on the web hook mechanism. It is important to emphasize that web hooks are a method in web development that uses custom callback functions to add or change the performance of a webpage. These callbacks can be saved, modified, and managed by third-party users and developers associated with the original website or application. In some exemplary embodiments, after obtaining the code extension event, the event callback module further uses the code extension event as identification information to match the extended callback interface corresponding to the code extension event from the interface database. It should be noted that after the custom callback function of WebHooks is configured, it can automatically match the extended callback interface corresponding to the code extension event from the interface database and send the target code to the quality inspection module through the extended callback interface. This allows for quality inspection of the target code, achieving automatic triggering of the code quality inspection method without the need for third-party plugins, thereby further improving the efficiency of code quality inspection.

[0087] In step S105 of some embodiments of this application, the target code is subjected to quality inspection based on the quality inspection module to obtain the quality inspection result. It should be noted that during the quality inspection of the target code, the detection methods used can be associated with the code extension event. Since the extension callback interface matches the code extension event, it can guide the quality inspection, indicating the specific detection method to be selected during the quality inspection process. Specifically, when the code extension event is a code update event, it means that the target code needs to be merged into the original code. Therefore, whether the target code matches the specifications of the original code is what needs to be evaluated during the quality inspection process. If the target code matches the specifications of the original code, it indicates that the target code has high quality; if the target code does not match the specifications of the original code, it indicates that the target code has low quality. Furthermore, when the code extension event is a code creation event, it means that the target code needs to be moved from the staging area into the local code repository, which may be creating a new independent code. In this case, there is no need to consider the compatibility between the target code and the original code; the quality inspection focuses more on whether the basic syntax of the target code is used correctly, whether there are data security issues in the target code, and whether the target code is easy to review and maintain. If the target code uses correct basic syntax, has no data security issues, or is easy to review, then the target code is considered to be of high quality. Conversely, if the target code uses incorrect basic syntax, has data security issues, or contains complex logic that makes it difficult to review, then the target code is considered to be of low quality. It should be noted that there are various ways to perform quality checks on target code, including, but not limited to, the examples given above.

[0088] Reference Figure 5 According to some embodiments of this application, step S105 may include, but is not limited to, steps S501 to S502.

[0089] Step S501: Based on the quality inspection module, the target code is parsed to obtain the target syntax tree corresponding to the target code;

[0090] Step S502: Perform quality checks on the target syntax tree based on preset code rules to obtain quality check results.

[0091] In step S501 of some embodiments of this application, the target code is parsed based on the quality inspection module to obtain the target syntax tree corresponding to the target code. It should be noted that the target syntax tree refers to the abstract syntax tree generated based on the target syntax. In computer science, an abstract syntax tree (AST), or simply a syntax tree, is an abstract representation of the syntactic structure of source code. It represents the syntactic structure of a programming language in a tree-like form, where each node in the tree represents a structure in the source code. The syntax is described as "abstract" because it does not necessarily represent every detail that appears in the actual syntax. For example, nested parentheses can be implicitly included in the tree structure and do not need to be presented as tree nodes, while conditional jump statements of the types if, condition, and then can be represented using nodes with two branches. Corresponding to the abstract syntax tree is the concrete syntax tree (usually called a parse tree). In some embodiments of this application, parsing the target code based on the quality inspection module can translate and compile the target code, thereby creating the target syntax tree corresponding to the target code. It should be noted that in some embodiments of this application, in order to perform quality inspection on the target code, it is necessary to first parse the target code based on the quality inspection module to obtain the target syntax tree corresponding to the target code. The reason is that the target syntax tree can reflect the syntactic structure of the target code. Therefore, by further comparing the target syntax tree with the preset code rules, it can be determined whether the syntactic structure of the target code follows the preset code rules, thereby realizing the quality inspection of the target code and obtaining the quality inspection result.

[0092] In step S502 of some embodiments of this application, the target syntax tree is subjected to quality detection based on preset code rules to obtain a quality detection result. It should be noted that preset code rules are pre-set syntax rules that the target code should follow. In some more specific embodiments, when the code expansion event is a code update event, it means that the target code needs to be merged into the original code. Therefore, whether the target code matches the specification of the original code can be set as the specific content of the preset code rules. For example, if the target code can match the specification of the original code, it indicates that the target code has high quality; if the target code cannot match the specification of the original code, it indicates that the target code has low quality. Furthermore, when the code extension event is a code creation event, it means that the target code needs to be moved from the staging area into the local code repository. This could mean creating a new, independent piece of code. In this case, the specific content of the preset code rules does not need to determine the compatibility between the target code and the original code. Instead, it focuses on quality checks regarding the correctness of the target code's basic syntax, the existence of data security issues, and the ease of review and maintenance. For example, if the target code uses correct basic syntax, has no data security issues, or is easy to review, it indicates high quality. Conversely, if the target code uses incorrect basic syntax, has data security issues, or exhibits complex logic and is difficult to review, it indicates low quality. It should be noted that preset code rules can be set in various ways, including, but not limited to, the examples mentioned above.

[0093] In the embodiments shown in steps S501 to S502, the target code needs to be parsed first using the quality inspection module to obtain the target syntax tree corresponding to the target code. Then, the target syntax tree is subjected to quality inspection based on preset code rules to obtain the quality inspection result. Since the target syntax tree is generated based on the parsing of the target code, and as a type of abstract syntax tree, it can concretely represent the syntactic structure of the target code, which is beneficial for quality inspection and can further improve the efficiency of code quality inspection.

[0094] Reference Figure 6 According to some embodiments of this application, the target syntax tree includes multiple branch nodes, each branch node corresponding to a syntax structure in the target code, and step S502 may include, but is not limited to, the following steps S601 to S603.

[0095] Step S601: Based on preset code rules, perform rule comparison on each branch node of the target syntax tree to obtain the comparison result;

[0096] Step S602: Based on the comparison results, identify the problematic codes in the target code that do not conform to the preset code rules, as well as the problem location information corresponding to the problematic codes;

[0097] Step S603: Obtain the quality inspection result based on the problem code and problem location information.

[0098] In step S601 of some embodiments of this application, rule comparison is performed on each branch node of the target syntax tree based on preset code rules to obtain comparison results. It should be noted that the target syntax tree includes multiple branch nodes, each corresponding to a syntactic structure in the target code. In some exemplary embodiments of this application, since the target syntax tree refers to an abstract syntax tree generated based on the target syntax, generating the target syntax tree requires two stages: first, tokenization, which decomposes the string of characters in the target code into meaningful code blocks, collectively referred to as lexical units; second, semantic analysis (parse), which, based on the tokenization results, converts the lexical unit stream into branch nodes composed of nested elements, and then determines the combination of several branch nodes as a tree representing the program's syntactic structure, i.e., the target syntax tree. It should be pointed out that since the target syntax tree includes multiple branch nodes, each corresponding to a syntactic structure in the target code, rule comparison is performed on each branch node of the target syntax tree based on preset code rules to determine whether each syntactic structure in the target code follows the preset code rules, thereby obtaining comparison results. It should be understood that the comparison of each branch node of the target syntax tree based on preset code rules to obtain the comparison results may include, but are not limited to, the specific embodiments mentioned above.

[0099] In step S602 of some embodiments of this application, based on the comparison results, problematic code in the target code that does not conform to preset code rules and the corresponding problem location information are determined. It should be emphasized that since the target syntax tree includes multiple branch nodes, each branch node corresponds to a syntactic structure in the target code, rule comparison of each branch node of the target syntax tree based on preset code rules can determine whether each syntactic structure in the target code follows the preset code rules, thereby obtaining the comparison results. In some exemplary embodiments, the comparison results obtained by rule comparison of each branch node of the target syntax tree based on preset code rules can reflect problematic code in the target code that does not conform to the preset code rules and the corresponding problem location information. The problematic code refers to the code segment in the target code that does not conform to the preset code rules, while the problem location information refers to the position information of the problematic code in the target code.

[0100] In some more specific embodiments, when the code expansion event is a code update event, it means that the target code needs to be merged into the original code. Therefore, whether the target code matches the specification of the original code can be set as the specific content of the preset code rules. For example, if the target code can match the specification of the original code, it can be said that the target code has high quality. If the target code cannot match the specification of the original code, it can be said that the target code has low quality. Therefore, in the process of comparing the rules of each branch node of the target syntax tree based on the above preset code rules, it is possible to determine which segments in the target code belong to the problematic code, and use the line number of the problematic code as the corresponding problem location information. Furthermore, when the code extension event is a code creation event, it means that the target code needs to be moved from the staging area into the local code repository. This could mean creating a new, independent piece of code. In this case, the specific content of the preset code rules does not need to determine the compatibility between the target code and the original code. Instead, it focuses on quality checks regarding the correctness of the target code's basic syntax, the existence of data security issues, and the ease of review and maintenance. For example, if the target code uses the correct basic syntax, has no data security issues, or is easy to review, it indicates high quality. Conversely, if the target code uses incorrect basic syntax, has data security issues, or is logically complex and difficult to review, it indicates low quality. Therefore, by comparing the various branch nodes of the target syntax tree based on the preset code rules, it is possible to determine which segments in the target code are problematic and use the line numbers of these problematic code as the corresponding problem location information. It should be understood that there are various ways to determine problematic code in the target code that does not conform to the preset code rules and the corresponding problem location information based on the comparison results. These methods can include, but are not limited to, the embodiments described above.

[0101] In step S603 of some embodiments of this application, a quality inspection result is obtained based on the problematic code and the problem location information. It should be noted that since the problematic code refers to a code segment in the target code that does not conform to preset code rules, and the problem location information refers to the position information of the problematic code in the target code, a quality inspection result reflecting the quality of the target code can be obtained based on the problematic code and the problem location information. It should also be pointed out that after obtaining the quality inspection result reflecting the quality of the target code, the quality inspection result can be fed back to maintenance personnel or the maintenance server to request code repair, or it can be fed back to the alarm module to remind software engineers that there are syntax defects in the target code.

[0102] Through the embodiments shown in steps S601 to S603 of this application, the various branch nodes of the target syntax tree are first compared according to preset code rules to obtain comparison results. Then, based on the comparison results, problematic codes in the target code that do not conform to the preset code rules and the problem location information corresponding to the problematic codes are identified. Furthermore, based on the problematic codes and the problem location information, quality inspection results are obtained. The quality inspection results can be obtained by using the problematic codes and the problem location information corresponding to the problematic codes as clues, which provides guidance and reference for code maintenance and repair work and improves the efficiency of operation and maintenance work.

[0103] Reference Figure 7 According to some embodiments of this application, step S105 may include, but is not limited to, steps S701 to S702.

[0104] Step S701: Based on the quality inspection module, the target code is compared with the original code to obtain the incremental code;

[0105] Step S702: Perform quality inspection based on incremental code to obtain quality inspection results.

[0106] In step S701 of some embodiments of this application, the target code and the original code are compared based on the quality inspection module to obtain incremental code. It should be noted that incremental code refers to the newly added code segment in the target code compared to the original code. It should also be pointed out that the original code is pre-stored in the code management module. In some embodiments, the target code can be used to update the original code, thus there is overlap between the target code and the original code. Therefore, to improve the efficiency of code quality inspection, the target code and the original code can be compared based on the quality inspection module to obtain incremental code, thereby identifying the newly added code segment in the target code compared to the original code. Then, quality inspection is further performed based on the incremental code to obtain the quality inspection result.

[0107] In step S702 of some embodiments of this application, quality inspection is performed based on incremental code to obtain quality inspection results. It should be noted that, since incremental code is a newly added code segment in the target code compared to the original code, in some embodiments, since the original code has already undergone quality inspection when it is pre-stored into the code management module, performing quality inspection based on incremental code is equivalent to performing quality inspection on code segments in the target code that have not yet been inspected. It is important to emphasize that during the quality inspection of the target code, the choice of which inspection methods can be associated with code extension events. Since the extension callback interface matches the code extension event, the extension callback interface can guide the quality inspection, indicating the specific inspection methods selected during the quality inspection process.

[0108] Through the embodiments shown in steps S701 to S702 above, the target code and the original code are first compared based on the quality inspection module to obtain incremental code, and then quality inspection is performed based on the incremental code to obtain quality inspection results. This can determine the difference code between the target code and the original code before quality inspection, and perform quality inspection on the code segments in the target code that have not yet been inspected, thereby further improving the efficiency of code quality inspection.

[0109] Reference Figure 8 The code quality inspection apparatus 800 according to a second aspect embodiment of this application includes:

[0110] The code management module 801 is used to obtain the target code and code extension instructions, parse the code extension instructions to obtain code extension events, the code extension events are used to extend the original code based on the target code, and the code extension events are transmitted to the event callback module 802.

[0111] Event callback module 802 is used to match the extension callback interface corresponding to the code extension event from the preset interface database and send the target code to the quality inspection module 803;

[0112] The quality inspection module 803 is used to perform quality inspection on the target code and obtain the quality inspection results.

[0113] It should be noted that, Figure 8 The code quality inspection device 800 shown includes a code management module 801, an event callback module 802, and a quality inspection module 803. First, the code management module 801 acquires the target code and code extension instructions, and parses the code extension instructions to obtain code extension events. These code extension events are used to extend the original code based on the target code. The code management module 801 transmits the code extension events to the event callback module 802. The event callback module 802 then matches the corresponding extension callback interface from a preset interface database. Further, based on the event callback module 802 and the extension callback interface, the target code is sent to the quality inspection module 803. Finally, the quality inspection module 803 performs quality inspection on the target code to obtain the quality inspection result. The code quality inspection method in this application can automatically trigger quality inspection of the target code after acquiring the target code and code extension instructions, improving the efficiency of code quality inspection.

[0114] Figure 9 An electronic device 900 according to an embodiment of this application is shown. The electronic device 900 includes a processor 901, a memory 902, and a computer program stored in the memory 902 and executable on the processor 901. When the computer program is executed, it is used to perform the code quality inspection method described above.

[0115] The processor 901 and the memory 902 can be connected via a bus or other means.

[0116] The memory 902, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs, such as the code quality inspection method described in the embodiments of this application. The processor 901 implements the above-described code quality inspection method by running the non-transitory software program and instructions stored in the memory 902.

[0117] The memory 902 may include a program storage area and a data storage area. The program storage area may store the operating system and application programs required for at least one function. The data storage area may store code quality control methods that execute as described above. Furthermore, the memory 902 may include high-speed random access memory 902, and may also include non-transitory memory 902, such as at least one storage device, flash memory, or other non-transitory solid-state storage device. In some embodiments, the memory 902 may optionally include remotely located memories 902 relative to the processor 901, which can be connected to the electronic device 900 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0118] The non-transitory software program and instructions required to implement the above code quality inspection method are stored in memory 902. When executed by one or more processors 901, the above code quality inspection method is executed, for example, executing... Figure 1 Method steps S101 to S105, Figure 2 Method steps S201 to S202, Figure 3 Method steps S301 to S302, Figure 4 Method steps S401 to S402, Figure 5 Method steps S501 to S502, Figure 6 Method steps S601 to S603, Figure 7 The method steps S701 to S702.

[0119] This application also provides a computer-readable storage medium storing computer-executable instructions for executing the above-described code quality inspection method.

[0120] In one embodiment, the computer-readable storage medium stores computer-executable instructions that are executed by one or more control processors, for example, executing... Figure 1 Method steps S101 to S105, Figure 2 Method steps S201 to S202, Figure 3 Method steps S301 to S302, Figure 4 Method steps S401 to S402, Figure 5 Method steps S501 to S502, Figure 6 Method steps S601 to S603, Figure 7 The method steps S701 to S702.

[0121] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0122] Those skilled in the art will understand that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, storage device storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically include computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium. It should also be understood that the various implementation methods provided in this application can be arbitrarily combined to achieve different technical effects.

[0123] The above provides a detailed description of the preferred embodiments of this application. However, this application is not limited to the above-described embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.

Claims

1. A code quality inspection method, applied to a code quality inspection device, the code quality inspection device comprising a code management module, an event callback module, and a quality inspection module, characterized in that, include: The target code and code extension instructions are obtained based on the code management module, and the code extension instructions are parsed to obtain code extension events; wherein, the code extension events are used to extend the original code based on the target code, and the original code refers to the code that has been pre-stored in the code management module; Based on the code management module, the code extension event is transmitted from the code management module to the event callback module; The event callback module matches the extended callback interface corresponding to the code extension event from the preset interface database; wherein, the extended callback interface is used to guide the specific detection method to be selected for quality inspection. Based on the event callback module and the extended callback interface, the target code is sent to the quality inspection module; The quality inspection module parses the target code to obtain a target syntax tree corresponding to the target code; wherein, the target syntax tree includes multiple branch nodes, and each branch node corresponds to a syntax structure in the target code; Based on preset code rules, each branch node of the target syntax tree is compared according to the rules to obtain the comparison results; The preset code rules compare the rules of each branch node of the target syntax tree to obtain the comparison results, including: When the code expansion event is specifically a code update event, rule comparison is performed on each branch node of the target syntax tree based on preset code rules to determine whether the target code matches the specification of the original code, and the corresponding comparison result is obtained; When the code extension event is specifically a code creation event, rule comparison is performed on each branch node of the target syntax tree based on preset code rules to determine whether the basic syntax of the target code is used correctly, whether the target code has data security issues, and whether the target code is easy to review, so as to obtain the corresponding comparison results. Based on the comparison results, identify the problematic code in the target code that does not conform to the preset code rules, and the problem location information corresponding to the problematic code; Based on the problem code and the problem location information, the quality inspection result is obtained.

2. The method according to claim 1, characterized in that, The step of obtaining target code and code extension instructions based on the code management module, and parsing the code extension instructions to obtain code extension events includes: The code extension instructions are parsed to obtain a code creation event, which is used to create the target code; The code creation event is identified as the code expansion event.

3. The method according to claim 1, characterized in that, The step of obtaining the target code and code extension instructions based on the code management module, and parsing the code extension instructions to obtain code extension events, further includes: The code extension instructions are parsed to obtain a code update event, which is used to merge the target code into the original code. The code update event is identified as the code expansion event.

4. The method according to any one of claims 1 to 3, characterized in that, The step of obtaining the extended callback interface corresponding to the code extension event from a preset interface database based on the event callback module includes: Configure a network hook mechanism for the event callback module; The event callback module, based on the network hook mechanism, matches the extended callback interface corresponding to the code extended event from the interface database.

5. The method according to claim 1, characterized in that, The quality inspection of the target code based on the quality inspection module, and the resulting quality inspection results, include: Based on the quality inspection module, the target code is compared with the original code to obtain the incremental code; The quality inspection is performed based on the incremental code to obtain the quality inspection result.

6. A code quality inspection device, characterized in that, The code quality inspection method applied to any one of claims 1 to 5 includes: The code management module is used to obtain target code and code extension instructions, parse the code extension instructions to obtain code extension events, the code extension events are used to extend the original code based on the target code, and the code extension events are transmitted to the event callback module; The event callback module is used to match the extension callback interface corresponding to the code extension event from the preset interface database, and send the target code to the quality inspection module; The quality inspection module is used to perform quality inspection on the target code and obtain the quality inspection results.

7. An electronic device, characterized in that, include: A memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the code quality inspection method as described in any one of claims 1 to 5.

8. 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 code quality inspection method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Code quality detection method and device

    CN106201861A

  • Abnormal code detection method and device, electronic equipment and storage medium

    CN114895952A