Code file processing method, device, equipment and storage medium

By obtaining and adjusting the style configuration files of code files, the problem of different writing styles of different developers is solved, automatic unified style processing of code files is realized, and maintenance efficiency and the unity of the code warehouse are improved.

CN112486566BActive Publication Date: 2024-10-29BIGO TECH PTE LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011150287.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-23
Publication Date
2024-10-29
Estimated Expiration
2040-10-23

AI Technical Summary

Technical Problem

During the development process of software projects, due to the different code writing styles of different developers, it is difficult to maintain the code files, and it is difficult to ensure the uniformity of the code files, which affects the maintenance efficiency.

Method used

By obtaining the original code files and style configuration files, the code style is adjusted to achieve unification, the processed code files are submitted to the remote code warehouse, and compliance verification is performed to ensure the consistency of the code style.

Benefits of technology

It realizes the automatic unified style processing of code files, reduces the difficulty of maintenance, improves the maintenance efficiency of code files, and ensures the uniformity of code style in the remote code warehouse.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112486566B_ABST
    Figure CN112486566B_ABST
Patent Text Reader

Abstract

The present application discloses a code file processing method, device, equipment and storage medium, which belongs to the field of computer technology. The method includes: obtaining an original code file to be style-converted; obtaining a style configuration file, which is used to specify the code style; adjusting the code style of the original code file according to the style configuration file to obtain a processed code file; submitting the processed code file to a remote code repository for storage. In the technical solution provided by the embodiment of the present application, the code style of the original code file obtained is adjusted and processed into a unified code style according to the style configuration file, realizing the function of automatically unifying the code style of the code file, thereby reducing the difficulty of code file maintenance, and then improving the efficiency of code file maintenance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a code file processing method, device, equipment and storage medium. Background Art

[0002] During the development of a software project, it is often necessary for developers to divide the work and cooperate with each other.

[0003] Taking the example of a software project developed by a team, a software project can include multiple functional modules, each of which is implemented by the code written by the developer, and the code of each functional module is written by a corresponding developer. For example, a 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.

[0004] However, due to the different coding styles of different developers, there are many different coding styles in software projects, which makes code maintenance difficult. Summary of the invention

[0005] The embodiments of the present application provide a code file processing method, device, equipment and storage medium, which can unify the code style of code files, reduce the maintenance difficulty of code files, and improve the maintenance efficiency of code files. The technical solution is as follows:

[0006] According to one aspect of an embodiment of the present application, a code file processing method is provided, the method comprising:

[0007] Get the original code file to be converted into style;

[0008] Obtain a style configuration file, where the style configuration file is used to specify a code style;

[0009] Adjust the code style of the original code file according to the style configuration file to obtain a processed code file;

[0010] The processed code file is submitted to a remote code repository for storage.

[0011] According to one aspect of an embodiment of the present application, a code file processing method is provided, the method comprising:

[0012] Receive a submitted version of a processed code file corresponding to an original code file, wherein the processed code file is a file obtained by performing style conversion on the original code file based on a style configuration file, wherein the style configuration file is used to specify a code style;

[0013] Adjust the code style of the original code file according to the style configuration file to obtain a verified version of the processed code file corresponding to the original code file;

[0014] Performing compliance verification on the submitted version based on the verification version;

[0015] If the submitted version passes the compliance check, the submitted version is stored in the remote code repository.

[0016] According to one aspect of an embodiment of the present application, a code file processing device is provided, the device comprising:

[0017] A code file acquisition module is used to obtain the original code file to be style converted;

[0018] A configuration file acquisition module is used to acquire a style configuration file, where the style configuration file is used to specify a code style;

[0019] A code style adjustment module, used to adjust the code style of the original code file according to the style configuration file to obtain a processed code file;

[0020] The code file submission module is used to submit the processed code file to a remote code repository for storage.

[0021] According to one aspect of an embodiment of the present application, a code file processing device is provided, the device comprising:

[0022] A code file receiving module, used to receive a submitted version of a processed code file corresponding to an original code file, wherein the processed code file is a file obtained by performing style conversion on the original code file based on a style configuration file, wherein the style configuration file is used to specify a code style;

[0023] A code file processing module, used to adjust the code style of the original code file according to the style configuration file, and obtain a verified version of the processed code file corresponding to the original code file;

[0024] A code file verification module, used to perform compliance verification on the submitted version based on the verification version;

[0025] The code file storage module is used to store the submitted version in a remote code repository if the submitted version passes the compliance check.

[0026] According to one aspect of an embodiment of the present application, a computer device is provided, comprising a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the above-mentioned code file processing method.

[0027] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is loaded and executed by a processor to implement the above-mentioned code file processing method.

[0028] According to one aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above-mentioned code file processing method.

[0029] The technical solution provided in the embodiments of the present application can bring the following beneficial effects:

[0030] According to the style configuration file, the code style of the obtained original code file is adjusted and processed into a unified code style, realizing the function of automatically unifying the code style of the code file, thereby reducing the difficulty of code file maintenance and further improving the efficiency of code file maintenance.

[0031] In addition, by performing compliance verification on the code style of the submitted version and the code style of the verified version, the code style of the submitted version can be automatically verified, thereby ensuring the uniformity of the code style of the code files in the remote code repository, thereby improving the efficiency of code file maintenance. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0033] Figure 1 It is a schematic diagram of an implementation environment of a solution provided by an embodiment of the present application;

[0034] Figure 2-6 is a flowchart of a code file processing method provided in an embodiment of the present application;

[0035] Figure 7-9 It is a block diagram of a code file processing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0036] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0037] Please refer to Figure 1 , which shows a schematic diagram of a solution implementation environment provided by an embodiment of the present application. The solution implementation environment can be implemented as a system architecture of an application development environment. The solution implementation environment may include: a developer terminal 10 and a server 20.

[0038] The developer terminal 10 may be an electronic device such as a PC (Personal Computer), a laptop, etc. A software development tool may be installed and run in the developer terminal 10. The software development tool is a tool that converts programming languages ​​into codes and compiles and executes them. Optionally, the developer may use the software development tool to write, modify, check, run, and other operations on the code.

[0039] The server 20 is used to store and detect the code uploaded by the developer terminal 10. The server 20 can be a single server, a server cluster consisting of multiple servers, or a cloud computing service center.

[0040] The developer terminal 10 and the server 20 can communicate with each other through a network.

[0041] For example, a client that has a software development tool installed and running is used as an example. The developer writes the code for the software project in the client that has the software development tool installed and running, and then uploads the completed code to the storage server corresponding to the software project through the client. Optionally, before uploading the code, the style of the code can be converted, checked, modified, etc.

[0042] Please refer to Figure 2 , which shows a flowchart of a code file processing method provided by an embodiment of the present application. The execution subject of each step of the method can be Figure 1 The developer terminal 10 in the implementation environment of the solution shown. The method may include the following steps (201-204):

[0043] Step 201, obtaining the original code file to be style converted.

[0044] In the embodiment of the present application, the original code file refers to the code file to be style converted. Among them, the code file is used to store the code. Code refers to human-readable computer language instructions written in accordance with certain programming language specifications. Among them, the programming language is a language used to write computer programs, such as C++ (The C++ProgrammingLanguage / c plus plus, C++ programming language), C (C Programming Language, C programming language), Java (Java computer programming language), JavaScript (JS, JavaScript scripting language), etc., that is, the code can be divided into different types of code according to different programming languages.

[0045] Optionally, the code may also include different styles. For example, the maximum character width of each line of code is different, the line breaking rules of function parameters are different, the rules for adding spaces are different, etc. Optionally, different developers have different coding styles. For example, Developer A uses function parameter line breaking rule A, while Developer B uses function parameter line breaking rule B. Optionally, the same developer may have inconsistent coding styles at different times. For example, Developer A used rule A for adding spaces to write code in 2020, and used rule B for adding spaces to write code in 2010.

[0046] Optionally, the original code file may be directly obtained according to the developer's input, that is, the developer's input is the original code file to be style-converted.

[0047] Optionally, the original code file can be obtained according to the path where the original code file is stored. The specific method is as follows:

[0048] 1. Get the target file path for style conversion;

[0049] 2. Detect whether the file in the target file path is a code file; if the file in the target file path is a code file, determine that the file in the target file path is the original code file to be converted into a style.

[0050] Among them, the target file path refers to the storage path of the target file. According to the storage path of the target file, the target file under the path can be queried and obtained. Based on the target file, it is determined whether it is a code file. If so, the target file is determined to be the original code file to be style converted. If not, a prompt message is displayed, such as prompting an input error. Optionally, it can be determined whether the target file is a code file based on the suffix of the file extension. For example, files with file extension suffixes such as ".c", ".h", ".cpp", ".java", etc. can be determined as original code files.

[0051] Optionally, the original code file can also be obtained according to the file directory storing the original code file. The specific method is as follows:

[0052] 1. Get the target file directory for style conversion;

[0053] 2. Check whether the files contained in the target file directory are code files; select the code files in the target file directory as the original code files to be converted into style.

[0054] The target file directory may be traversed to filter non-code files to obtain code files, and the obtained code files may be determined as original code files to be style converted. Optionally, the target file directory may include multiple code files, so that the original code files may be obtained in batches.

[0055] refer to Figure 3 The file reading unit 301 can obtain the original code file according to the file or directory input by the developer.

[0056] Step 202: Obtain a style configuration file, where the style configuration file is used to specify a code style.

[0057] The style configuration file is used to specify the code style. For example, after obtaining the original code file A and the original code file B, the code styles of the original code file A and the original code file B can be converted according to the code style specified by the style configuration file, that is, the code styles of the original code file A and the original code file B after conversion are consistent with the code style specified by the style configuration file. Optionally, there are multiple types of codes, such as C++, C, Java, JavaScript, etc. The style configuration file may include style configuration files corresponding to the types of codes of the multiple types, and the style configuration files of the corresponding types in the style configuration file may be extracted according to the code types in the obtained original code files. For example, if the obtained original code file is a C++ type code file, the style configuration file corresponding to the C++ type code file in the style configuration file is extracted.

[0058] Optionally, the style configuration file may include a remote style configuration file and a local project style configuration file. The remote style configuration file refers to a style configuration file stored in a server, and the local project style configuration file refers to a style configuration file stored in a developer terminal. Optionally, the acquired remote style configuration file may be stored in a developer terminal, i.e., a new local project style configuration file, so as to be acquired and used when the network is unavailable. Optionally, the developer may acquire the remote style configuration file from the server and the local project style configuration file from the developer terminal.

[0059] Optionally, the local project style configuration file may include a custom project style configuration file, which refers to a style configuration file set by the project developer. For example, the maximum character width of each line of code in the remote style configuration file is A, but the project developer believes that the style configuration does not match the style configuration of the project, and can set the maximum character width of each line of code to B, generate and use the custom project style configuration file.

[0060] Optionally, the required style configuration file is a remote style configuration file by default, and the remote style configuration file will be updated in real time according to the demand, that is, it will be kept as the latest style configuration file. Optionally, when the network is unavailable, the local project style configuration file (or a custom project style configuration file) can be obtained to ensure that the code style conversion of the original code file runs normally, so that the code style conversion of the code file can be realized offline, which improves the selectivity of the conversion.

[0061] In an example, the process of obtaining the project's style configuration file is as follows:

[0062] 1. Check whether the original code file uses a custom project style configuration;

[0063] 2. When the original code file does not use a customized project style configuration, if the network connection with the server is available, a configuration file acquisition request is sent to the server to receive the style configuration file from the server, wherein the configuration file acquisition request is used to request the style configuration file stored in the server; if the network connection with the server is unavailable, the style configuration file is obtained from the local storage unit.

[0064] Optionally, a customized project style configuration file is pre-saved in the root directory of the project, distinguished by a specific file name. For example, the customized project style configuration file is named developer name + "style configuration file", project name + "style configuration file", etc. In the process of obtaining the style configuration file of the project, the root directory of the project is first scanned. If a style configuration file is detected in the root directory of the project, the style configuration file is obtained, which indicates that a customized project style configuration file is used for the source code file. If no style configuration file is detected in the root directory of the project, it indicates that the project does not use a customized project style configuration for the source code file, and the remote style configuration file is obtained by default. Among them, if the network between the server is unavailable, the local project style configuration file can be obtained from the local storage unit. Reference Figure 3The configuration file parsing unit 302 can read the project style configuration file locally, and can also obtain the remote style configuration file from the server via HTTP (HyperText Transfer Protocol).

[0065] Optionally, the remote style configuration file may be pre-set in the server and support HTTP request return, wherein HTTP refers to a request-response protocol, that is, upon receiving a request to obtain the remote style configuration file, HTTP responds and returns the remote style configuration file.

[0066] After obtaining the style configuration file, the key-value pairs of each style configuration are parsed based on the style configuration file, that is, the specific content of each style configuration can be obtained according to the "key". For example, if the remote style configuration file obtained is in Json (JavaScript Object Notation) format, it is necessary to parse it to obtain the key-value pairs of each specific style configuration, and then obtain the specific style configuration content of each item in the style configuration file according to the key-value pairs. Optionally, the obtained key-value pairs can be written into the memory, and the key-value pairs can also be written into the local storage unit for subsequent retrieval and use.

[0067] Step 203: Adjust the code style of the original code file according to the style configuration file to obtain a processed code file.

[0068] Optionally, the process of adjusting the code style of the original code file includes: obtaining a syntax tree of the code in the original code file; and rewriting the code in the original code file based on the style configuration file and the syntax tree to obtain a processed code file.

[0069] Wherein, obtaining specific style configuration content includes: based on the code type of the original code file, calling the key-value pair of the style configuration of the corresponding type in the style configuration file, and then extracting the specific style configuration content of the style configuration of the type according to the corresponding key-value pair. For example: for the original code file of type C++, the specific style configuration content of type C++ is called accordingly.

[0070] Obtaining the content of the processed code file includes: generating a syntax tree of the code based on the original code file, traversing each unit of the syntax tree, and then writing the code back to the original code file according to the specific style configuration content corresponding to the style configuration file, generating an intermediate file, that is, a code file in text format. Finally, make format adjustments to obtain the processed code file. Since the above operations are idempotent operations, they will not affect the execution effect of the code, that is, the modified code file has the same effect as the original code file, and only the code style is different.

[0071] refer to Figure 3 The file reading unit 301 generates an original code file in a syntax tree parsing format based on the acquired original code file, and then generates a modified code file according to the specific style configuration content extracted from the style configuration file by the configuration file parsing unit 302, and outputs it in the form of a file or directory.

[0072] Step 204: submit the processed code file to a remote code repository for storage.

[0073] After obtaining the processed code file, submit it to the remote code repository for storage. In this way, other developers can pull the code file with the latest code style from the remote code repository, realizing resource sharing of code files.

[0074] Optionally, the code files submitted to the remote code repository are remote codes, and the code files retained locally are local codes.

[0075] To sum up, the technical solution provided in the embodiment of the present application adjusts the code style of the acquired original code file into a unified code style according to the style configuration file, realizes the function of automatically unifying the code style of the code file, thereby reducing the difficulty of code file maintenance and further improving the efficiency of code file maintenance.

[0076] In addition, by saving the remote style configuration file locally, when the network is unavailable, the remote style configuration file saved locally can be called to ensure the code style conversion process of the original code file, realize the offline conversion of the code style of the original code file, and improve the selectivity of the operation.

[0077] In addition, by obtaining the original code files based on the directory of the target file, batch acquisition of the original code files is achieved, thereby improving the efficiency of the original code file conversion.

[0078] Please refer to Figure 4 , which shows a flowchart of a code file processing method provided by another embodiment of the present application. The execution subject of each step of the method can be Figure 1 The server 20 in the implementation environment of the solution shown. The method may include the following steps (401-404):

[0079] Step 401, receiving a submitted version of a processed code file corresponding to an original code file.

[0080] The processed code file is a file obtained by converting the style of the original code file based on the style configuration file, and the style configuration file is used to specify the code style. The introduction of the style configuration file can be found in the above embodiment, which will not be repeated here.

[0081] A submitted version refers to a version of a processed code file that is submitted to a remote code repository. Optionally, the submitted versions of processed code files corresponding to different original code files in the same project have the same code style.

[0082] Optionally, after receiving the submitted version of the processed code file corresponding to the original code file, the submitted version may also be preliminarily screened.

[0083] In one example, it is detected whether the submitted version belongs to a file whitelist, which is used to indicate code files that need to be style-checked. If the submitted version belongs to the file whitelist, the following steps are performed to adjust the code style of the original code file according to the style configuration file to obtain a check version of the processed code file corresponding to the original code file.

[0084] In another example, it is detected whether the submitted version belongs to a file blacklist, which is used to indicate code files that do not need style verification; if the submitted version does not belong to the file blacklist, the following steps are performed to adjust the code style of the original code file according to the style configuration file to obtain a verified version of the processed code file corresponding to the original code file.

[0085] Optionally, the code files in the file whitelist or file blacklist can be customized, which is not limited in the embodiments of the present application. For example, the submitted version includes project code files and third-party code files, and the third-party code files are added to the file blacklist. Then, the third-party code files do not need to be style-checked, and only the project code files need to be checked. Optionally, when the code files that need to be style-checked pass the verification, the code files that do not need to be style-checked will also be stored in the remote code repository. When the code files that need to be style-checked fail the verification, the code files that do not need to be style-checked cannot be stored in the remote code repository.

[0086] Optionally, the code file content of the submitted version can be obtained through the text difference content and file list submitted by the version control system. For example, when using a version control system such as Svn (Subversion, a software project version control management system) or Git (distributed version control system), each submission of the version control system includes the text difference content and file list of the submitted version. Among them, the text difference content refers to the modified content corresponding to the code style conversion process of the original code file.

[0087] refer to Figure 5After obtaining the submitted version, the parsing unit 501 parses the latest file whitelist and file blacklist of the project. At the same time, the parsing unit 501 performs version parsing on the submitted version, and the specific content is as follows: call the code file in the file list, and then obtain the latest code file content according to the corresponding text difference content. Finally, match the file list with the file whitelist or file blacklist to obtain the code file list and the corresponding code file content that need to be checked in the file list.

[0088] Step 402: Adjust the code style of the original code file according to the style configuration file to obtain a verified version of the processed code file corresponding to the original code file.

[0089] The verification version generation process in step 402 is similar to the modified code file generation process in step 203 above, except that the execution subject of the modified code file generation process is the developer terminal, and the execution subject of the verification version generation process is the server.

[0090] Optionally, the style configuration file used by the verified version of the original code file is consistent with that used by the submitted version. When the style configuration file used by the submitted version is a remote style configuration file, the style configuration file of the verified version is the remote style configuration file. When the style configuration file used by the submitted version is a project style configuration file, the style configuration file of the verified version is the project style configuration file. The project style configuration file includes a unified local project style configuration file or a customized local project style configuration file. Figure 5 The format checking unit 502 obtains a verified version of the processed code file corresponding to the original code file based on the obtained original code file and the corresponding remote configuration file (or project style configuration file).

[0091] Step 403: Perform compliance verification on the submitted version based on the verification version.

[0092] In the embodiment of the present application, the compliance check is used to check whether the code style of the submitted version and the verified version is consistent. Among them, the verified version is the verification standard file, and the submitted version is the verification object. If the code style of the submitted version is consistent with the code style of the verified version, it is determined that the compliance check of the submitted version has passed. If the code style of the submitted version is inconsistent with the code style of the verified version, it is determined that the compliance check of the submitted version has not passed. For example, refer to Figure 5 The format checking unit 502 performs compliance checking on the code text content of the verified version and the code text content of the submitted version output by the parsing unit 501 to determine whether the code style of the submitted version meets the review standards.

[0093] Step 404: If the submitted version passes the compliance check, the submitted version is stored in the remote code repository.

[0094] If the submitted version passes the compliance check, it means that the code style of the submitted version meets the review standards, and the submitted version is stored in the remote code repository. Optionally, the submitted content includes code files that need to be checked and code files that do not need to be checked.

[0095] In one example, reference Figure 6 , the submitted version that passes the compliance check will be stored in a temporary remote code repository, and will not be stored in the remote code repository until it passes the review of the reviewer. The reviewer can be the project leader, other project developers, etc. The submitted version that fails the compliance check and review will be returned to the developer terminal.

[0096] In one example, if the submitted version fails the compliance check, the difference content between the submitted version and the checked version is obtained; and a viewing link corresponding to the difference content is generated, and the viewing link is used to view the difference content.

[0097] The difference content refers to the specific difference in code style between the submitted version and the verified version. For example, if the maximum character width of the first line of code in the submitted version is A, and the maximum character width of the first line of code in the verified version is B, then the difference content is that the maximum character width of the first line of code is B, not A.

[0098] The viewing link is a link used to locate the difference content. The viewing link is unique, that is, one piece of difference content corresponds to one viewing link.

[0099] Optionally, the difference content can be stored in the server, and the difference content can be obtained by accessing the corresponding view link. This makes it easier for developers to locate specific difference content and adjust the code writing style according to the difference content, thereby cultivating a good code writing style for developers. Figure 5 , the file difference submission unit 503 includes an HTTP service unit and a file storage service unit. When the submitted version and the verified version do not pass the compliance check, the file difference submission unit 503 stores the received difference content in the file storage service unit, and generates a unique URL (Uniform Resource Locator) through the HTTP service unit and returns it to the developer terminal. The developer can access the URL through the developer terminal to obtain the file difference.

[0100] To sum up, the technical solution provided by the embodiment of the present application realizes automatic verification of the code style of the submitted version by performing compliance verification on the code style of the submitted version and the code style of the verified version, thereby ensuring the uniformity of the code style in the remote code repository, facilitating the maintenance of code files, and thus improving the efficiency of code file maintenance.

[0101] In addition, by providing customizable whitelist and blacklist functions, the number of code files that require style verification is reduced, thereby improving the efficiency of code file processing.

[0102] In addition, by generating the difference content and corresponding viewing links between the submitted version and the verified version, developers can obtain the difference content by accessing the viewing link, and perform operations such as studying and modifying the difference content, thereby cultivating a good coding style for developers and improving the maintenance efficiency of code files.

[0103] The following are device embodiments of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.

[0104] Please refer to Figure 7 , which shows a block diagram of a code file processing device provided by an embodiment of the present application. The device has the function of implementing the above-mentioned example of the code file processing method on the developer terminal side, and the function can be implemented by hardware, or by hardware executing corresponding software. The device can be a computer device, or it can be set in a computer device. The device 700 may include: a code file acquisition module 701, a configuration file acquisition module 702, a code style adjustment module 703 and a code file submission module 704.

[0105] The code file acquisition module 701 is used to acquire the original code file to be style converted.

[0106] The configuration file acquisition module 702 is used to acquire a style configuration file, where the style configuration file is used to specify a code style.

[0107] The code style adjustment module 703 is used to adjust the code style of the original code file according to the style configuration file to obtain a processed code file.

[0108] The code file submission module 704 is used to submit the processed code file to the remote code repository for storage.

[0109] In an exemplary embodiment, the code style adjustment module 703 is used to obtain a syntax tree of the code in the original code file; based on the style configuration file and the syntax tree, rewrite the code in the original code file to obtain the processed code file.

[0110] In an exemplary embodiment, the configuration file acquisition module 702 is used to detect whether the original code file adopts a customized project style configuration; if the original code file does not adopt the customized project style configuration, if the network connection with the server is available, a configuration file acquisition request is sent to the server, and the style configuration file from the server is received, wherein the configuration file acquisition request is used to request to obtain the style configuration file stored in the server; if the network connection with the server is unavailable, the style configuration file is obtained from a local storage unit.

[0111] In an exemplary embodiment, the code file acquisition module 701 is used to obtain the target file path to be style converted; detect whether the file in the target file path is a code file; if the file in the target file path is the code file, determine that the file in the target file path is the original code file to be style converted.

[0112] Alternatively, the code file acquisition module 701 is used to obtain a target file directory to be style converted; detect whether the files contained in the target file directory are code files; and select the code files in the target file directory as the original code files to be style converted.

[0113] To sum up, the technical solution provided in the embodiment of the present application adjusts the code style of the acquired original code file into a unified code style according to the style configuration file, realizes the function of automatically unifying the code style of the code file, thereby reducing the difficulty of code file maintenance and further improving the efficiency of code file maintenance.

[0114] Please refer to Figure 8 , which shows a block diagram of a code file processing device provided by another embodiment of the present application. The device has the function of implementing the above-mentioned example of the code file processing method on the server side, and the function can be implemented by hardware, or by hardware executing corresponding software. The device can be a computer device, or it can be set in a computer device. The device 800 may include: a code file receiving module 801, a code file processing module 802, a code file verification module 803 and a code file storage module 804.

[0115] The code file receiving module 801 is used to receive a submitted version of a processed code file corresponding to an original code file, wherein the processed code file is a file obtained by performing style conversion on the original code file based on a style configuration file, wherein the style configuration file is used to specify a code style.

[0116] The code file processing module 802 is used to adjust the code style of the original code file according to the style configuration file to obtain a verified version of the processed code file corresponding to the original code file.

[0117] The code file verification module 803 is used to perform compliance verification on the submitted version based on the verification version.

[0118] The code file storage module 804 is used to store the submitted version in a remote code repository if the submitted version passes the compliance check.

[0119] In an exemplary embodiment, Fig. 9 As shown, the device 800 also includes a list detection module 805.

[0120] Optionally, the list detection module 805 is used to detect whether the submitted version belongs to the file whitelist, and the file whitelist is used to indicate the code files that need to be style-checked. The code file processing module 802 is also used to, if the submitted version belongs to the file whitelist, perform the step of adjusting the code style of the original code file according to the style configuration file to obtain the check version of the processed code file corresponding to the original code file.

[0121] Optionally, the list detection module 805 is used to detect whether the submitted version belongs to a file blacklist, and the file blacklist is used to indicate code files that do not need style verification. The code file processing module 902 is also used to perform the step of adjusting the code style of the original code file according to the style configuration file to obtain a verified version of the processed code file corresponding to the original code file if the submitted version does not belong to the file blacklist.

[0122] In an exemplary embodiment, Fig. 9 As shown, the device 800 includes: a difference content acquisition module 806 and a viewing link generation module 807 .

[0123] The difference content acquisition module 806 is used to acquire the difference content between the submitted version and the verified version if the submitted version fails the compliance verification.

[0124] The viewing link generating module 807 is used to generate a viewing link corresponding to the difference content, and the viewing link is used to view the difference content.

[0125] To sum up, the technical solution provided by the embodiment of the present application realizes automatic verification of the code style of the submitted version by performing compliance verification on the code style of the submitted version and the code style of the verified version, thereby ensuring the uniformity of the code style of the code files in the remote code repository, thereby improving the efficiency of code file maintenance.

[0126] It should be noted that the device provided in the above embodiment only uses the division of the above functional modules as an example to implement its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and their specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0127] In an exemplary embodiment, a computer device is provided. The computer device includes a processor and a memory. A computer program is stored in the memory. The computer program is loaded and executed by the processor to implement the above code file processing method.

[0128] In an exemplary embodiment, a computer-readable storage medium is further provided, wherein a computer program is stored in the storage medium, and when the computer program is executed by a processor, the above-mentioned code file processing method is implemented.

[0129] In an exemplary embodiment, a computer program product or a computer program is also provided, wherein the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above-mentioned code file processing method.

[0130] It should be understood that the "multiple" mentioned in this article refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In addition, the step numbers described in this article only illustrate a possible execution sequence between the steps. In some other embodiments, the above steps may not be executed in the order of the numbers, such as two steps with different numbers are executed at the same time, or two steps with different numbers are executed in the opposite order to the diagram. The embodiments of the present application are not limited to this.

[0131] The above description is only an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

Claims

1. A code file processing method, characterized in that: The method comprises: Get the original code file to be converted into style; Scanning the root directory corresponding to the original code file; If there is a style configuration file in the root directory, obtaining the style configuration file, where the style configuration file is a custom project style configuration file; If the style configuration file does not exist in the root directory, determining that the original code file does not use a customized project style configuration; In the case that the original code file does not adopt the customized project style configuration, if the network connection with the server is available, sending a configuration file acquisition request to the server, and receiving the style configuration file from the server, wherein the configuration file acquisition request is used to request to acquire the style configuration file stored in the server; If the network connection with the server is unavailable, obtaining the style configuration file from a local storage unit; Adjust the code style of the original code file according to the style configuration file to obtain a processed code file; Submitting the processed code file that has passed the compliance check to a remote code repository for storage, wherein the compliance check refers to checking the processed code file based on a check version, wherein the check version is obtained by processing the original code file based on the style configuration file; The style configuration file is used to define the code style, which refers to the code writing style of the developer, and includes at least one of the following: the maximum character width of each line of code, the line break rules of function parameters, and the rules for adding spaces.

2. The method according to claim 1, characterized in that The step of adjusting the code style of the original code file according to the style configuration file to obtain a processed code file includes: Obtaining a syntax tree of the code in the original code file; Based on the style configuration file and the syntax tree, the code in the original code file is rewritten to obtain the processed code file.

3. The method according to claim 1 or 2, characterized in that: The obtaining of the original code file to be style converted includes: Obtain a target file path to be converted into a style; detect whether the file in the target file path is a code file; if the file in the target file path is the code file, determine that the file in the target file path is the original code file to be converted into a style; or, Obtain a target file directory to be subjected to style conversion; detect whether the file contained in the target file directory is a code file; and select the code file in the target file directory as the original code file to be subjected to style conversion.

4. A code file processing method, characterized in that: The method comprises: Receive a submitted version of a processed code file corresponding to an original code file, wherein the processed code file is a file obtained by performing style conversion on the original code file based on a style configuration file, wherein the style configuration file is used to specify a code style, wherein the code style refers to a code writing style owned by a developer, and the code style includes at least one of the following: a maximum character width of each line of code, a line break rule for function parameters, and a rule for adding spaces; Adjust the code style of the original code file according to the style configuration file to obtain a verified version of the processed code file corresponding to the original code file; Performing compliance verification on the submitted version based on the verification version; If the submitted version passes the compliance check, the submitted version is stored in the remote code repository; Among them, when there is a style configuration file in the root directory corresponding to the original code file, the style configuration file is a custom project style configuration file; when the style configuration file does not exist in the root directory, the original code file does not adopt the custom project style configuration; when the original code file does not adopt the custom project style configuration, if the network connection between the terminal and the server is available, the style configuration file is the style configuration file from the server; if the network connection between the terminal and the server is unavailable, the style configuration file is the style configuration file obtained from the local storage unit.

5. The method according to claim 4, characterized in that After receiving the submitted version of the processed code file corresponding to the original code file, the method further includes: Detecting whether the submitted version belongs to a file whitelist, where the file whitelist is used to indicate code files that need to be style-checked; if the submitted version belongs to the file whitelist, executing the step of adjusting the code style of the original code file according to the style configuration file to obtain a check version of the processed code file corresponding to the original code file; or, Detect whether the submitted version belongs to a file blacklist, where the file blacklist is used to indicate code files that do not need style verification; if the submitted version does not belong to the file blacklist, execute the step of adjusting the code style of the original code file according to the style configuration file to obtain a verified version of the processed code file corresponding to the original code file.

6. The method according to claim 4 or 5, characterized in that: After the compliance check of the submitted version is performed based on the check version, the method further includes: If the submitted version fails the compliance check, obtaining the difference between the submitted version and the checked version; A viewing link corresponding to the difference content is generated, where the viewing link is used to view the difference content.

7. A code file processing device, characterized in that: The device comprises: A code file acquisition module is used to obtain the original code file to be style converted; A configuration file acquisition module is used to scan the root directory corresponding to the original code file; if there is a style configuration file in the root directory, the style configuration file is acquired, and the style configuration file is a customized project style configuration file; if there is no style configuration file in the root directory, it is determined that the original code file does not adopt the customized project style configuration; if the original code file does not adopt the customized project style configuration, if the network connection with the server is available, a configuration file acquisition request is sent to the server to receive the style configuration file from the server, wherein the configuration file acquisition request is used to request to acquire the style configuration file stored in the server; if the network connection with the server is unavailable, the style configuration file is acquired from a local storage unit; A code style adjustment module, used to adjust the code style of the original code file according to the style configuration file to obtain a processed code file; A code file submission module, used to submit the processed code file that has passed the compliance check to a remote code repository for storage, wherein the compliance check refers to checking the processed code file based on a check version, wherein the check version is obtained by processing the original code file based on the style configuration file; The style configuration file is used to define the code style, which refers to the code writing style of the developer, and includes at least one of the following: the maximum character width of each line of code, the line break rules of function parameters, and the rules for adding spaces.

8. A code file processing device, characterized in that: The device comprises: A code file receiving module is used to receive a submitted version of a processed code file corresponding to an original code file, wherein the processed code file is a file obtained by performing style conversion on the original code file based on a style configuration file, wherein the style configuration file is used to specify a code style, wherein the code style refers to a code writing style owned by a developer, and the code style includes at least one of the following: a maximum character width of each line of code, a line break rule for function parameters, and a rule for adding spaces; A code file processing module, used to adjust the code style of the original code file according to the style configuration file, and obtain a verified version of the processed code file corresponding to the original code file; A code file verification module, used to perform compliance verification on the submitted version based on the verification version; A code file storage module, used for storing the submitted version in a remote code repository if the submitted version passes the compliance check; Among them, when there is a style configuration file in the root directory corresponding to the original code file, the style configuration file is a custom project style configuration file; when the style configuration file does not exist in the root directory, the original code file does not adopt the custom project style configuration; when the original code file does not adopt the custom project style configuration, if the network connection between the terminal and the server is available, the style configuration file is the style configuration file from the server; if the network connection between the terminal and the server is unavailable, the style configuration file is the style configuration file obtained from the local storage unit.

9. A computer device, characterized in that: The computer device includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the code file processing method according to any one of claims 1 to 3, or the code file processing method according to any one of claims 4 to 6.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is loaded and executed by a processor to implement the code file processing method according to any one of claims 1 to 3, or the code file processing method according to any one of claims 4 to 6.

11. A computer program product, characterized in that The computer program product comprises a computer program, and the computer program is loaded and executed by a processor to implement the code file processing method according to any one of claims 1 to 3, or the code file processing method according to any one of claims 4 to 6.

Citation Information

Patent Citations

  • Code regulatory checking method and device

    CN108536472A

  • Code updating method and device based on data standardization and terminal equipment

    CN110609693A