CN113535183A - Code processing method and device, electronic equipment and storage medium - Google Patents

Code processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113535183A
CN113535183A CN202110856545.2A CN202110856545A CN113535183A CN 113535183 A CN113535183 A CN 113535183A CN 202110856545 A CN202110856545 A CN 202110856545A CN 113535183 A CN113535183 A CN 113535183A
Authority
CN
China
Prior art keywords
code
rule information
code rule
processing
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110856545.2A
Other languages
Chinese (zh)
Other versions
CN113535183B (en
Inventor
王兵营
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Dajia Internet Information Technology Co Ltd
Original Assignee
Beijing Dajia Internet Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Dajia Internet Information Technology Co Ltd filed Critical Beijing Dajia Internet Information Technology Co Ltd
Priority to CN202110856545.2A priority Critical patent/CN113535183B/en
Publication of CN113535183A publication Critical patent/CN113535183A/en
Application granted granted Critical
Publication of CN113535183B publication Critical patent/CN113535183B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons

Landscapes

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

Abstract

The disclosure relates to a code processing method, a code processing device, an electronic device and a storage medium. The method comprises the following steps: acquiring a plurality of items of first code rule information which are used for realizing first code processing among different code processing tools from code rule information contained in the code processing tools, wherein the plurality of items of first code rule information belong to the different code processing tools respectively; determining target code rule information from the plurality of items of first code rule information; combining the target code rule information with second code rule information contained in a plurality of code processing tools to obtain combined code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools and is used for realizing second code processing; and processing the code to be processed based on the combined code rule information to obtain a processed code. The present disclosure may improve the efficiency of code rule unification for multiple code processing tools.

Description

Code processing method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a code processing method and apparatus, an electronic device, and a storage medium.
Background
With the development of computer technology, code development is increasingly complicated, and code regularization has been increasingly emphasized in the code development process.
At present, code regularization is mainly solved through a code rule tool, a user can input a code into the code processing tool, and the code processing tool performs code regularization processing on the input code, however, at present, standard rules are difficult to unify among a plurality of code processing tools, and a mode of ensuring code rules to be unified among the plurality of code processing tools through copying the rules is low in efficiency.
Disclosure of Invention
The present disclosure provides a code processing method, apparatus, electronic device and storage medium, to at least solve the problem of low efficiency in a manner of ensuring code rule unification among a plurality of code rule tools in the related art. The technical scheme of the disclosure is as follows:
according to a first aspect of the embodiments of the present disclosure, there is provided a code processing method, including:
acquiring a plurality of items of first code rule information which are used for realizing first code processing among different code processing tools from code rule information contained in the code processing tools, wherein the plurality of items of first code rule information belong to the different code processing tools respectively;
determining target code rule information from the plurality of items of first code rule information;
combining the target code rule information with second code rule information contained in the plurality of code processing tools to obtain combined code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools, and the second code rule information is used for realizing second code processing;
and processing the code to be processed based on the combined code rule information to obtain a processed code.
In an exemplary embodiment, the determining target code rule information from the plurality of items of first code rule information includes: acquiring performance parameters for realizing the first code processing by the plurality of items of first code rule information; target code rule information is determined from the plurality of items of first code rule information based on the performance parameter.
In an exemplary embodiment, before the combining the target code rule information and the second code rule information included in the plurality of code processing tools, the method further includes: acquiring various first code processing tools to which various first code rule information except the target code rule information belongs; and for each first code processing tool, forbidding the first code rule information contained in the first code processing tool, and using the code rule information which is not forbidden as the second code rule information contained in the first code processing tool.
In an exemplary embodiment, the combining the target code rule information and the second code rule information included in the plurality of code processing tools to obtain combined code rule information corresponding to the plurality of code processing tools includes: determining second code rule information associated with the target code rule information from second code rule information contained in the first code processing tool as candidate rule information; and generating a corresponding target plug-in based on the target code rule information, and configuring calling information for calling the target plug-in for the candidate rule information to obtain the combined code rule information.
In an exemplary embodiment, after obtaining the combined code rule information corresponding to the plurality of code processing tools, the method further includes: acquiring tool configuration information of each code processing tool corresponding to the combined code rule information through a configuration file interface reserved in the combined code rule information; acquiring editing information aiming at one or more tool configuration information, updating corresponding tool configuration information by using the editing information, and updating the combined code rule information based on the updated tool configuration information.
In an exemplary embodiment, the first code process comprises a code formatting process, the first code specification information being for implementing the code formatting process; the second code process includes a code quality check process, and the second code rule information is used to implement the code quality check process.
In an exemplary embodiment, the processing the to-be-processed code based on the combined code rule information to obtain a processed code includes: performing code quality inspection processing on the code to be processed based on the second code rule information in the combined code rule information; after the code quality inspection processing is completed, code formatting processing is performed on the code subjected to the code quality inspection processing based on the target code rule information in the combined code rule information, and a processed code is obtained.
According to a second aspect of the embodiments of the present disclosure, there is provided a code processing apparatus including:
a first rule obtaining unit configured to execute obtaining, from code rule information included in a plurality of code processing tools, a plurality of items of first code rule information for realizing a first code process between different code processing tools, the plurality of items of first code rule information belonging to the different code processing tools, respectively;
a target rule obtaining unit configured to perform determination of target code rule information from the plurality of items of first code rule information;
a combination rule obtaining unit configured to perform combination of the target code rule information and second code rule information included in the plurality of code processing tools to obtain combination code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools, and the second code rule information is used for realizing second code processing;
and the code processing unit is configured to execute processing on the code to be processed based on the combined code rule information to obtain a processed code.
In an exemplary embodiment, the target rule obtaining unit is further configured to perform obtaining the plurality of items of first code rule information to achieve a performance parameter of the first code processing; target code rule information is determined from the plurality of items of first code rule information based on the performance parameter.
In an exemplary embodiment, the code rule information processing apparatus further includes: a second rule obtaining unit configured to execute obtaining of each first code processing tool to which each item of first code rule information other than the target code rule information belongs; and for each first code processing tool, forbidding the first code rule information contained in the first code processing tool, and using the code rule information which is not forbidden as the second code rule information contained in the first code processing tool.
In an exemplary embodiment, the combination rule obtaining unit is further configured to determine, from second code rule information included in the first code rule tool, second code rule information associated with the target code rule information as candidate rule information; and generating a corresponding target plug-in based on the target code rule information, and configuring calling information for calling the target plug-in for the candidate rule information to obtain the combined code rule information.
In an exemplary embodiment, the code rule information processing apparatus further includes: the configuration information updating unit is configured to execute the configuration file interface reserved in the combined code rule information to acquire the tool configuration information of each code processing tool corresponding to the combined code rule information; acquiring editing information aiming at one or more tool configuration information, updating corresponding tool configuration information by using the editing information, and updating the combined code rule information based on the updated tool configuration information.
In an exemplary embodiment, the first code process comprises a code formatting process, the first code specification information being for implementing the code formatting process; the second code process includes a code quality check process, and the second code rule information is used to implement the code quality check process.
In an exemplary embodiment, the code processing unit is further configured to perform code quality check processing on the code to be processed based on the second code rule information in the combined code rule information; after the code quality inspection processing is completed, code formatting processing is performed on the code subjected to the code quality inspection processing based on the target code rule information in the combined code rule information, and a processed code is obtained.
According to a third aspect of the embodiments of the present disclosure, there is provided an electronic apparatus including: a processor; a memory for storing the processor-executable instructions; wherein the processor is configured to execute the instructions to implement the code processing method as defined in any one of the embodiments of the first aspect.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer-readable storage medium, wherein instructions, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method as defined in any one of the first aspects.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements a code processing method as defined in any one of the embodiments of the first aspect.
The technical scheme provided by the embodiment of the disclosure at least brings the following beneficial effects:
acquiring a plurality of items of first code rule information which are used for realizing first code processing among different code processing tools from code rule information contained in the code processing tools, wherein the plurality of items of first code rule information belong to the different code processing tools respectively; determining target code rule information from the plurality of items of first code rule information; combining the target code rule information with second code rule information contained in a plurality of code processing tools to obtain combined code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools, and the second code rule information is used for realizing second code processing; and processing the code to be processed based on the combined code rule information to obtain a processed code. The present disclosure can improve the efficiency of code rule unification of a plurality of code processing tools by determining one plurality of first code rule information for each of the plurality of code processing tools, and combining code rule information other than the first code rule information in the plurality of code rule tools with the target code rule information to obtain combined code rule information in which a plurality of code rule information included in the plurality of code rule tools are combined, for code processing.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure and are not to be construed as limiting the disclosure.
FIG. 1 is a flow diagram illustrating a method of code processing according to an example embodiment.
FIG. 2 is a flow diagram illustrating obtaining second code specification information, according to an example embodiment.
FIG. 3 is a flowchart illustrating obtaining combined code rule information according to an example embodiment.
FIG. 4 is a flowchart illustrating updating combined code rule information according to an example embodiment.
FIG. 5 is a flowchart illustrating processing of code to be processed according to an example embodiment.
FIG. 6 is a diagram illustrating code processing functionality corresponding to a code rule tool, according to an example embodiment.
FIG. 7 is a block diagram illustrating a code processing apparatus according to an example embodiment.
FIG. 8 is a block diagram illustrating an electronic device in accordance with an example embodiment.
Detailed Description
In order to make the technical solutions of the present disclosure better understood by those of ordinary skill in the art, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the disclosure described herein are capable of operation in sequences other than those illustrated or otherwise described herein. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
Fig. 1 is a flowchart illustrating a code processing method according to an exemplary embodiment, and the code processing method is used in a terminal as shown in fig. 1, and includes the following steps.
In step S101, a plurality of items of first code rule information for implementing the first code processing between different code processing tools are obtained from code rule information included in the plurality of code processing tools, and the plurality of items of first code rule information belong to different code processing tools, respectively.
The plurality of code processing tools refer to rule tools for performing code regularization processing on codes in different code formats, or different types of code rule tools for performing different regularization functions on codes, and may include, for example, a rule tool for performing problem finding and repairing on a script language, a rule tool for performing problem finding and repairing on a code in a cascading style, a rule tool for focusing on code formatting on codes, and the like. Code rule information refers to code processing rules that are inherent in the code rule tool. Since each code rule tool can adopt one or more processing rules to execute the regularization processing of the code, some code rule information of a plurality of code rule tools may be used to implement the same certain code processing function, i.e. all the code rule information is used to implement the first code processing function, and the first code rule information is the code rule information used to implement the first code processing in the code rule information included in the plurality of code processing tools. Specifically, after obtaining the plurality of code processing tools, the terminal may extract the code rule information included in the code processing tool from the code processing tool, and may find out, from the obtained plurality of code rule information, a plurality of items of first code rule information for realizing the same first code processing function among different code processing tools.
Taking eslin tools and Prettier tools as examples, both the eslin tools and Prettier tools carry code rule information for implementing a formatting processing function for a scripting language, so that the formatting processing function for the scripting language can be used as a first code processing function, and the code rule information of the part can be used as the first code rule information.
In step S102, target code rule information is determined from the plurality of items of first code rule information.
The object code rule information is first code rule information for uniformly implementing the same first code processing function, and for example, one of the first code rule information may be selected as the object code rule information, and the terminal may select one of the first code rule information as the object code rule information from a plurality of first code rule information for implementing the same first code processing function. For example, the first code rule information implementing the first code process may include code rule information a, code rule information B, and code rule information C, and then the terminal may select one of the code rule information, which may be the code rule information B, as the target code rule information.
In the present disclosure, the first code rule information for uniformly implementing the same first code processing function may be code rule information for implementing the same formatting function, and taking an eslin tool and a Prettier tool as examples, since all the above tools have code rule information for implementing the formatting function for a scripting language, in the present disclosure, one code rule information for implementing the formatting function may be selected from the eslin tool and the Prettier tool as target code rule information, and the code rule information for implementing the formatting function in the Prettier tool may be selected as the target code rule information.
In step S103, combining the target code rule information and the second code rule information included in the plurality of code processing tools to obtain combined code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information other than the first code rule information included in the plurality of code processing tools, and the second code rule information is used for realizing the second code processing.
The second code rule information is code rule information other than the first code rule information among code rule information included in the plurality of code rule tools, and the terminal may combine the second code rule information included in the plurality of code rule tools with the target code rule information determined in step S102 to obtain combined code rule information corresponding to the plurality of code rule tools in step S101.
For example, the code rule information included in the plurality of code rule tools may include: code rule information a, code rule information B, code rule information C, code rule information D, and code rule information E, wherein the code rule information a, the code rule information B, and the code rule information C implement the same first code process, and the code rule information D and the code rule information E implement a second code rule process, then the terminal may determine that the code rule information a, the code rule information B, and the code rule information C are first code rule information, and the code rule information D and the code rule information E are second code rule information, and the terminal may determine target code rule information for unifying the first code rule information from the first code rule information, may be the code rule information B, then the terminal may combine the code rule information B with the code rule information D and the code rule information E, thereby obtaining the combined code rule information corresponding to the plurality of code rule tools.
In step S104, the code to be processed is processed based on the combined code rule information, and a processed code is obtained.
The to-be-processed code refers to a code which needs to be processed by using combined code rule information, and may be a code which needs to be subjected to code regularization processing, and after the code rule information included in the plurality of code processing tools is combined at the terminal to obtain the combined code rule information, the to-be-processed code which needs to be subjected to code regularization processing may be processed by using the combined code rule information. Specifically, the terminal may process the code to be processed by using the combined code rule information obtained in step S103, so as to obtain a processed code.
In the code processing method, a terminal acquires a plurality of items of first code rule information which are used for realizing first code processing among different code processing tools from code rule information contained in the code processing tools, wherein the plurality of items of first code rule information belong to different code processing tools respectively; determining target code rule information from the plurality of items of first code rule information; combining the target code rule information with second code rule information contained in a plurality of code processing tools to obtain combined code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools, and the second code rule information is used for realizing second code processing; and processing the code to be processed based on the combined code rule information to obtain a processed code. The method comprises the steps that a terminal determines one piece of first code rule information through a plurality of pieces of first code rule information which are used for realizing first code processing in a plurality of code processing tools, and combines code rule information except the first code rule information in the plurality of code rule tools with the target code rule information, so that combined code rule information which is formed by combining a plurality of pieces of code rule information contained in the plurality of code rule tools is obtained and is used for code processing.
In an exemplary embodiment, step S102 may further include: acquiring a plurality of items of first code rule information to realize performance parameters of first code processing; target code rule information is determined from the plurality of items of first code rule information based on the performance parameter.
In this embodiment, the target code rule information may be one of the plurality of items of first code rule information for implementing the first code processing, which has the highest performance, may be one of the first code rule information with the highest efficiency of the executed first code processing, or may be one of the first code rule information with the highest degree of regularization of the executed first code processing. Taking the first code rule information for code formatting as an example, if the plurality of items of first code rule information are all code rule information for performing code formatting, the terminal may obtain a performance parameter for performing code formatting processing for each item of first code rule information, so as to compare the performance parameters of the plurality of items of first code rule information for performing code formatting functions, for example, the applicable range of each item of code rule information for performing code formatting, or the succinctness parameter of each item of code rule information configuration item for performing code formatting, or the accuracy of each item of code rule information for performing code formatting for code, etc., and the terminal may select the best first code rule information from the plurality of items of first code rule information as target code rule information according to the set performance parameters, so that the object code rule information has an optimal first code processing performance.
In this embodiment, the terminal may implement the performance parameter of the first code processing based on each piece of first code rule information, and select the first code rule information with the best performance as the target code rule information, so that the effectiveness of implementing the first code processing performance by the selected target code rule information may be ensured, and the effectiveness of implementing the code function by using the combined code rule information may be further improved.
In an exemplary embodiment, as shown in fig. 2, before step S103, the method may further include:
in step S201, first code processing tools to which first code rule information items other than the target code rule information belong are acquired.
The first code processing tool refers to a code processing tool to which other first code rule information than the object code rule information belongs, and generally, each item of first code rule information realizing the same first code processing function is from a different code processing tool, so that after the terminal determines the object code rule information, the terminal can determine the code processing tool from which the other first code rule information than the object code rule information belongs as the first code processing tool. For example, the code rule information a in the first code rule information is from a code processing tool a, the code rule information B is from a code processing tool B, and the code rule information C is from a code processing tool C, and if the terminal selects the code processing information B as the target code rule information, the terminal may use the code processing tool a and the code processing tool C as the first code processing tool.
In step S202, for each first code processing tool, the first code rule information included in the first code processing tool is disabled, and the code rule information that is not disabled is used as the second code rule information included in the first code processing tool.
Since some second code rule information may be originated from the first code processing tool, the terminal may disable the first code rule information included in the first code processing tool in a disabled manner, and use the code rule information that is not disabled in the first code processing tool as the second code rule information included in the first code processing tool. For example, when code rule information a for realizing the first code process and code rule information D for realizing the second code process are included in the code rule tool a together with other code rule information and the code rule information a is not target code rule information, the terminal may disable the code rule information a and retain the code rule information D as the second code rule information included in the first code process tool.
In this embodiment, a combination of a plurality of pieces of code rule information for implementing different code processing functions may be implemented by disabling the first code rule information included in the first code processing tool, so that it is ensured that the combined code rule information may include all pieces of code rule information for implementing different code processing functions in the plurality of code processing tools, and the integrity of the combined code rule information is improved.
Further, as shown in fig. 3, step S103 may further include:
in step S301, second code rule information associated with the target code rule information is specified as candidate rule information from the second code rule information included in the first code rule tool.
The candidate rule information refers to code rule information having an association relationship with target code rule information in the second code rule information, the association relationship may refer to an association relationship between a second code processing function that can be realized by the second code rule information and a first code rule function that can be realized by the target code rule information, and the candidate rule information may be second code rule information directly spliced with the first code rule information in a certain first code processing tool.
For example, a certain first code processing tool a may be composed of code rule information a, code rule information B, and code rule information C, which are sequentially merged together, wherein the code rule information C is first code rule information for implementing the same first code processing function from among code rule information included in other code processing tools, and the corresponding target code rule information may be code rule information D provided by other code rule tools, and since both the code rule information D and the code rule information C are used for implementing the first code processing function, and the code rule information B is directly merged with the code rule information C, the terminal may determine the code rule information B as second code rule information associated with the target code rule information D from second code rule information included in the first code processing tool, that is, the code rule information a and the code rule information B, i.e. candidate rule information.
In step S302, a corresponding target plug-in is generated based on the target code rule information, and the calling information for calling the target plug-in is configured for the candidate rule information, so as to obtain the combined code rule information.
And then, the terminal can combine the candidate rule information with the target code rule information in a plug-in form, specifically, a corresponding plug-in can be generated based on the target code rule information to serve as a target plug-in, the target plug-in is combined with the second code rule information contained in the first code processing tool, calling information for the target plug-in is configured for the candidate rule information in the second code rule information, and then combined code rule information is obtained, so that after the terminal performs second code processing on the code through the candidate rule information, the terminal can perform further first code processing on the code by using the target code rule information in a mode of calling the target plug-in, and the code processing is completed through the combined code rule information.
In the embodiment, the terminal can call the target code rule information in a plug-in mode, so that the combination of code rule information among cross-tools is realized, and the convenience of code rule information combination is improved.
In an exemplary embodiment, as shown in fig. 4, after step S103, the method may further include:
in step S401, tool configuration information of each code processing tool corresponding to the combined code rule information is acquired through a configuration file interface reserved in the combined code rule information.
In this embodiment, in order to meet personalized requirements of different users, after the terminal combines the code rule information included in the plurality of code processing tools into corresponding combined code rule information, a corresponding configuration file interface may be further reserved for the combined code rule information, and when a user needs to modify the tool configuration information corresponding to the code processing tool, the user may obtain the tool configuration information of each code processing tool by calling the configuration file interface.
In step S402, edit information for one or more of the tool configuration information is acquired, the corresponding tool configuration information is updated with the edit information, and the combination code rule information is updated based on the updated tool configuration information.
Then, the user may edit one or more pieces of tool configuration information in the tool configuration information of the code processing tool obtained by the terminal in step S401 as needed, so that the terminal may obtain the edit information edited by the user for the tool configuration information, and update the corresponding tool configuration information by using the edit information, thereby updating the combined code rule information by using the updated tool configuration information.
For example: through a configuration file interface, the configuration information of a plurality of code rule tools is exported in a js file form, and the configuration right of the code processing tool is given to a user so as to meet the customized requirement of the user.
In this embodiment, after obtaining the combined code rule information, the terminal may further reserve a configuration file interface for the combined code rule information, so that a user may obtain tool configuration information corresponding to each code processing tool through the configuration file interface, and edit the tool configuration information to update the combined code rule information, thereby implementing customized update of the combined code rule information, and meeting requirements of different users.
In addition, in an exemplary embodiment, the first code process includes a code formatting process, the first code specification information being for implementing the code formatting process; the second code process includes a code quality check process, and the second code rule information is used to implement the code quality check process.
In this embodiment, the first code rule information for implementing the same first code processing function may be rule information for performing formatting processing on a code, and the second code rule information for implementing the second code processing function may be rule information for performing code quality check processing on a code, and therefore, the process of processing the code to be processed in this embodiment may include: a formatting process for formatting the code to be processed, a non-formatting process for checking the quality of the code to be processed, and so on.
In this embodiment, if the first code rule information that realizes the same first code processing function belongs to the rule information for formatting the code, the terminal may perform the unformatted code quality inspection processing using the second code rule information, and perform the formatting processing of the code using the target code rule information, so that the code processing may be performed using the optimal processing method of the code quality inspection processing and the formatting processing at the same time, and the normalization of the obtained code is improved.
Further, as shown in fig. 5, the step S104 may further include:
in step S501, a code quality check process is performed on the code to be processed based on the second code rule information in the combined code rule information.
In this embodiment, the code processing flow is to perform code quality check on the code to be processed first and then perform formatting processing, and since the second code rule information is the code rule information for implementing the code quality check, the terminal can perform the code quality check processing on the code to be processed through the second code rule information after obtaining the code to be processed.
In step S502, after the code quality check processing is completed, code formatting processing is performed on the code subjected to the code quality check processing based on the target code rule information in the combined code rule information, resulting in a processed code.
Then, since the target code rule information and the first code rule information are both code rule information for implementing code formatting processing, the terminal may perform formatting processing on the code to be processed after the code quality inspection processing by using the target code rule information included in the combined code rule information, so as to obtain the processed code.
In this embodiment, after the combined code rule information is obtained, the code quality inspection processing may be performed on the code to be processed, which needs to be processed, through the second code rule information, and after the code quality inspection processing is completed, the code after the code quality inspection processing is further formatted by using the target code rule information, so that the code normalization processing may be performed on the code to be processed, and a more standard processed code is obtained.
In an exemplary embodiment, there is also provided a method of integrating code processing tools, the code processing tools requiring integration may include: ESLint for finding and repairing problems in JavaScript code, StyleLint for finding and repairing problems in CSS style code, Prettier for focusing on code formatting, Husky for preventing irregular commit, push and other operations, Lint-staged for running lines on git scratch files, and Committet for checking whether submitted commit msg meets the convention rules. As shown in fig. 6, eslin and StyleLint both have definitions of formatting, and directly use the rule that two parts of formatting must be defined repeatedly, and Prettier only focuses on formatting, if three parts are integrated, the formatted configuration will appear in three parts, so that some code conflicts will be encountered when integrating the above tools.
Therefore, in order to avoid the code conflict, the present embodiment may implement integration of the code processing tool by the following technical means, and specifically may include the following steps:
1. taking a configuration file of a Prettier as a landing point, firstly defining a uniform formatting rule, namely the target code rule information, and then respectively disabling conflicting formatting rules in ESLint and StyleLint, namely all first code rule information except the target code rule information;
in this embodiment, because Prettier is a tool dedicated to code formatting, it can format all types of files, and compared with esline, which can only format JavaScript codes, and StyleLint, which can only format CSS style codes, Prettier tool has a better formatting capability, and therefore, code rule information for implementing a code formatting function in Prettier tool is used as target code rule information.
2. Utilizing plug-in mechanisms of ESLint and StyleLint to enable preter to become a plug-in of the ESLint and the StyleLint respectively, calling the preter plug-in to complete one-time formatting after finishing the quality check of JavaScript and CSS styles respectively, wherein the quoted rule is a default formatting rule uniformly defined in the previous step, eliminating conflicting formatting rules through disabled, and simultaneously placing the preter configuration at the end of an extensions array to realize the coverage of the same rule in the ESLint;
3. through the first two steps, the ESLint, the StyleLint and the Prettier are perfectly combined together, the ESLint and the StyleLint are focused on the quality inspection of JS and CSS, and the code formatting work of all files is finished by the Prettier;
4. further integrating Husky, Lint-staged and Commitling, forcibly finishing one-time quality check and formatting before commit by means of a Git life cycle hook function, finishing the formatting check of the submitted message at commit, and enabling commit to be successful after the two steps are passed;
5. the principle of inheritance and overloading is adopted, the configuration information of the six tools is exported in a js file form, and the configuration right is given to a user so as to meet the customized requirement of the user.
In the method for integrating the code processing tools provided by the embodiment, conflicts among a plurality of main tools are smoothed, so that the main tools respectively exert the advantages of the fields, and are finally integrated into a unified dependency package, thereby efficiently solving the problem of unified code rules among a plurality of projects in a team. All projects realize the unification of code rules among projects by accessing the dependency package of the embodiment, realize the quality check and formatting of JS and CSS and the optimal solution of submitting message format check simultaneously by grinding rule conflict among tools, and provide the customization capability on the basis of default code rules by accessing the unified dependency package and postpositing a large number of third party dependencies, simplifying the project codes and exposing a configuration file interface.
It should be understood that although the various steps in the flow charts of fig. 1-5 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 1-5 may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed in turn or alternately with other steps or at least some of the other steps.
FIG. 7 is a block diagram illustrating a code processing apparatus according to an example embodiment. Referring to fig. 7, the apparatus includes a first rule acquisition unit 701, a target rule acquisition unit 702, a combination rule acquisition unit 703, and a code processing unit 704.
A first rule obtaining unit 701 configured to perform obtaining, from code rule information included in a plurality of code processing tools, a plurality of items of first code rule information that are used for implementing a first code process between different code processing tools, the plurality of items of first code rule information belonging to different code processing tools, respectively;
a target rule obtaining unit 702 configured to perform determining target code rule information from a plurality of items of first code rule information;
a combination rule obtaining unit 703 configured to perform combining the target code rule information and second code rule information included in the plurality of code processing tools to obtain combination code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools, and the second code rule information is used for realizing second code processing;
and a code processing unit 704 configured to execute processing on the code to be processed based on the combined code rule information, resulting in a processed code.
In an exemplary embodiment, the target rule obtaining unit 702 is further configured to perform obtaining a plurality of items of first code rule information to realize performance parameters of the first code processing; target code rule information is determined from the plurality of items of first code rule information based on the performance parameter.
In an exemplary embodiment, the code rule information processing apparatus further includes: a second rule obtaining unit configured to execute each first code processing tool to which each item of first code rule information other than the target code rule information belongs; and for each first code processing tool, forbidding the first code rule information contained in the first code processing tool, and using the code rule information which is not forbidden as the second code rule information contained in the first code processing tool.
In an exemplary embodiment, the combination rule obtaining unit 703 is further configured to determine, from the second code rule information included in the first code rule tool, second code rule information associated with the target code rule information as candidate rule information; and generating a corresponding target plug-in based on the target code rule information, and configuring calling information for calling the target plug-in for the candidate rule information to obtain combined code rule information.
In an exemplary embodiment, the code rule information processing apparatus further includes: the configuration information updating unit is configured to execute the configuration file interface reserved in the combined code rule information to acquire tool configuration information of each code processing tool corresponding to the combined code rule information; acquiring editing information aiming at one or more pieces of tool configuration information, updating the corresponding tool configuration information by using the editing information, and updating the combination code rule information based on the updated tool configuration information.
In an exemplary embodiment, the first code process includes a code formatting process, the first code specification information being for implementing the code formatting process; the second code process includes a code quality check process, and the second code rule information is used to implement the code quality check process.
In an exemplary embodiment, the code processing unit 704 is further configured to perform a code quality check process on the code to be processed based on the second code rule information in the combined code rule information; and after the code quality inspection processing is finished, performing code formatting processing on the code subjected to the code quality inspection processing based on target code rule information in the combined code rule information to obtain a processed code.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Fig. 8 is a block diagram illustrating an apparatus 800 for code rule information processing or for code processing according to an example embodiment. For example, the device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a gaming console, a tablet device, a medical device, a fitness device, a personal digital assistant, and so forth.
Referring to fig. 8, device 800 may include one or more of the following components: processing component 802, memory 804, power component 806, multimedia component 808, audio component 810, input/output (I/O) interface 812, sensor component 814, and communication component 816.
The processing component 802 generally controls overall operation of the device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operation at the device 800. Examples of such data include instructions for any application or method operating on device 800, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 804 may be implemented by any type or combination of volatile or non-volatile storage devices, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power component 806 provides power to the various components of the device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 800.
The multimedia component 808 includes a screen that provides an output interface between the device 800 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front facing camera and/or a rear facing camera. The front-facing camera and/or the rear-facing camera may receive external multimedia data when the device 800 is in an operating mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the device 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 814 includes one or more sensors for providing various aspects of state assessment for the device 800. For example, the sensor assembly 814 may detect the open/closed state of the device 800, the relative positioning of components, such as a display and keypad of the device 800, the sensor assembly 814 may also detect a change in the position of the device 800 or a component of the device 800, the presence or absence of user contact with the device 800, orientation or acceleration/deceleration of the device 800, and a change in the temperature of the device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
Communications component 816 is configured to facilitate communications between device 800 and other devices in a wired or wireless manner. The device 800 may access a wireless network based on a communication standard, such as WiFi, an operator network (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the device 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a computer-readable storage medium comprising instructions, such as the memory 804 comprising instructions, executable by the processor 820 of the device 800 to perform the above-described method is also provided. For example, the computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
In an exemplary embodiment, there is also provided a computer program product comprising a computer program which, when executed by a processor, implements the code rule information processing method as described in any one of the above embodiments, or the code processing method as described in any one of the above embodiments.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A code processing method, comprising:
acquiring a plurality of items of first code rule information which are used for realizing first code processing among different code processing tools from code rule information contained in the code processing tools, wherein the plurality of items of first code rule information belong to the different code processing tools respectively;
determining target code rule information from the plurality of items of first code rule information;
combining the target code rule information with second code rule information contained in the plurality of code processing tools to obtain combined code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools, and the second code rule information is used for realizing second code processing;
and processing the code to be processed based on the combined code rule information to obtain a processed code.
2. The method of claim 1, wherein determining target code rule information from the plurality of items of first code rule information comprises:
acquiring performance parameters for realizing the first code processing by the plurality of items of first code rule information;
target code rule information is determined from the plurality of items of first code rule information based on the performance parameter.
3. The method of claim 1, wherein prior to combining the target code rule information with second code rule information included in the plurality of code processing tools, further comprising:
acquiring various first code processing tools to which various first code rule information except the target code rule information belongs;
and for each first code processing tool, forbidding the first code rule information contained in the first code processing tool, and using the code rule information which is not forbidden as the second code rule information contained in the first code processing tool.
4. The method of claim 3, wherein combining the target code rule information and second code rule information included in the code processing tools to obtain combined code rule information corresponding to the code processing tools comprises:
determining second code rule information associated with the target code rule information from second code rule information contained in the first code processing tool as candidate rule information;
and generating a corresponding target plug-in based on the target code rule information, and configuring calling information for calling the target plug-in for the candidate rule information to obtain the combined code rule information.
5. The method of claim 1, wherein after obtaining the combined code rule information corresponding to the plurality of code processing tools, the method further comprises:
acquiring tool configuration information of each code processing tool corresponding to the combined code rule information through a configuration file interface reserved in the combined code rule information;
acquiring editing information aiming at one or more tool configuration information, updating corresponding tool configuration information by using the editing information, and updating the combined code rule information based on the updated tool configuration information.
6. The method of claim 1, wherein the first code process comprises a code formatting process, and wherein the first code rule information is used to implement the code formatting process; the second code process includes a code quality check process, and the second code rule information is used to implement the code quality check process.
7. A code processing apparatus, comprising:
a first rule obtaining unit configured to execute obtaining, from code rule information included in a plurality of code processing tools, a plurality of items of first code rule information for realizing a first code process between different code processing tools, the plurality of items of first code rule information belonging to the different code processing tools, respectively;
a target rule obtaining unit configured to perform determination of target code rule information from the plurality of items of first code rule information;
a combination rule obtaining unit configured to perform combination of the target code rule information and second code rule information included in the plurality of code processing tools to obtain combination code rule information corresponding to the plurality of code processing tools; the second code rule information is code rule information except the first code rule information contained in the plurality of code processing tools, and the second code rule information is used for realizing second code processing;
and the code processing unit is configured to execute processing on the code to be processed based on the combined code rule information to obtain a processed code.
8. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the code processing method of any one of claims 1 to 6.
9. A computer-readable storage medium, wherein instructions in the computer-readable storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method of any one of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that the computer program realizes the code processing method according to any one of claims 1 to 6 when executed by a processor.
CN202110856545.2A 2021-07-28 2021-07-28 Code processing method, device, electronic equipment and storage medium Active CN113535183B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110856545.2A CN113535183B (en) 2021-07-28 2021-07-28 Code processing method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110856545.2A CN113535183B (en) 2021-07-28 2021-07-28 Code processing method, device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113535183A true CN113535183A (en) 2021-10-22
CN113535183B CN113535183B (en) 2024-05-28

Family

ID=78121100

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110856545.2A Active CN113535183B (en) 2021-07-28 2021-07-28 Code processing method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113535183B (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB201107809D0 (en) * 2011-05-10 2011-06-22 Peri Bhaskar A method and apparatus for managing evaluation of computer program code
EP2388740A1 (en) * 2010-05-20 2011-11-23 Accenture Global Services Limited Rule merging in system for monitoring adherence by developers to a software code development process
CN106055980A (en) * 2016-05-30 2016-10-26 南京邮电大学 Rule-based JavaScript security testing method
CN109032949A (en) * 2018-08-02 2018-12-18 郑州悉知信息科技股份有限公司 A kind of front-end code quality determining method and device
CN109408101A (en) * 2018-09-12 2019-03-01 深圳点猫科技有限公司 A kind of code development maintaining method and electronic equipment for programming
CN112286532A (en) * 2020-10-31 2021-01-29 中环曼普科技(南京)有限公司 Method and system for realizing front-end code formatting based on ESLint and Prettier
CN112559354A (en) * 2020-12-18 2021-03-26 中国平安财产保险股份有限公司 Front-end code specification detection method and device, computer equipment and storage medium
CN113010157A (en) * 2021-03-08 2021-06-22 北京达佳互联信息技术有限公司 Code generation method and device

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2388740A1 (en) * 2010-05-20 2011-11-23 Accenture Global Services Limited Rule merging in system for monitoring adherence by developers to a software code development process
CN102253829A (en) * 2010-05-20 2011-11-23 埃森哲环球服务有限公司 Rule merging in system for monitoring adherence by developers to a software code development process
GB201107809D0 (en) * 2011-05-10 2011-06-22 Peri Bhaskar A method and apparatus for managing evaluation of computer program code
CN106055980A (en) * 2016-05-30 2016-10-26 南京邮电大学 Rule-based JavaScript security testing method
CN109032949A (en) * 2018-08-02 2018-12-18 郑州悉知信息科技股份有限公司 A kind of front-end code quality determining method and device
CN109408101A (en) * 2018-09-12 2019-03-01 深圳点猫科技有限公司 A kind of code development maintaining method and electronic equipment for programming
CN112286532A (en) * 2020-10-31 2021-01-29 中环曼普科技(南京)有限公司 Method and system for realizing front-end code formatting based on ESLint and Prettier
CN112559354A (en) * 2020-12-18 2021-03-26 中国平安财产保险股份有限公司 Front-end code specification detection method and device, computer equipment and storage medium
CN113010157A (en) * 2021-03-08 2021-06-22 北京达佳互联信息技术有限公司 Code generation method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
杨冰娥: "代码规则自动化检查系统的设计与实现", 《万方数据》 *

Also Published As

Publication number Publication date
CN113535183B (en) 2024-05-28

Similar Documents

Publication Publication Date Title
EP3041204A1 (en) Method for prompting calling request and device for the same
CN104850643B (en) Picture comparison method and device
CN113238752A (en) Code generation method and device, electronic equipment and storage medium
CN107463372B (en) Data-driven page updating method and device
CN105183571A (en) Function calling method and device
CN111580824B (en) Program optimization method, device and storage medium
US9854559B2 (en) Method and device for pushing user information
CN115357626A (en) Data processing method, device, electronic equipment, medium and product
CN113535183B (en) Code processing method, device, electronic equipment and storage medium
CN113919311A (en) Data display method and device, electronic equipment and storage medium
CN110457084B (en) Loading method and device
CN110489155B (en) Data file management method, device, electronic equipment and medium
CN112631695A (en) Data verification method and device, electronic equipment and storage medium
CN113934452B (en) Data processing method and device, electronic equipment and storage medium
CN114489641B (en) Data processing method and device, electronic equipment and storage medium
CN113778385B (en) Component registration method, device, terminal and storage medium
CN111767249B (en) Method and device for determining self-running time of function
CN111596949B (en) Method and device for developing application program
CN114661487A (en) Data processing method and device, electronic equipment and storage medium
CN113535242A (en) Pin Pin configuration method, device and storage medium
CN115422905A (en) Data splitting method and device, electronic equipment, medium and product
CN115390911A (en) Node information determination method, device and equipment
CN113885938A (en) Code modification method and device, electronic equipment and storage medium
CN115937350A (en) Picture editing method and device, electronic equipment and storage medium
CN111862983A (en) Collaborative editing method, device, electronic equipment and medium

Legal Events

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