Code style checking method, device and system, electronic equipment and storage medium
By presetting the code style check configuration files in the code repository and using the commit hook function, combined with the collaborative inspection of the user terminal and the server, the problem of inconsistent code styles of team members is solved, and the unified and flexible inspection of code styles is achieved, ensuring the uniformity of code quality.
Patent Information
- Application Number
- CN202510566338.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-15
AI Technical Summary
In software development, team members have inconsistent understanding of code style, which makes it difficult to unify the code style, and it is difficult to ensure the uniformity of code style when checking existing tools.
By presetting code style check configuration files in the code repository and executing code style check commands in the code repository jointly maintained by the user terminal and the server, ensuring that all code submitted by members triggers the same check when the same code repository, including compiling and using the commit hook function to trigger the check before committing, the server checks the added code again to prevent bypassing.
It realizes the unified code style submitted by different members, improves the flexibility and consistency of code style checking in the code repository, and ensures the consistency of code quality and the consistent code style after merge.
Smart Images

Figure CN120492305A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computers, and in particular to a code style checking method, device, system, electronic device, and storage medium. Background Art
[0002] Software development requires a good coding style, such as indentation of different code levels, statement alignment, and reasonable statement length. It is also necessary to ensure code quality, such as correct spelling, proper use of local and global variables, and proper memory allocation and release.
[0003] In real-world development, it's difficult to unify coding styles. Team members often have different understandings of coding styles, making it difficult to integrate different team members' requirements. Even if software developers check code styles manually or with the help of various tools before submitting code, there's no guarantee that the code styles submitted by different team members will be consistent. Summary of the Invention
[0004] The present application provides a code style checking method, device, system, electronic device and storage medium to ensure that the code style of codes submitted by different members is unified.
[0005] In a first aspect, the present application provides a code style checking method, which is applied to any user terminal in a code development system, the code development system also including a server, and all the user terminals and the server jointly maintain at least one code repository, the method including: in response to a submission instruction of a target code to a target code repository, executing a code style checking command in a code style checking configuration file preset in the target code repository, checking the target code, and obtaining a first checking result; if the first checking result indicates failure, returning the submitted target code; if the first checking result indicates success, storing the target code in the target code repository, so that when the server detects that a new target code has been added to the target code repository, it executes the code style checking command in the code style checking configuration file preset in the target code repository, checking the target code, and obtaining a second checking result; if the second checking result indicates failure, deleting the newly added target code; if the second checking result indicates success, retaining the newly added target code.
[0006] In the embodiment of the present application, since a code style check configuration file is preset in the code repository, and the code repository is jointly maintained by the user terminal and the server, when the user terminal that has deployed the same code repository responds to the submission instruction and executes the code style detection command in the code style check configuration file to check the submitted target code, the code style check configuration file obtained is the same. Therefore, when different members submit code to the same code repository, the same code style check command is triggered, so that the code style of the codes submitted by different members is unified. In addition, after the first check result is characterized as passed, the server will again use the code style check configuration file preset in the code repository to check the newly added target code to prevent the code style check performed locally on the user terminal from being bypassed, and further ensure the code style of the codes submitted by different members is unified.
[0007] In combination with the technical solution provided in the first aspect above, in some possible implementations, the target code repository includes a submission hook function, which is used to trigger the code style check command in the preset code style check configuration file in the target code repository when a submission instruction to submit code to the target code repository is detected.
[0008] In combination with the technical solution provided in the first aspect above, in some possible implementations, in response to a submission instruction of the target code being submitted to the target code repository, before executing the code style check command in the code style check configuration file preset in the target code repository, the method also includes: compiling the target code in response to a compilation instruction of the target code; detecting whether there is a submission hook function in all local code repositories; if there is a designated code repository where the submission hook function does not exist, storing the submission hook function to a preset location in the designated code repository.
[0009] In an embodiment of the present application, the submission hook function is stored in a preset location in the specified code repository, thereby ensuring that when the code is submitted, the code style check command in the preset code style check configuration file in the target code repository can be triggered.
[0010] In combination with the technical solution provided in the first aspect above, in some possible implementations, the code style check commands included in the code style check configuration files in different code repositories are not completely the same.
[0011] In an embodiment of the present application, the code style check configuration files in different code repositories include different code style check commands, so that different code repositories can apply different code styles, thereby improving the flexibility of this solution.
[0012] In combination with the technical solution provided in the first aspect above, in some possible implementations, the code repository also includes a check object file, which is used to record the target file path, and the code stored under the target file path needs to be checked for code style using the code style check configuration file; before executing the code style check command in the code style check configuration file preset in the target code repository, the method also includes: determining that the storage path record of the target code in the target code repository is recorded in the check object file.
[0013] In an embodiment of the present application, since in actual applications, not all codes in the same code repository necessarily need to be checked for code style, this solution limits the codes in the code repository that need to be checked for code style by checking object files, so that only the codes that need to be checked can be checked, thereby improving the flexibility of this solution.
[0014] In combination with the technical solution provided in the first aspect above, in some possible implementations, the code style check configuration file also includes a mark corresponding to each code style check command; the mark indicates that it needs to be executed or that it does not need to be executed; executing the code style check commands in the code style check configuration file preset in the target code repository includes: executing all code style check commands in the code style check configuration file preset in the target code repository that are marked as indicating that they need to be executed.
[0015] In an embodiment of the present application, since the requirements for code style may change in actual applications, by setting a mark corresponding to each code style check command in the code style check configuration file, the code style check command to be executed can be changed by changing the mark, thereby making this solution more flexible.
[0016] In a second aspect, the present application provides a code style checking method, which is applied to a server in a code development system, wherein the code development system also includes at least one user terminal, and all of the user terminals and the server jointly maintain at least one code repository, and the method includes: when it is detected that a new target code is added to the target code repository, executing a code style checking command in a code style checking configuration file preset in the target code repository, checking the target code, and obtaining a second checking result; wherein, in response to a submission instruction for the target code to be submitted to the target code repository, the user terminal executes a code style checking command in a code style checking configuration file preset in the target code repository, checking the target code, and when the first checking result obtained indicates a pass, the target code is stored in the target code repository; if the second checking result indicates a fail, the newly added target code is deleted; if the second checking result indicates a pass, the newly added target code is retained.
[0017] In an embodiment of the present application, after the first check result characterization is passed, when the server detects that a new target code has been added to the target code repository, it will use the code style check configuration file preset in the code repository to check the newly added target code to prevent the code style check performed locally on the user terminal from being bypassed, and further ensure that the code styles of the codes submitted by different members are unified. At the same time, since a code style check configuration file is preset in the code repository, and the code repository is jointly maintained by the user terminal and the server, when the user terminal deployed with the same code repository responds to the submission instruction and executes the code style detection command in the code style check configuration file to check the submitted target code, the code style check configuration file obtained is the same. Therefore, when different members submit code to the same code repository, and when the server performs a code style check, the same code style check command is triggered, so that the code styles of the codes submitted by different members are unified.
[0018] In combination with the technical solution provided in the second aspect above, in some possible implementations, after at least two codes in the target code repository are merged, the method further includes: executing the code style check command in the code style check configuration file preset in the target code repository, checking the merged code, and obtaining a third check result; if the third check result indicates failure, the target code repository is rolled back to the state before the merge.
[0019] In an embodiment of the present application, after the codes are merged, the merged codes are checked using a code style check configuration file preset in the code repository, thereby ensuring that the code style of the merged codes is unified.
[0020] In a third aspect, the present application provides a code style checking method, which is applied to a code development system, wherein the code development system includes a server and at least one user terminal, and all of the user terminals and the server jointly maintain at least one code repository, and the method includes: in response to a submission instruction of a target code to a target code repository, the user terminal executes a code style checking command in a code style checking configuration file preset in the target code repository, checks the target code, and obtains a first inspection result; if the first inspection result indicates failure, the user terminal returns the submitted target code; if the first inspection result indicates success, the target code is stored in the target code repository; when the server detects that a new target code has been added to the target code repository, the server executes a code style checking command in a code style checking configuration file preset in the target code repository, checks the target code, and obtains a second inspection result; if the second inspection result indicates failure, the server deletes the newly added target code; if the second inspection result indicates success, the server retains the newly added target code.
[0021] In a fourth aspect, the present application provides a code style checking device, which is deployed on any user terminal in a code development system, the code development system also including a server, and all the user terminals and the server jointly maintain at least one code repository. The device includes: a response module and a first processing module, the response module being configured to, in response to a submission instruction for a target code to be submitted to a target code repository, execute a code style checking command in a code style checking configuration file preset in the target code repository, check the target code, and obtain a first check result; the first processing module being configured to, if the first check result indicates a failure, return the submitted target code; the first processing module being further configured to, if the first check result indicates a passing, store the target code in the target code repository, so that when the server detects that new target code has been added to the target code repository, it executes the code style checking command in the code style checking configuration file preset in the target code repository, checks the target code, and obtains a second check result; if the second check result indicates a failure, deletes the newly added target code; if the second check result indicates a passing, retains the newly added target code; wherein the user terminal and the server jointly maintain at least one code repository.
[0022] In a fifth aspect, the present application provides a code style checking device, which is deployed on a server in a code development system, wherein the code development system also includes at least one user terminal, and all of the user terminals and the server jointly maintain at least one code repository, and the device includes: a detection module and a second processing module, wherein the detection module is used to execute a code style checking command in a code style checking configuration file preset in the target code repository when detecting that a new target code has been added to the target code repository, check the target code, and obtain a second inspection result; wherein, in response to a submission instruction of the target code being submitted to the target code repository, the user terminal executes a code style checking command in a code style checking configuration file preset in the target code repository, checks the target code, and if the first inspection result obtained indicates a pass, the target code is stored in the target code repository; the second processing module is used to delete the newly added target code if the second inspection result indicates a fail; and the second processing module is also used to retain the newly added target code if the second inspection result indicates a pass.
[0023] In a sixth aspect, the present application provides a code development system, comprising: at least one user terminal deployed with the code style checking device described in the third aspect above, and a server deployed with the code style checking device described in the fourth aspect above, all of the user terminals and the servers jointly maintain at least one code repository.
[0024] In the seventh aspect, the present application provides an electronic device, comprising: a memory and a processor, the memory and the processor being connected; the memory being used to store programs; the processor being used to call the programs stored in the memory to execute the method described in the first aspect above and / or in combination with any possible implementation of the first aspect above, or to execute the method described in the second aspect above and / or in combination with any possible implementation of the second aspect above.
[0025] In an eighth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is run by a computer, it executes the method described in the first aspect above and / or in combination with any possible implementation of the first aspect above, or executes the method described in the second aspect above and / or in combination with any possible implementation of the second aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0027] Figure 1 This is a flow chart of the first code style checking method shown in an embodiment of the present application;
[0028] Figure 2 This is a flow chart of a second code style checking method according to an embodiment of the present application;
[0029] Figure 3 This is a flow chart of a third code style checking method according to an embodiment of the present application;
[0030] Figure 4 This is a structural block diagram of a first code style checking device shown in an embodiment of the present application;
[0031] Figure 5 This is a structural block diagram of a second code style checking device shown in an embodiment of the present application;
[0032] Figure 6 This is a structural block diagram of a code development system shown in an embodiment of the present application;
[0033] Figure 7 This is a structural block diagram of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0034] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0035] It should be noted that similar numbers and letters represent similar items in the following figures, so once an item is defined in one figure, it does not need to be further defined and explained in the subsequent figures. At the same time, in the description of this application, relational terms such as "first", "second", etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also includes other elements that are not clearly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the sentence "comprise a..." do not exclude the presence of other identical elements in the process, method, article or equipment including the elements.
[0036] The technical solution of this application will be described in detail below with reference to the accompanying drawings.
[0037] See also Figure 1 , Figure 1 This is a flow chart of a code style checking method shown in an embodiment of the present application. The code style checking method is applied to any user terminal in a code development system. The code development system also includes a server. All user terminals and servers jointly maintain at least one code repository. Figure 1 Describe the steps it involves.
[0038] S110: In response to a submission instruction of the target code to the target code repository, executing a code style check command in a code style check configuration file preset in the target code repository, checking the target code, and obtaining a first check result.
[0039] The submission instruction for submitting the target code to the target code repository can be a submission instruction generated by a user clicking a submit button or other operations, or it can also be a submission instruction generated by other means, as long as the submission instruction represents submitting a piece of code to the target code repository.
[0040] In one embodiment, the code style check configuration file can be implemented in a manner such as "repos:
[0041]
[0042]
[0043] Each id is a check item, and the following entry is the code style check command corresponding to the check item. A return value of 0 indicates a successful check, while a non-zero value indicates a failure. For example, trailing-whitespace-ext checks for spaces after each line of code, shebang checks for executable permissions for C / C++, clang-format checks C / C++ code style, codespell checks for spelling errors, and cppcheck performs static code checking. The code style check configuration file includes more code style check commands than those listed here.
[0044] Alternatively, you can obtain code style check commands from the open source community. Alternatively, you can modify code style check commands obtained from the open source community to obtain the required code style check commands. You can also create your own code style check commands, such as code license checks.
[0045] For ease of understanding, taking clang-format (which checks the C / C++ code style) as an example, you can have a customized configuration, that is, the repo manifest puts .clang-format in the root directory. Specifically:
[0046]
[0047] clang-format will search for the first .clang-format file in the current directory as a check rule. The kernel (programming kernel) often uses a different coding style, so a new configuration can be customized for the kernel code repository and automatically point to that rule. That is:
[0048]
[0049] Git is a widely used code repository. Code can be hosted on Gerrit, Gitlab, or Github servers.
[0050] In one embodiment, the target code repository may include a commit hook function, which is used to trigger a code style check command in a preset code style check configuration file in the target code repository when a commit instruction to submit code to the target code repository is detected.
[0051] Because code repositories support numerous hooks that can be triggered at various stages of code management, code style checks must be completed after the code is submitted, but before a commit (a commit is the process of permanently saving changes to code or files in the version control system) occurs. This can be managed using a pre-commit hook.
[0052] Optionally, the commit hook function can be set in the .git / hook directory of the code repository.
[0053] Optionally, before executing the code style check commands in the code style check configuration file preset in the target code repository in response to a submit instruction for submitting the target code to the target code repository, the target code may be compiled in response to a compile instruction for the target code. Furthermore, a check is performed to determine whether a commit hook function exists in all local code repositories. If a designated code repository does not have a commit hook function, the commit hook function is stored in a preset location in the designated code repository.
[0054] The commit hook function is stored in a preset location in the specified code repository, ensuring that when the code is submitted, the code style check command in the preset code style check configuration file in the target code repository can be triggered.
[0055] Optionally, to implement the aforementioned function of detecting whether a commit hook function exists in all local code repositories during compilation, a script can be added during compilation. Specifically, the compilation instructions of the target code will trigger the script to run, detecting whether a commit hook function exists in all local code repositories. If a specified code repository does not have a commit hook function, the commit hook function is stored in a preset location in the specified code repository.
[0056] The script can be
[0057]
[0058] Therefore, after a compilation is performed locally on the user terminal, the submission hook function will be stored in all code repositories.
[0059] Optionally, if the code style check configuration file does not exist in the code repository, the code style check will not be performed on the submitted target code.
[0060] The code style check configuration file can be a .hook_opt file. If the .hook_opt file exists in the repository directory of the code repository, code style checking does not need to be performed on the code submitted to the code repository. The implementation of the code style check configuration file is not limited to the example shown here.
[0061] In one embodiment, the code repository also includes a check object file, which is used to record the target file path. The code stored under the target file path needs to be checked for code style using a code style check configuration file; before executing the code style check command in the preset code style check configuration file in the target code repository, it can also be determined that the storage path record of the target code in the target code repository is recorded in the check object file.
[0062] In actual applications, not all codes in the same code repository need to be checked for code style. This solution limits the codes in the code repository that need to be checked for code style by checking object files, so that only the codes that need to be checked can be checked, which improves the flexibility of this solution.
[0063] For ease of understanding, taking the example of the file path A / B / C recorded in the check target file, it means that all codes with storage paths including A / B / C need to be checked, that is, all codes stored in folder C need to be checked. For example, if the storage path of the target code in the code repository is A / B / C / D, the code style check command in the preset code style check configuration file in the target code repository will be executed to perform code style check on the target code.
[0064] If the storage path of the target code in the code repository is A / B, there is no need to execute the code style check command in the preset code style check configuration file in the target code repository to perform code style check on the target code.
[0065] The examples here are only for ease of understanding and should not be construed as limiting this application.
[0066] In one embodiment, the code style check configuration file further includes a flag corresponding to each code style check command, the flag indicating that execution is required or that execution is not required. A specific method for executing the code style check commands in the code style check configuration file preset in the target code repository may be to execute all code style check commands marked as requiring execution in the code style check configuration file preset in the target code repository.
[0067] Since the requirements for code style may change in actual applications, by setting the tag corresponding to each code style check command in the code style check configuration file, the code style check command to be executed can be changed by changing the tag, making this solution more flexible.
[0068] Among them, the specific type of the mark can be set according to actual needs. For example, the mark can be set to HOOK and SKIP. Then, when the mark of the code style check command check1 is HOOK and the mark of the code style check command check2 is SKIP, it is confirmed that the code style check command check1 will be executed, and the code style check command check2 will not be executed.
[0069] The examples here are only for ease of understanding. The specific implementation method of the marking can be set according to actual needs and is not limited to the method shown here.
[0070] In one implementation, each code style check command in the code style check configuration file may also be configured.
[0071] For example, for a code style checking command used for spell checking, it can be set to ignore certain special nouns, such as codespell_ignore=cros, that is, ignore the noun cros.
[0072] For clang_format, you can set whether it is the kernel code style, for example, clang_format=kernel.
[0073] The examples here are only for ease of understanding. The configuration methods of the code style check command are not limited to the methods shown here.
[0074] In one embodiment, the code style check configuration files in different code repositories may include different code style check commands. In other words, the code style check instructions to be executed in different code repositories may be different, thereby achieving personalized settings for the code style.
[0075] S120: If the first check result indicates failure, the submitted target code is returned.
[0076] The first check result may include the result returned by each executed code style check instruction. If any code style check instruction returns a result indicating a failure, the first check result indicates a failure. Therefore, the target code is returned for modification.
[0077] If the result returned by each code style check instruction included in the first check result indicates a pass, then the first check result indicates a pass.
[0078] S130: If the first check result indicates passing, the target code is stored in the target code repository.
[0079] When the server detects that a new target code has been added to the target code repository, it executes the code style check command in the preset code style check configuration file in the target code repository to check the target code and obtain a second check result; if the second check result indicates that it fails, the newly added target code will be deleted; if the second check result indicates that it passes, the newly added target code will be retained.
[0080] For ease of understanding, if the first check result of the submitted target code is:
[0081] $ git commit -m update
[0082] worktree check................................................Passed
[0083] trailing whitespace........................................Passed
[0084] forbid-crlf........................................Passed
[0085] forbid-intermediate................................Passed
[0086] check shebang and executable attribute........................Passed
[0087] fix end of files........................................Passed
[0088] shell format........................................Passed
[0089] clang-format for c,c++....................................Passed
[0090] clang-format for java..........................................Passed
[0091] code spell...................................................Passed
[0092] autopep8.....................................................Skipped
[0093] yapf....................................................Skipped
[0094] ruff.........................................................Skipped
[0095] license check...............................................Passed
[0096] black.......................................................Skipped
[0097] check for merge conflicts...................................Passed
[0098] [detached HEAD c9a6c63f]test
[0099] 1file changed,0insertions(+),0deletions(-)
[0100] create mode 100644test
[0101] Since there are no failed code style check instructions in the first check result, the target code is stored in the target code repository.
[0102] If the first check result is:
[0103] git commit -m test
[0104] worktree check................................................Passed
[0105] trailing whitespace........................................Failed
[0106] -hook id:trailing-whitespace-ext
[0107] -exit code:1
[0108] -files were modified by this hook
[0109] forbid-crlf........................................Passed
[0110] forbid-intermediate........................Passed
[0111] check shebang and executable attribute........................Passed
[0112] fix end of files........................Failed
[0113] -hook id:end-of-file-fixer-ext
[0114] -exit code:1
[0115] -files were modified by this hook
[0116] shell format........................................Passed
[0117] Since the result corresponding to the code style check instruction is failed, the first check result indicates failure, and the submitted target code is returned.
[0118] Based on the same technical concept, the present application also provides a code style checking method, which is applied to a server in a code development system. The code development system also includes at least one user terminal. All user terminals and servers jointly maintain at least one code repository. Figure 2 Describe the steps it involves.
[0119] S210: When it is detected that a new target code is added to the target code repository, a code style check command in a code style check configuration file preset in the target code repository is executed to check the target code and obtain a second check result.
[0120] In which, when the user terminal responds to the submission instruction of the target code to the target code repository, the code style check command in the code style check configuration file preset in the target code repository is executed to check the target code. If the first check result obtained indicates that it passes, the target code is stored in the target code repository.
[0121] The code style checking method executed by the user terminal has been clearly described above and will not be repeated here for the sake of brevity.
[0122] The code repository, code style check configuration file, and implementation of the code style check command have been clearly described in the previous article. For the sake of brevity, they will not be repeated here.
[0123] The specific method of executing the code style check command in the preset code style check configuration file in the target code repository to check the target code and obtain the second check result is the same as the specific method of executing the code style check command in the preset code style check configuration file in the target code repository to check the target code and obtain the first check result in the previous article. For the sake of brief description, it will not be repeated here.
[0124] S220: If the second check result indicates failure, the newly added target code is deleted.
[0125] The second check result may include the result returned by each executed code style check instruction. If any code style check instruction returns a result indicating failure, the second check result indicates failure. Therefore, the target code is returned for modification.
[0126] If the result returned by each code style check instruction included in the second check result indicates a pass, then the second check result indicates a pass.
[0127] S230: If the second check result indicates passing, retain the newly added target code.
[0128] In one implementation, after at least two codes in the target code repository are merged, a code style check command in a preset code style check configuration file in the target code repository may be executed to check the merged code and obtain a third check result.
[0129] If the third check result indicates a failure, the target code repository is rolled back to the state before the merge.
[0130] If the third check result indicates passing, the merged code is retained.
[0131] The specific method of executing the code style check command in the preset code style check configuration file in the target code repository to check the target code and obtain the third check result is the same as the specific method of executing the code style check command in the preset code style check configuration file in the target code repository to check the target code and obtain the first check result in the previous article. For the sake of brief description, it will not be repeated here.
[0132] To facilitate understanding of the connection between the code style checking methods executed by the client terminal and the server, an example is given below.
[0133] In response to a submission instruction for submitting the target code to the target code repository, the client terminal executes a code style check command in a code style check configuration file preset in the target code repository, checks the target code, and obtains a first check result.
[0134] If the first check result indicates that the code fails, the submitted target code will be returned.
[0135] If the first check result indicates a passing result, the target code is stored in the target code repository. Since the user terminal and the server jointly maintain at least one code repository, once the target code submitted by the user terminal is stored in the target code repository, the server detects that the target code has been newly added to the target code repository. Therefore, the server executes the code style check command in the code style check configuration file preset in the target code repository to check the target code and obtain a second check result.
[0136] If the second check result indicates that the target code fails, the newly added target code will be deleted.
[0137] If the second check result indicates passing, the newly added target code is retained.
[0138] If at least two codes in the target code repository are merged, the server executes a code style check command in a code style check configuration file preset in the target code repository, checks the merged code, and obtains a third check result.
[0139] If the third check result indicates a failure, the target code repository is rolled back to the state before the merge.
[0140] If the third check result indicates passing, the merged code is retained.
[0141] Based on the same technical concept, this application also provides a code style checking method, such as Figure 3 As shown, the code checking method is applied to a code development system, which includes a server and at least one user terminal. All user terminals and the server jointly maintain at least one code repository.
[0142] In response to a submission instruction for submitting the target code to the target code repository, the user terminal executes a code style check command in a code style check configuration file preset in the target code repository, checks the target code, and obtains a first check result.
[0143] If the first check result indicates that the code fails, the user terminal returns the submitted target code.
[0144] If the first check result indicates that the target code passes, the target code is stored in the target code repository.
[0145] When detecting that a new target code is added to the target code repository, the server executes a code style check command in a code style check configuration file preset in the target code repository to check the target code and obtain a second check result.
[0146] If the second check result indicates that the target code fails, the server deletes the newly added target code.
[0147] If the second check result indicates passing, the server retains the newly added target code.
[0148] Figure 3 The specific implementation methods and principles of each step shown have been clearly described in the previous text and will not be repeated here for the sake of brevity.
[0149] In one implementation, after at least two codes in the target code repository are merged, the server executes a code style check command in a preset code style check configuration file in the target code repository, checks the merged code, and obtains a third check result.
[0150] If the third check result indicates a failure, the target code repository is rolled back to the state before the merge.
[0151] If the third check result indicates passing, the merged code is retained.
[0152] Based on the same technical concept, the present application also provides a code style checking device, which is deployed on any user terminal in a code development system. The code development system also includes a server, and all the user terminals and the server jointly maintain at least one code repository.
[0153] like Figure 4 As shown, the code style checking apparatus 100 includes a response module 110 and a first processing module 120 .
[0154] The response module 110 is configured to execute a code style check command in a preset code style check configuration file in the target code repository in response to a submission instruction of the target code to the target code repository, check the target code, and obtain a first check result.
[0155] The first processing module 120 is configured to return the submitted target code if the first inspection result indicates failure.
[0156] The first processing module 120 is also used to store the target code in the target code repository if the first inspection result is characterized as passed, so that when the server detects that a new target code has been added to the target code repository, it executes the code style check command in the preset code style check configuration file in the target code repository to check the target code and obtain a second inspection result; if the second inspection result is characterized as failed, the newly added target code is deleted; if the second inspection result is passed, the newly added target code is retained; wherein, the user terminal and the server jointly maintain at least one code repository.
[0157] In one embodiment, the target code repository includes a commit hook function, which is used to trigger a code style check command in a preset code style check configuration file in the target code repository when a commit instruction to submit code to the target code repository is detected.
[0158] In response to a submission instruction of the target code being submitted to the target code repository, before executing the code style check command in the code style check configuration file preset in the target code repository, the response module 110 is also used to compile the target code in response to the compilation instruction of the target code; detect whether there is a submission hook function in all local code repositories; if there is a designated code repository where the submission hook function does not exist, store the submission hook function to a preset location in the designated code repository.
[0159] In one implementation, the code style check configuration files in different code repositories include different code style check commands.
[0160] The code repository also includes a check object file, which is used to record the target file path. The code stored under the target file path needs to be checked for code style using the code style check configuration file; before executing the code style check command in the code style check configuration file preset in the target code repository, the first processing module 120 is also used to determine whether the storage path record of the target code in the target code repository is recorded in the check object file.
[0161] The code style check configuration file also includes a mark corresponding to each code style check command; the mark indicates that it needs to be executed or that it does not need to be executed; the response module 110 is specifically used to execute all code style check commands marked as needing to be executed in the preset code style check configuration file in the target code repository.
[0162] The code style checking device 100 provided in the embodiment of the present application has the same implementation principle and technical effects as those of the aforementioned code style checking method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding content in the aforementioned code style checking method embodiment.
[0163] Based on the same technical concept, the present application also provides a code style checking device, which is deployed on a server in a code development system. The code development system also includes at least one user terminal, and all of the user terminals and the server jointly maintain at least one code repository.
[0164] like Figure 5 As shown, the code style checking apparatus 200 includes a detection module 210 and a second processing module 220 .
[0165] The detection module 210 is configured to, upon detecting that a target code has been newly added to the target code repository, execute a code style check command in a code style check configuration file preset in the target code repository to check the target code and obtain a second check result. The user terminal, in response to a submission instruction for submitting the target code to the target code repository, executes a code style check command in a code style check configuration file preset in the target code repository to check the target code. If the first check result indicates a passing result, the target code is stored in the target code repository.
[0166] A second processing module 220 is configured to delete the newly added target code if the second inspection result indicates failure;
[0167] The second processing module 220 is further configured to retain the newly added target code if the second inspection result indicates passing.
[0168] After at least two codes in the target code repository are merged, the detection module 210 is further configured to execute a code style check command in the code style check configuration file preset in the target code repository, check the merged code, and obtain a third check result;
[0169] The second processing module 220 is further configured to roll back the target code repository to a state before merging if the third check result indicates failure.
[0170] The code style checking device 200 provided in the embodiment of the present application has the same implementation principle and technical effects as those of the aforementioned code style checking method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding content in the aforementioned code style checking method embodiment.
[0171] Based on the same technical concept, this application also provides a code development system, such as Figure 6 As shown, the code development system 10 includes at least one user terminal 20 and a server 30 .
[0172] The server 30 is equipped with the aforementioned code style checking device, and the user terminal 20 is equipped with the aforementioned code style checking device. All user terminals 20 and the server 30 jointly maintain at least one code repository. Each user terminal 20 is connected to the server 30.
[0173] See also Figure 7 , which is an electronic device 300 provided in an embodiment of the present application. The electronic device 300 includes: a processor 310 and a memory 320.
[0174] The memory 320 and the processor 310 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The memory 320 is used to store computer programs, such as Figure 4 or Figure 5 The software functional modules shown in the figure are the coding style checking device 100 or the coding style checking device 200. The coding style checking device 100 includes at least one software functional module that can be stored in the memory 320 in the form of software or firmware or fixed in the operating system (OS) of the electronic device 300. The processor 310 is used to execute the executable modules stored in the memory 320, such as the software functional modules or computer programs included in the coding style checking device 100. At this time, the processor 310 is used to respond to the submission instruction of the target code to the target code repository, execute the code style check command in the code style check configuration file preset in the target code repository, check the target code, and obtain a first inspection result; if the first inspection result indicates that it fails, return the submitted target code; if the first inspection result indicates that it passes, store the target code in the target code repository, so that when the server detects that new target code has been added to the target code repository, it executes the code style check command in the code style check configuration file preset in the target code repository, checks the target code, and obtains a second inspection result; if the second inspection result indicates that it fails, deletes the newly added target code; if the second inspection result indicates that it passes, retains the newly added target code.
[0175] The code style checking device 200 includes at least one software function module that can be stored in the memory 320 in the form of software or firmware or fixed in the operating system (OS) of the electronic device 300. The processor 310 is used to execute the executable module stored in the memory 320, such as the software function module or computer program included in the code style checking device 200. At this time, the processor 310 is used to execute the code style checking command in the code style checking configuration file preset in the target code repository when detecting that the target code is newly added to the target code repository, check the target code, and obtain a second check result; wherein, in response to the submission instruction of the target code to the target code repository, the user terminal executes the code style checking command in the code style checking configuration file preset in the target code repository and checks the target code. If the first check result indicates that the target code passes, the target code is stored in the target code repository; if the second check result indicates that the target code fails, the newly added target code is deleted; if the second check result indicates that the target code passes, the newly added target code is retained.
[0176] Among them, the memory 320 can be, but is not limited to, RAM (Random Access Memory), ROM (Read Only Memory), PROM (Programmable Read-Only Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electric Erasable Programmable Read-Only Memory), etc.
[0177] The processor 310 may be an integrated circuit chip with signal processing capabilities. The above-mentioned processor may be a general-purpose processor, including a CPU (Central Processing Unit), an NP (Network Processor), etc.; it may also be a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor, or the processor 310 may also be any conventional processor, etc.
[0178] The electronic device 300 mentioned above includes but is not limited to a personal computer, a server, etc.
[0179] The present application also provides a non-volatile computer-readable storage medium (hereinafter referred to as storage medium) having a computer program stored thereon. When the computer program is executed by a computer, such as the electronic device 300 described above, the computer-readable storage medium executes the code style checking method described above. The computer-readable storage medium includes various media capable of storing program code, such as a USB flash drive, a mobile hard drive, a read-only memory, a random access memory, a magnetic disk, or an optical disk.
[0180] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application shall be included within the scope of protection of the present application.
Claims
1. A code style checking method, characterized in that: Applied to any user terminal in a code development system, the code development system also including a server, all the user terminals and the server jointly maintaining at least one code repository, the method comprising: In response to a submission instruction of the target code to the target code repository, executing a code style check command in a code style check configuration file preset in the target code repository, checking the target code, and obtaining a first check result; If the first check result indicates that the object code is not passed, the submitted object code is returned; If the first inspection result is characterized as passing, the target code is stored in the target code repository, so that when the server detects that a new target code has been added to the target code repository, it executes the code style check command in the preset code style check configuration file in the target code repository, checks the target code, and obtains a second inspection result; if the second inspection result is characterized as failing, the newly added target code is deleted; if the second inspection result is characterized as passing, the newly added target code is retained.
2. The method according to claim 1, characterized in that The target code repository includes a commit hook function, which is used to trigger a code style check command in a preset code style check configuration file in the target code repository when a commit instruction to submit code to the target code repository is detected.
3. The method according to claim 2, characterized in that In response to a submission instruction for submitting the target code to the target code repository, before executing a code style check command in a code style check configuration file preset in the target code repository, the method further includes: Compiling the target code in response to a compilation instruction of the target code; Check whether there is a commit hook function in all local code repositories; If there is a designated code repository where the submission hook function does not exist, the submission hook function is stored in a preset location in the designated code repository.
4. The method according to claim 1, wherein The code style check commands included in the code style check configuration files in different code repositories are not exactly the same.
5. The method according to claim 1, characterized in that The code repository also includes a check object file, which is used to record a target file path. The code stored in the target file path needs to be checked for code style using the code style check configuration file. Before executing the code style check command in the code style check configuration file preset in the target code repository, the method further includes: It is determined that a storage path record of the object code in the object code repository is recorded in the inspection target file.
6. The method according to claim 1, characterized in that The code style check configuration file also includes a tag corresponding to each code style check command; The mark indicates that execution is required or that execution is not required; Executing the code style check command in the code style check configuration file preset in the target code repository includes: Execute all code style check commands marked as needing to be executed in the code style check configuration file preset in the target code repository.
7. A code style checking method, characterized in that: A method for a server in a code development system, wherein the code development system further includes at least one user terminal, wherein all the user terminals and the server jointly maintain at least one code repository, includes: When it is detected that a new target code is added to the target code repository, a code style check command in a code style check configuration file preset in the target code repository is executed to check the target code and obtain a second check result; wherein, in response to a submission instruction for submitting the target code to the target code repository, the user terminal executes a code style check command in a code style check configuration file preset in the target code repository to check the target code, and when the first check result indicates that the target code passes, the target code is stored in the target code repository; If the second inspection result indicates failure, deleting the newly added target code; If the second check result indicates passing, the newly added target code is retained.
8. The method according to claim 7, characterized in that After merging at least two codes in the target code repository, the method further includes: executing a code style check command in the code style check configuration file preset in the target code repository, checking the merged code, and obtaining a third check result; If the third check result indicates failure, the target code repository is rolled back to a state before the merge.
9. A code style checking method, characterized in that: Applied to a code development system, the code development system includes a server and at least one user terminal, all of the user terminals and the server jointly maintain at least one code repository, the method includes: In response to a submission instruction for submitting the target code to the target code repository, the user terminal executes a code style check command in a code style check configuration file preset in the target code repository, checks the target code, and obtains a first check result; If the first check result indicates failure, the user terminal returns the submitted target code; If the first inspection result indicates passing, storing the target code in the target code repository; When detecting that a new target code is added to the target code repository, the server executes a code style check command in a code style check configuration file preset in the target code repository to check the target code and obtain a second check result; If the second inspection result indicates that the target code is not passed, the server deletes the newly added target code; if the second inspection result indicates that the target code is passed, the server retains the newly added target code.
10. A code style checking device, characterized in that: The device is deployed on any user terminal in a code development system, wherein the code development system further includes a server, and all the user terminals and the server jointly maintain at least one code repository. The device includes: a response module, configured to, in response to a submission instruction of the target code to the target code repository, execute a code style check command in a code style check configuration file preset in the target code repository, check the target code, and obtain a first check result; A first processing module, configured to return the submitted target code if the first inspection result indicates failure; The first processing module is also used to store the target code in the target code repository if the first inspection result is characterized as passed, so that when the server detects that new target code has been added to the target code repository, it executes the code style check command in the code style check configuration file preset in the target code repository, checks the target code, and obtains a second inspection result; if the second inspection result is characterized as failed, the newly added target code is deleted; if the second inspection result is passed, the newly added target code is retained; wherein, the user terminal and the server jointly maintain at least one code repository.
11. A code style checking device, characterized in that: A server deployed in a code development system, the code development system also including at least one user terminal, all of the user terminals and the server jointly maintaining at least one code repository, the apparatus comprising: a detection module configured to, upon detecting that a target code has been newly added to a target code repository, execute a code style check command in a code style check configuration file preset in the target code repository, check the target code, and obtain a second check result; wherein, in response to a submission instruction for submitting the target code to the target code repository, the user terminal executes a code style check command in a code style check configuration file preset in the target code repository, checks the target code, and if the first check result indicates a passing result, the target code is stored in the target code repository; A second processing module, configured to delete the newly added target code if the second inspection result indicates a failure; The second processing module is further configured to retain the newly added target code if the second inspection result indicates passing.
12. A code development system, characterized in that: include: At least one user terminal deployed with the code style checking apparatus according to claim 10, and a server deployed with the code style checking apparatus according to claim 11; all of the user terminals and the servers jointly maintain at least one code repository.
13. An electronic device, characterized in that: include: a memory and a processor, the memory and the processor being connected; The memory is used to store programs; The processor is configured to call a program stored in the memory to execute the method according to any one of claims 1 to 6, or to execute the method according to any one of claims 7 to 8.
14. A computer-readable storage medium, characterized in that A computer program is stored thereon, and when the computer program is run by a computer, the method according to any one of claims 1 to 6 is executed, or the method according to any one of claims 7 to 8 is executed.