Code verification method and device, electronic equipment and storage medium

By acquiring code configuration files and parsing programming languages, and using a pre-set code verification library to determine target tools and rules, the code in software projects is verified, solving the problem of inconsistent writing styles among different developers and improving code quality and readability.

CN120973649APending Publication Date: 2025-11-18ZHUYI TECHNOLOGY (GUANGDONG HENGQIN GUANGDONG-MACAO DEEP COOP ZONE) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511298611.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-11
Publication Date
2025-11-18

AI Technical Summary

Technical Problem

In software projects, the inconsistent quality and writing styles of code written by different developers make it difficult to control code quality, maintain it, and improve readability.

Method used

By obtaining the code configuration file, the file directory and programming language of the code to be verified are parsed out. The target verification tools and rules are determined from the pre-set code verification library. The code is verified based on these tools and rules, the verification results are output, and code that does not conform to the rules can be adjusted.

Benefits of technology

It enables flexible validation across different programming languages ​​and directories, improving the consistency and readability of code quality and reducing the difficulty of code maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120973649A_ABST
    Figure CN120973649A_ABST
Patent Text Reader

Abstract

The invention discloses a code verification method and device, electronic equipment and a storage medium, and relates to the technical field of Internet. The method comprises the following steps: firstly, obtaining a code configuration file, and then analyzing a file directory where a to-be-checked code is located and a programming language of the to-be-checked code from the code configuration file; and determining a target verification tool and a target verification rule from a preset code verification library according to the programming language, and verifying the to-be-verified code in the file directory based on the target verification tool and the target verification rule to obtain a verification result of the to-be-verified code. According to the method and the device, independent verification tools and verification rules can be adopted for different programming languages and even different directory files, and verification of code files can be realized more flexibly.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a code verification method and device, electronic equipment and storage medium. BACKGROUND

[0002] In the development process of a software project, division of labor among developers is often required. Taking a team cooperation to develop a software project as an example, the software project can include multiple functional modules, each of which is implemented by code written by a developer, and the code of each functional module is written by a corresponding developer. For example, the software project includes functional module A and functional module B, developer 1 is responsible for code writing of functional module A, and developer 2 is responsible for code writing of functional module B. However, since the code written by different developers has different qualities and code writing styles, it is difficult to control the code quality and maintain the style uniformity in the software project, thereby resulting in great difficulty in code maintenance and low readability. SUMMARY

[0003] In view of the above problems, the present application provides a code verification method, device, electronic equipment and storage medium, which can solve the above problems.

[0004] In a first aspect, an embodiment of the present application provides a code verification method, which comprises: obtaining a code configuration file; parsing a file directory in which to-be-verified code is located and a programming language of the to-be-verified code from the code configuration file; determining a target verification tool and a target verification rule from a pre-set code verification library according to the programming language; and verifying the to-be-verified code under the file directory based on the target verification tool and the target verification rule to obtain a verification result of the to-be-verified code.

[0005] In some embodiments, optionally, the verifying the to-be-verified code under the file directory based on the target verification tool and the target verification rule comprises: if a custom verification rule is set in the code configuration file, verifying the to-be-verified code under the file directory based on the target verification tool, the custom verification rule and the target verification rule.

[0006] Further, the verifying the to-be-verified code under the file directory based on the target verification tool, the custom verification rule and the target verification rule comprises: if the custom verification rule and the target verification rule have different verification methods for the to-be-verified code, determining a verification method with higher priority in the custom verification rule and the target verification rule; and verifying the to-be-verified code based on the target verification tool and the verification method with higher priority.

[0007] Further, before the determining the custom check rule and the check method with higher priority in the target check rule, the method further includes: setting priority for the check method of the target check rule in response to a user operation.

[0008] As an implementation, the determining the target check tool from the preset code check library according to the programming language includes: obtaining a preset check tool specified in advance from a specified field of the code configuration file; determining whether the preset check tool matches the programming language; and if so, determining the preset check tool as the target check tool.

[0009] In some embodiments, the checking the to-be-checked code under the file directory based on the target check tool and the target check rule includes: configuring a configuration file of the target check tool based on the target check rule; and running the target check tool, so that the target check tool checks the to-be-checked code based on the configuration file.

[0010] Optionally, after the checking the to-be-checked code under the file directory based on the target check tool and the target check rule to obtain a check result of the to-be-checked code, the method further includes: adjusting the to-be-checked code that does not conform to the target check rule based on the check result, and outputting the adjusted to-be-checked code.

[0011] Optionally, the target check rule includes a syntax specification of the programming language and a check rule predefined for the programming language.

[0012] In a second aspect, an embodiment of the present application provides a code check device, which includes: an obtaining module, an analyzing module, a determining module, and a checking module. The obtaining module is configured to obtain a code configuration file. The analyzing module is configured to analyze a file directory where to-be-checked code is located and a programming language of the to-be-checked code from the code configuration file. The determining module is configured to determine a target check tool and a target check rule from a preset code check library according to the programming language. The checking module is configured to check the to-be-checked code under the file directory based on the target check tool and the target check rule, and obtain a check result of the to-be-checked code.

[0013] In a third aspect, an embodiment of the present application provides an electronic device, which includes: one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more application programs are configured to execute the above method.

[0014] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, wherein the computer readable storage medium stores program codes, and the program codes can be invoked by a processor to execute the method.

[0015] In a fifth aspect, an embodiment of the present application provides a computer program product containing instructions, wherein the computer program product stores instructions, and when the instructions are run on a computer, the computer implements the method.

[0016] The code verification method and device, the electronic device and the storage medium provided by the present application first acquire a code configuration file, then parse a file directory where the code to be verified is located and a programming language of the code to be verified from the code configuration file. Then, the target verification tool and the target verification rule are determined from the pre-set code verification library according to the programming language, and then the code to be verified under the file directory is verified based on the target verification tool and the target verification rule to obtain the verification result of the code to be verified. The present application can use separate verification tools and verification rules for different programming languages and even different directory files, and can more flexibly implement the verification of the code file.

[0017] These aspects or other aspects of the present application will be more apparent in the following description of the embodiments. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without any creative effort on the basis of these drawings.

[0019] Figure 1 Fig. 1 shows an application environment schematic diagram of the code verification method provided by an embodiment of the present application; Figure 2 Fig. 2 shows a flowchart of the code verification method provided by an embodiment of the present application; Figure 3 Fig. 3 shows a schematic diagram of the code verification library provided by another embodiment of the present application; Figure 4 Fig. 4 shows a verification process schematic diagram of the code verification method provided by an embodiment of the present application; Figure 5 Fig. 5 shows a flowchart of the code verification method provided by another embodiment of the present application; Figure 6 Fig. 6 shows a flowchart of the code verification method provided by another embodiment of the present application; Figure 7A module block diagram of a code verification device provided by an embodiment of the present application is shown. Figure 8 A structural block diagram of an electronic device provided by an embodiment of the present application is shown. Figure 9 A structural block diagram of a computer readable storage medium provided by an embodiment of the present application is shown. Figure 10 A structural block diagram of a computer program product provided by an embodiment of the present application is shown. DETAILED DESCRIPTION

[0020] In order to enable personnel in the technical field to better understand the present application scheme, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application.

[0021] With the continuous expansion of the update iteration and boundary of software products, the volume of the corresponding source code files of the software also expands, and the types of programming languages are also increasing, such as javascript, typescript, css, html, vue, jsx, scss files in the front-end source code. In the development process of the software project, cooperation among developers is often required. Taking the development of a software project by a team as an example, the software project can include multiple functional modules, each functional module is implemented by the code written by a developer, and the code of each functional module is written by a corresponding developer. For example, the software project includes functional module A and functional module B, developer 1 is responsible for the code writing of functional module A, and developer 2 is responsible for the code writing of functional module B. However, due to the different code quality and code writing styles of different developers, it is difficult to control the code quality and maintain the style uniformity in the software project, resulting in great difficulty in code maintenance and low readability.

[0022] After careful research, the inventors found that if different verification methods are used to verify the code files of different programming languages, it is necessary to switch between multiple verification tools, which increases the workload, and may also lead to problems such as inconsistent code style and poor readability in the same software project. To solve the above problems, the present inventors have invested in research and development, unified the access configuration of multiple code verification tools, then encapsulated the basic verification rules, and then encapsulated the verification rules into hot-pluggable plug-ins for different programming languages and different style systems. Finally, a startup script is written, when the startup script is started, the configuration file is parsed, different code verification tools and rule plug-ins are assembled, the final configuration is generated, and then the verification is started.

[0023] In order to better understand the code verification method, device, electronic equipment and storage medium provided by the embodiments of the present application, the application environment suitable for the embodiments of the present application will be described first.

[0024] Referring to Figure 1 , Figure 1 application environment of the code verification method provided by an embodiment of the present application is shown, the code verification method, device, electronic device and storage medium provided by the embodiment of the present application can be applied to an application program development environment 100 as shown in the figure. Figure 1 The application program development environment 100 includes a server 110 and a terminal device 120, and the terminal device 120 can be connected to the server 110. The terminal device 120 is an electronic device for software development of a developer, and the terminal device 120 can be an electronic device such as a PC (Personal Computer), a notebook computer, etc. The terminal device 120 can be installed and run with a software development tool, which is a tool for coding and compiling programming language code. Optionally, the developer can perform operations such as writing, modifying, checking, running, etc. on the code through the software development tool.

[0025] The server 110 is used to store and detect the code uploaded by the terminal device 120. The server 110 can be a server, a server cluster composed of multiple servers, or a cloud computing service center.

[0026] The terminal device 120 and the server 110 can communicate through a network.

[0027] Exemplarily, the terminal device 120 installed and running with the software development tool is taken as an example. The developer writes the code of a software project in the terminal device 120 installed and running with the software development tool, and then uploads the completed code to the server 110 corresponding to the software project through the terminal device 120.

[0028] Optionally, before uploading the code, the code verification method provided by the embodiment of the present application can be used to verify the code in the terminal device 120 or the server 110. That is, the code verification method provided by the embodiment of the present application can be used to verify the code in the terminal device 120, and then the verified code is uploaded to the server 110; or the code verification method provided by the embodiment of the present application can be used to verify the received code in the server 110 after the terminal device 110 uploads the code to the server 110.

[0029] Optionally, multiple terminal devices 120 can be allowed to access the server 110 at the same time.

[0030] The above application environment is only an example for easy understanding, and it can be understood that the embodiment of the present application is not limited to the above application environment.

[0031] The code verification method, device, electronic device and storage medium provided by the embodiments of the present application will be described in detail below through specific embodiments.

[0032] Please refer to Figure 2 which shows a flowchart of a code verification method provided by an embodiment of the present application. The code verification method will be described in detail below with respect to the flowchart shown in Figure 2 The code verification method can specifically include the following steps: Step S210: Obtain a code configuration file.

[0033] In the embodiments of the present application, the code configuration file can be used to configure parameters and initial settings for the code to be verified. For example, the parameters configured in the code configuration file can include the running environment of the code to be verified, etc.

[0034] To facilitate reading of the code configuration file, the code configuration file is usually in a fixed file format or has a fixed file name. Therefore, in some embodiments, a file in a preset file format or a preset file name can be read from the source code file of the software project as the code configuration file. Alternatively, the preset file format or the preset file name can be pre-set, and the preset file format and the preset file name can be set simultaneously, or only one of the preset file format and the preset file name can be set.

[0035] As an embodiment, the preset file format can be a preset file suffix name. The source code file with the preset file suffix name can be matched with the file suffix name of the source code file of the software project, and the source code file with the preset file suffix name can be taken as the code configuration file.

[0036] For example, taking python as an example, the file suffix name of the code configuration file is usually cfg, conf or ini. Therefore, the preset file suffix name can be set as cfg, conf or ini. When the source code file with the file suffix name of cfg, conf or ini is matched from the software project, the source code file with the file suffix name of cfg, conf or ini can be taken as the code configuration file of the software project.

[0037] Similarly, taking python as an example, the file name of the code configuration file can be config.py or settings.py. Therefore, the preset file name can be set as config.py or settings.py. When the source code file with the file name of config.py or settings.py is read from the software project, the source code file with the file name of config.py or settings.py can be taken as the code configuration file of the software project.

[0038] It should be noted that if multiple programming languages are used in the same software project, each programming language can correspond to a code configuration file, and thus one or more code configuration files can be read in the same software project.

[0039] Step S220: parsing a file directory where the to-be-verified code is located and a programming language of the to-be-verified code from the code configuration file.

[0040] As an implementation, after the code configuration file is obtained, a file directory where the code configuration file is located can be obtained, and the to-be-verified code can be found by traversing the file directory, so as to find the file directory where the to-be-verified code is located.

[0041] As another implementation, if the file directory where the to-be-verified code is located is configured in the code configuration file, the file directory of the to-be-verified code can be read from the code configuration file.

[0042] Optionally, the programming language of the to-be-verified code can be parsed from the file suffix name of the code configuration file. For example, if the file suffix name of the code configuration file is “.py”, it can be determined that the programming language of the to-be-verified code is python. Optionally, after the file directory where the to-be-verified code is located is parsed, the file suffix name of the to-be-verified file is read from the file directory, and the programming language of the to-be-verified code is parsed from the file suffix name of the to-be-verified file. For example, the file suffix names “.c” and “.h” correspond to the programming language C, “.cpp” corresponds to the programming language C++, “.java” corresponds to the programming language java, “.js” corresponds to the programming language javascript, and the like.

[0043] Step S230: determining a target verification tool and a target verification rule from a pre-set code verification library according to the programming language.

[0044] Since the coding rules and coding specifications of various programming languages are different, different verification tools and verification rules can be used for different programming languages. The verification rule can include the syntax specification of the programming language corresponding to the verification rule and the verification rule predefined for the programming language. The verification rule predefined for the programming language can include a predefined code style. As an example, the target verification tool and the target verification rule can be determined from the pre-set code verification library according to the programming language parsed from the to-be-verified code in the foregoing embodiment. It can be understood that the target verification tool and the target verification rule are both used to verify the to-be-verified code.

[0045] In some embodiments, the plurality of programming languages corresponding to the verification tools and verification rules can be encapsulated in the code verification library in advance, and the verification tools and verification rules corresponding to the programming languages can be stored. Therefore, when verifying the code to be verified, the corresponding target verification tool and target verification rule can be determined according to the programming language of the code to be verified. Optionally, for the convenience of verification and to reduce the verification time, when the code verification library is set, each verification tool in the code verification library can be installed and configured. When verifying the code to be verified, the target verification tool is directly called and the code to be verified in the file directory is verified based on the target verification rule.

[0046] As shown in Figure 3 For example, the code verification library can store the eslint tool and javascript verification rule for verifying javascript files, the stylelint tool and css verification rule for verifying css files, and the pylint tool and python verification rule for verifying python files, and the like. In addition, the programming languages included in the code verification library can include typescript, html, vue, jsx, scss, and the like, and the type of the programming language is not limited by the embodiments of the present application.

[0047] As shown in Figure 4 When the code verification library is set, the verification tools corresponding to each programming language can be installed using the package management manager. Then, when verifying the source files in the actual software project, the source code in each source file in the software project can be taken as the code to be verified, the programming language of the code to be verified can be determined according to the code configuration file in the software project, then the target verification tool and the target verification rule can be determined from the code verification library according to the programming language, the configuration file of the target verification tool can be configured based on the target verification rule, and finally the verification tool can be assembled and the verification rule of the target verification tool can be generated according to the configuration file. Starting verification, running the target verification tool, so that the code to be verified can be verified according to the verification rule of the target verification tool.

[0048] Step S240: verifying the code to be verified in the file directory based on the target verification tool and the target verification rule, and obtaining the verification result of the code to be verified.

[0049] As an embodiment, after the file directory where the code to be verified is located, the coding language, and the target verification tool and the target verification rule are determined, the target verification tool can be called and the code to be verified in the file directory can be verified based on the target verification rule, and the verification result of the code to be verified can be output.

[0050] Optionally, in some embodiments, the target verification rule can be encapsulated into the target verification tool before verification. For example, a configuration file of the target verification tool can be configured based on the target verification rule, and the target verification tool can be run during verification, and the target verification tool can verify the to-be-verified code based on the configuration file, for example, the target verification rule in the configuration file is called and the to-be-verified code in the file directory is verified according to the target verification rule, and the verification result of the to-be-verified code is output after verification.

[0051] As some embodiments, in addition to verifying the to-be-verified code by using the target verification tool, that is, determining whether the writing of the to-be-verified code conforms to the target verification rule, the code in the to-be-verified code that does not conform to the target verification rule can be adjusted based on the verification result and the adjusted to-be-verified code is output. Optionally, there can be some to-be-verified code in the file directory that cannot be adjusted by the target verification tool, at this time, the code statement in the to-be-verified code that does not conform to the target verification rule and cannot be adjusted can be identified by using the target verification tool, and the code statement is output in the verification result to remind the developer to manually correct.

[0052] Wherein, if multiple code configuration files are read for the same software project, and the multiple code configuration files correspond to multiple programming languages, different verification tools and verification rules can be used to verify the to-be-verified code of different programming languages.

[0053] In summary, the code verification method provided by the embodiment first acquires the code configuration file, then parses the file directory where the to-be-verified code is located and the programming language of the to-be-verified code from the code configuration file. Then the target verification tool and the target verification rule are determined from the pre-set code verification library according to the programming language, and then the to-be-verified code in the file directory is verified based on the target verification tool and the target verification rule, and the verification result of the to-be-verified code is obtained. The present application can use separate verification tools and verification rules for different programming languages, even different directory files, and can more flexibly implement the verification of the code file.

[0054] Please refer to Figure 5 which shows a flowchart of a code verification method provided by another embodiment of the present application. The code verification method can specifically include the following steps: Step S510: acquiring a code configuration file.

[0055] Step S520: parsing a file directory where to-be-verified code is located and a programming language of the to-be-verified code from the code configuration file.

[0056] Step S530: determining the target verification tool and the target verification rule from the pre-set code verification library according to the programming language.

[0057] As an implementation, the developer can specify the verification tool to be used in the code configuration file of the code to be verified. Therefore, when determining the target verification tool, the preset verification tool specified in the specified field of the code configuration file can be obtained, and to prevent the developer from configuring errors, it can also be determined whether the preset verification tool matches the programming language of the code to be verified, for example, it can be determined in the code verification library whether the verification tool corresponding to the programming language of the code to be verified is the preset verification tool, and if so, it is matched. If it is matched, the preset verification tool is determined as the target verification tool.

[0058] Specifically, the specific description of steps S510 to S530 can refer to steps S210 to S230 in the foregoing embodiments, which will not be described here.

[0059] After determining the file directory where the code to be verified is located, the coding language, and the target verification tool and the target verification rule, the code to be verified in the file directory can be verified based on the target verification tool and the target verification rule to obtain the verification result of the code to be verified.

[0060] Step S540: determining whether the code configuration file is set with a custom verification rule. If yes, step S550 is performed; if no, step S560 is performed.

[0061] Step S550: verifying the code to be verified in the file directory based on the target verification tool, the custom verification rule, and the target verification rule to obtain the verification result of the code to be verified.

[0062] In the embodiments of the present application, the developer can set the custom verification rule in the code configuration file, therefore, if it is detected that the code configuration file is set with the custom verification rule, the target verification tool can be called and the code to be verified in the file directory can be verified based on the target verification rule and the custom verification rule, and the verification result of the code to be verified is output.

[0063] Similarly to step S240, optionally, before verification, the target verification rule and the custom verification rule can also be encapsulated into the target verification tool. For example, the configuration file of the target verification tool can be configured based on the target verification rule and the custom verification rule, and then the target verification tool is run, so that the target verification tool can verify the code to be verified based on the configuration file and output the verification result. The specific process can refer to step S240, except that the custom verification rule can be used in addition to the target verification rule when verifying.

[0064] Step S560: verifying the to-be-verified code under the file directory based on the target verification tool and the target verification rule to obtain a verification result of the to-be-verified code.

[0065] If it is detected that no custom verification rule is set in the code configuration file, the target verification tool is invoked and the to-be-verified code under the file directory is verified based on the target verification rule, and a verification result of the to-be-verified code is output. Specifically, the specific description of step S560 can be referred to step S240 in the foregoing embodiments, which will not be described here.

[0066] The embodiments of the present application not only allow the developer to specify the verification tool in the code configuration file, but also run the custom verification rule set by the developer in the code configuration file. Therefore, the developer can select the verification tool or set the verification rule as needed to verify the code, which improves the flexibility of code verification.

[0067] In some embodiments, if the custom verification rule is set in the code configuration file, there may be a case that the custom verification rule contradicts the verification method of the target verification rule. Therefore, before verifying the to-be-verified code, it can be determined whether the verification method of the custom verification rule and the target verification rule for the to-be-verified code is the same. Specifically, please refer to Figure 6 FIG. 7 shows a flow diagram of a code verification method according to another embodiment of the present application. Specifically, the code verification method can include the following steps: Step S610: obtaining a code configuration file.

[0068] Step S620: parsing a file directory where the to-be-verified code is located and a programming language of the to-be-verified code from the code configuration file.

[0069] Step S630: determining a target verification tool and a target verification rule from a pre-set code verification library according to the programming language.

[0070] Specifically, the specific description of steps S610 to S630 can be referred to steps S510 to S530 in the foregoing embodiments, which will not be described here.

[0071] Step S640: determining whether a custom verification rule is set in the code configuration file. If yes, step S650 is performed; if no, step S680 is performed.

[0072] Step S650: determining whether the verification method of the custom verification rule and the target verification rule for the to-be-verified code is the same. If no, step S660 is performed.

[0073] In the embodiments of the present application, if it is detected that the custom verification rule is set in the code configuration file, firstly, it can be determined whether the verification methods of the custom verification rule and the target verification rule on the to-be-verified code are the same. If not, it indicates that there is a contradiction between the verification methods of the custom verification rule and the target verification rule, and then it can be determined which verification rule is used to verify the to-be-verified code by comparing the priorities of the custom verification rule and the target verification rule.

[0074] Step S660: determining the verification method with higher priority in the custom verification rule and the target verification rule.

[0075] Step S670: verifying the to-be-verified code based on the target verification tool and the verification method with higher priority to obtain the verification result of the to-be-verified code.

[0076] In some embodiments, the priority of the custom verification rule can be set as higher than the target verification rule by default, or the priority of the custom verification rule can be set as lower than the target verification rule by default, without manually setting the priorities of the verification rules. In other embodiments, a user (for example, a developer) can set the priorities of the custom verification rule and / or the target verification rule according to needs. For example, in response to a user operation, the priority of the verification method of the target verification rule can be set.

[0077] In the present embodiment, the verification method with higher priority in the custom verification rule and the target verification rule can be used. That is, the to-be-verified code can be verified based on the target verification tool and the verification method with higher priority to obtain the verification result of the to-be-verified code.

[0078] As an embodiment, optionally, if the verification methods of the custom verification rule and the target verification rule on the to-be-verified code are the same, the to-be-verified code under the file directory can be verified based on the target verification tool and the target verification rule, or the to-be-verified code under the file directory can be verified based on the target verification tool and the custom verification rule.

[0079] Step S680: verifying the to-be-verified code under the file directory based on the target verification tool and the target verification rule to obtain the verification result of the to-be-verified code.

[0080] If it is detected that the custom verification rule is not set in the code configuration file, the target verification tool is called and the to-be-verified code under the file directory is verified based on the target verification rule, and the verification result of the to-be-verified code is output. Specifically, the specific description of step S680 can refer to step S240 in the foregoing embodiments, which will not be described here.

[0081] When the custom verification rule exists, the embodiment can determine whether the custom verification rule and the target verification rule are consistent in the verification method for the to-be-verified code. If consistent, the verification method with higher priority is used to verify the to-be-verified code. Thus, not only can the verification method of the custom verification rule and the target verification rule be avoided, but also the use order of the custom verification rule and the target verification rule can be adjusted by setting the priority, thereby meeting the needs of the developer.

[0082] Referring to FIG. 7, Figure 7 , a module block diagram of a code verification apparatus provided by an embodiment of the present application is shown. Specifically, the apparatus includes an acquisition module 710, an analysis module 720, a determination module 730, and a verification module 740.

[0083] The acquisition module 710 is configured to acquire a code configuration file. The analysis module 720 is configured to analyze a file directory in which the to-be-verified code is located and a programming language of the to-be-verified code from the code configuration file. The determination module 730 is configured to determine a target verification tool and a target verification rule from a pre-set code verification library according to the programming language. The verification module 740 is configured to verify the to-be-verified code in the file directory based on the target verification tool and the target verification rule, and obtain a verification result of the to-be-verified code.

[0084] In some embodiments, the verification module 740 can optionally include a first verification submodule configured to verify the to-be-verified code in the file directory based on the target verification tool, the custom verification rule, and the target verification rule, if the custom verification rule is set in the code configuration file.

[0085] Further, the first verification submodule can include a priority determination module configured to determine a verification method with higher priority between the custom verification rule and the target verification rule, if the verification methods of the custom verification rule and the target verification rule are different. The first verification submodule can also include a second verification submodule configured to verify the to-be-verified code based on the target verification tool and the verification method with higher priority.

[0086] Still further, the apparatus can also include a priority setting module configured to set a priority for the verification method of the target verification rule in response to a user operation.

[0087] As an implementation, the determining module 730 can include: a first processing module configured to acquire a preset check tool from a designated field of the code configuration file; a tool matching module configured to determine whether the preset check tool matches the programming language; and a second processing module configured to determine the preset check tool as the target check tool if the match is found.

[0088] In some embodiments, the check module 740 can include: a file configuration module configured to configure a configuration file of the target check tool based on the target check rule; and a running module configured to run the target check tool, so that the target check tool checks the code to be checked based on the configuration file.

[0089] Optionally, the apparatus can further include a code adjustment module configured to adjust the code in the code to be checked that does not conform to the target check rule based on the check result, and output the adjusted code to be checked.

[0090] Optionally, the target check rule includes a syntax specification of the programming language and a check rule predefined for the programming language.

[0091] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the modules / units / sub-units / components in the apparatus described above can refer to the corresponding process in the foregoing method embodiments, which will not be described here.

[0092] In several embodiments provided in the present application, the coupling or direct coupling or communication connection between the modules displayed or discussed can be indirect coupling or communication connection between the interfaces, apparatuses or modules, which can be electrical, mechanical or other forms.

[0093] In addition, each functional module in each embodiment of the present application can be integrated in one processing module, or each module can exist physically independently, or two or more modules can be integrated in one module. The integrated module can be realized in the form of hardware or in the form of a software functional module.

[0094] Please refer to Figure 8 which shows a structural block diagram of an electronic device provided in an embodiment of the present application. The electronic device in the embodiment can include one or more of the following components: a processor 810, a memory 820, and one or more application programs, wherein the one or more application programs can be stored in the memory 820 and configured to be executed by the one or more processors 810, and the one or more application programs are configured to perform the method described in the foregoing method embodiments.

[0095] Among others, the electronic device can be any of various types of computer system devices that are mobile, portable, and perform wireless communication. Specifically, the electronic device can be a mobile phone or a smart phone (e.g., iPhone TM, Android TM-based phone), a portable game device (e.g., Nintendo DS TM, PlayStation Portable TM, Gameboy Advance TM, iPhone TM), a laptop computer, a PDA, a portable Internet device, a music player, and a data storage device, other handheld devices, and such as a smart watch, a smart bracelet, a headset, a pendant, etc., and the electronic device can also be other wearable devices (e.g., such as electronic glasses, electronic clothes, electronic bracelet, electronic necklace, electronic tattoo, electronic device, or head-mounted device (HMD)).

[0096] The electronic device can also be any one of a plurality of electronic devices including, but not limited to, a cellular phone, a smart phone, a smart watch, a smart bracelet, other wireless communication device, a personal digital assistant, an audio player, other media player, a music recorder, a video recorder, a camera, other media recorder, a radio, a medical device, a vehicle transportation instrument, a calculator, a programmable remote controller, a pager, a laptop computer, a desktop computer, a printer, a netbook, a personal digital assistant (PDA), a portable multimedia player (PMP), a moving picture experts group (MPEG-1 or MPEG-2) audio layer 3 (MP3) player, a portable medical device, and a digital camera, and combinations thereof.

[0097] In some cases, the electronic device can perform a plurality of functions (e.g., playing music, displaying a video, storing a picture, and receiving and transmitting a phone call). If necessary, the electronic device can be a cellular phone, a media player, other handheld device, a wristwatch device, a pendant device, a headset device, or other compact portable device.

[0098] Alternatively, the electronic device can also be a server, which can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, a cloud server providing cloud service, cloud database, cloud computing, cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, CDN (Content Delivery Network), and basic cloud computing services such as big data and artificial intelligence platform, a specialized or platform server providing face recognition, autonomous driving, industrial internet service, data communication (such as 4G, 5G, etc.), etc.

[0099] The processor 810 can include one or more processing cores. The processor 810 connects various parts within the entire electronic device by running or executing instructions, application programs, code sets or instruction sets stored in the memory 820, and calling data stored in the memory 820, to perform various functions and process data of the electronic device. Alternatively, the processor 810 can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), a programmable logic array (PLA). The processor 810 can integrate a combination of one or several of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes operating systems, user interfaces, and application programs, etc.; the GPU is responsible for rendering and drawing display content; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 810, but can be realized by a separate communication chip.

[0100] The memory 820 can include a random access memory (RAM) and can also include a read-only memory (ROM). The memory 820 can be used to store instructions, application programs, codes, code sets or instruction sets. The memory 820 can include a storage program area and a storage data area, wherein the storage program area can store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing each of the method embodiments described below, etc. The storage data area can also store data created by the electronic device in use (such as a phone book, audio and video data, chat record data, etc.).

[0101] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the processor 810 and the memory 820 of the electronic device described above can refer to the corresponding processes in the foregoing method embodiments, which will not be described here.

[0102] Please refer to Figure 9 which shows a structural block diagram of a computer readable storage medium provided by an embodiment of the present application. The computer readable storage medium 900 stores program codes, which can be called and executed by a processor to perform the methods described in the foregoing method embodiments.

[0103] The computer-readable storage medium 900 can be an electronic, magnetic, optical, or other storage device capable of providing a processing unit with non-transitory storage of computer- readable instructions such as a floppy disk, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM (Electrically Programmable Read-Only Memory), hard disk, or ROM (Read-Only Memory). Optionally, the computer-readable storage medium 900 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 900 has a storage space for program codes 910 to perform any of the method steps of the above methods. These program codes can be read from or written to one or more computer program products. The program codes 910 can be compressed in an appropriate form, for example. The computer-readable storage medium 900 can be, for example, a ROM (Read-Only Memory), a RAM (Random Access Memory), an SSD, an EEPROM (Electrically Erasable Programmable Read-Only Memory), or a Flash memory.

[0104] Reference is made to Figure 10 which shows a computer program product 1000 provided by an embodiment of the present application, including computer programs / instructions 1010, which, when executed by a processor, implement the above method.

[0105] It should be noted that, in this document, the terms "comprising", "including", or any other variant thereof are intended to cover a non-exclusive inclusion, so that a process, method, article, or apparatus that includes a list of elements not only includes those elements, but also includes other elements not expressly listed or inherent to such process, method, article, or apparatus. Without more limitations, an element defined by the statement "including a" does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.

[0106] Through the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiments can be realized by means of software and the necessary general hardware platform, and of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product in essence or in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium (such as ROM / RAM, SSD, Flash), and includes a plurality of instructions for causing a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method of each embodiment of the present application.

[0107] The code verification method and device, the electronic device, and the storage medium provided in the present application first acquire a code configuration file, then parse a file directory where the code to be verified is located and a programming language of the code to be verified from the code configuration file. Then, the target verification tool and the target verification rule are determined from the pre-set code verification library according to the programming language, and then the code to be verified under the file directory is verified based on the target verification tool and the target verification rule to obtain the verification result of the code to be verified. The present application can use separate verification tools and verification rules for different programming languages and even different directory files, and can more flexibly realize the verification of the code file.

[0108] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not drive the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A code verification method, characterized in that, The method includes: Get the code configuration file; The file directory containing the code to be verified and the programming language of the code to be verified are parsed from the code configuration file. The target verification tool and target verification rules are determined from a pre-set code verification library based on the programming language. The target verification tool and the target verification rules are used to verify the code to be verified in the file directory to obtain the verification result of the code to be verified.

2. The method according to claim 1, characterized in that, The verification of the code to be verified in the file directory based on the target verification tool and the target verification rules includes: If the code configuration file contains custom verification rules, the code to be verified in the file directory is verified based on the target verification tool, the custom verification rules, and the target verification rules.

3. The method according to claim 2, characterized in that, The verification of the code to be verified in the file directory based on the target verification tool, the custom verification rules, and the target verification rules includes: If the custom verification rule and the target verification rule have different verification methods for the code to be verified, determine the verification method with higher priority between the custom verification rule and the target verification rule; The code to be verified is verified based on the target verification tool and the higher-priority verification method.

4. The method according to claim 1, characterized in that, The step of determining the target verification tool from a pre-set code verification library according to the programming language includes: Retrieve the pre-specified preset verification tool from the specified field in the code configuration file; Determine whether the preset verification tool is compatible with the programming language; If a match is found, the preset verification tool will be identified as the target verification tool.

5. The method according to claim 1, characterized in that, The verification of the code to be verified in the file directory based on the target verification tool and the target verification rules includes: Configure the target verification tool's configuration file based on the target verification rules; Run the target verification tool so that it verifies the code to be verified based on the configuration file.

6. The method according to claim 1, characterized in that, After verifying the code to be verified in the file directory based on the target verification tool and the target verification rules to obtain the verification result of the code to be verified, the method further includes: Based on the verification results, the code in the code to be verified that does not conform to the target verification rule is adjusted, and the adjusted code to be verified is output.

7. A code verification device, characterized in that, The device includes: The retrieval module is used to retrieve code configuration files; The parsing module is used to parse the file directory where the code to be verified is located and the programming language of the code to be verified from the code configuration file; The determination module is used to determine the target verification tool and target verification rules from a pre-set code verification library according to the programming language; The verification module is used to verify the code to be verified in the file directory based on the target verification tool and the target verification rules, and to obtain the verification result of the code to be verified.

8. An electronic device, characterized in that, include: One or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs being configured to perform the method as described in any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program code that can be invoked by a processor to execute the method as described in any one of claims 1-6.

10. A computer program product containing instructions, characterized in that, The computer program product stores instructions that, when run on a computer, cause the computer to perform the method as described in any one of claims 1-6.