CN111061488A - Method and device for detecting quality of front-end code, computer equipment and storage medium - Google Patents

Method and device for detecting quality of front-end code, computer equipment and storage medium Download PDF

Info

Publication number
CN111061488A
CN111061488A CN201911310711.8A CN201911310711A CN111061488A CN 111061488 A CN111061488 A CN 111061488A CN 201911310711 A CN201911310711 A CN 201911310711A CN 111061488 A CN111061488 A CN 111061488A
Authority
CN
China
Prior art keywords
code
codes
variable
detecting
detecting whether
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.)
Pending
Application number
CN201911310711.8A
Other languages
Chinese (zh)
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.)
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Original Assignee
Shenzhen Qianhai Huanrong Lianyi Information Technology Service 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 Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd filed Critical Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority to CN201911310711.8A priority Critical patent/CN111061488A/en
Publication of CN111061488A publication Critical patent/CN111061488A/en
Pending legal-status Critical Current

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/43Checking; Contextual analysis

Landscapes

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

Abstract

The invention relates to a method, a device, computer equipment and a storage medium for detecting the quality of a front-end code, wherein the method comprises the following steps: acquiring a code to be compiled and run; sequentially retrieving the codes by taking the single-line codes as a single retrieval target to obtain retrieval information of the codes; and detecting whether the code conforms to a preset standard or not according to the retrieval information, and modifying the code according to the preset standard when the code does not conform to the preset standard so as to enable the modified code to conform to the preset standard. The method comprises the steps of acquiring codes to be compiled and run, sequentially retrieving the codes by taking a single line of codes as a single retrieval target, detecting whether the codes conform to a preset specification after retrieval, modifying the codes according to the preset specification after non-specification codes are detected so that the modified codes conform to the preset specification, detecting the codes before compiling and running, finding code problems in time, further unifying code specifications and habits, avoiding low-level defects and ensuring the quality of the codes on line.

Description

Method and device for detecting quality of front-end code, computer equipment and storage medium
Technical Field
The present invention relates to the field of code detection, and more particularly, to a method, an apparatus, a computer device, and a storage medium for detecting the quality of a front-end code.
Background
In the process of project development, after a front-end code is developed, the front-end code generally needs to be directly called after simple debugging, and some codes have defects caused by non-standard codes after being combined or on-line.
Disclosure of Invention
The present invention is directed to overcome the drawbacks of the prior art, and provides a method, an apparatus, a computer device, and a storage medium for detecting the quality of a front-end code.
In a first aspect, the present invention provides a method for detecting the quality of a front-end code, comprising the following steps:
acquiring a code to be compiled and run;
sequentially retrieving the codes by taking the single-line codes as a single retrieval target to obtain retrieval information of the codes;
and detecting whether the code conforms to a preset standard or not according to the retrieval information, and modifying the code according to the preset standard when the code does not conform to the preset standard so as to enable the modified code to conform to the preset standard.
In a second aspect, the present invention provides an apparatus for detecting front-end code quality, including:
the code acquisition unit is used for acquiring a code to be compiled and run;
the code retrieval unit is used for sequentially retrieving the codes by taking a single line of codes as a single retrieval target so as to obtain retrieval information of the codes;
and the detection modification unit is used for detecting whether the code conforms to the preset specification or not according to the retrieval information, and modifying the code according to the preset specification when the code does not conform to the preset specification so as to enable the modified code to conform to the preset specification.
In a third aspect, the present invention provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the method for detecting the quality of the front-end code according to any one of the above when executing the computer program.
In a fourth aspect, the present invention provides a storage medium storing a computer program which, when executed by a processor, implements a method of detecting front-end code quality as described in any one of the above.
Compared with the prior art, the invention has the beneficial effects that: the method comprises the steps of acquiring codes to be compiled and run, sequentially retrieving the codes by taking a single line of codes as a single retrieval target, detecting whether the codes conform to a preset specification after retrieval, modifying the codes according to the preset specification after non-specification codes are detected so that the modified codes conform to the preset specification, detecting the codes before compiling and running, finding code problems in time, further unifying code specifications and habits, avoiding low-level defects and ensuring the quality of the codes on line.
The invention is further described below with reference to the accompanying drawings and specific embodiments.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic application scenario diagram of a method for detecting front-end code quality according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a method for detecting the quality of a front-end code according to an embodiment of the present invention;
FIG. 3 is a sub-flowchart of a method for detecting the quality of a front-end code according to an embodiment of the present invention;
FIG. 4 is a sub-flowchart of a method for detecting the quality of a front-end code according to an embodiment of the present invention;
FIG. 5 is a schematic block diagram of an apparatus for detecting front-end code quality according to an embodiment of the present invention;
fig. 6 is a schematic block diagram of a detection modification unit of an apparatus for detecting front-end code quality according to an embodiment of the present invention;
FIG. 7 is a schematic block diagram of a detection subunit of an apparatus for detecting front-end code quality according to an embodiment of the present invention;
FIG. 8 is a schematic block diagram of a variable detection subunit of an apparatus for detecting front-end code quality according to an embodiment of the present invention;
FIG. 9 is a schematic block diagram of a computer device provided by an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1 and fig. 2, fig. 1 is a schematic view of an application scenario of a method for detecting front-end code quality according to an embodiment of the present invention. Fig. 2 is a schematic flow chart of a method for detecting the quality of a front-end code according to an embodiment of the present invention. The method for detecting the quality of the front-end code is applied to a server, the server and a terminal carry out data interaction, the terminal uploads a code to be compiled and run to the server, the code is sequentially retrieved in the server by taking a single-row code as a single retrieval target, after the retrieval is finished, the server detects whether the code meets a preset standard, and when the code does not meet the preset standard, the code is modified according to the preset standard, so that the modified code meets the preset standard.
Fig. 2 is a flowchart illustrating a method for detecting front-end code quality according to an embodiment of the present invention. As shown in fig. 2, the method includes the following steps S110 to S150.
And S110, acquiring a code to be compiled and run.
In this embodiment, the whole process of compiling and running the code is probably: the developer writes the code (. java file), then compiles the code into byte code (. class file), then the byte code is loaded into the memory, once the byte code enters the virtual machine, the byte code is interpreted by the interpreter to be executed, or is selectively converted into machine code to be executed by the instant code generator, wherein the code compiling is completed by the source code compiler. Due to the difference between the development habit and the development specification of a developer, after the code is written, the code may have the problem of being out of specification or incapable of running. Therefore, the server obtains the code to be compiled and run, and the code to be compiled and run is used as a target of subsequent retrieval, so that errors existing in the code development process can be found in time, and the problem that the development efficiency and the code quality are influenced due to the errors generated in the compiling or running process of the code is avoided.
And S120, sequentially searching the codes by taking the single line of codes as a single searching target.
In this embodiment, a front page is formed after the code is written, and the code is arranged and displayed in a line form on the front page. Specifically, the front page is formed by combining a series of HTML tags, and all the tag styles and JS written on the front page need to conform to the standard specification of W3C (the W3C standard is a set of standards including three parts, namely structure, presentation and behavior, the structure is a page, the presentation is a CSS style, and the behavior is JS).
As for the HTML tag, specifically: HTML is a hypertext markup language, markup tags are commonly referred to as HTML tags; HTML tags are the most basic units in HTML language, and HTML tags are the most important components of HTML (an application under the standard universal markup language).
The code on the front-end page is searched line by line, so that the search information of the code can be obtained, the search information comprises the label information, the class naming information, the global variable statement information, the method function information, the variable information, the code annotation description information, the core code state information and the like of the code, and whether the code meets the preset specification can be further detected according to the search information.
S130, detecting whether the code conforms to the preset standard or not, and modifying the code according to the preset standard when the code does not conform to the preset standard so as to enable the modified code to conform to the preset standard.
In this embodiment, the preset specification may be preconfigured according to the code development specification and specific requirements, and then the codes are sequentially detected according to the preset specification, that is, the codes that do not meet the preset specification in the codes are obtained, and the corresponding codes are modified in time according to the preset specification, so that the codes are compiled and run subsequently and smoothly, thereby avoiding obvious low-level defects in the codes and ensuring the quality of the codes on line.
In one embodiment, step S130 includes step S131.
S131, detecting whether the label of the code is written normally, closed or not and whether the nesting standard is met or not.
In this embodiment, detecting whether the code meets the preset specification specifically includes detecting whether a label of the code writes the specification, whether the nesting is correct, and whether the label is closed. The specific criteria are as follows: detecting whether the writing standard of the label is the label and all the attributes are lowercase; detecting whether all elements of the label are correctly nested and meeting the nesting standard; detecting that a double tag must be closed, a single tag (self-closing tag) is not closed; and detecting whether a double quote attribute value is used, etc.
In one embodiment, step S130 includes step S132.
S132, detecting whether the class name of the code conforms to a large hump method.
In this embodiment, the class (class) is used to define the style in the front-end page, and the detecting whether the code meets the preset specification includes detecting whether the class name is named according to the { module _ element _ modifier } mode, and whether the file name conforms to the large hump naming method.
In one embodiment, step S130 includes step S133.
And S133, detecting whether the global variable statement of the code is correct.
In this embodiment, a variable is declared outside any function definition, then the variable is a global variable, and the value of the global variable can be accessed and modified throughout the persistence range. The declaration of the global variable is defined according to the required function, the assignment of similar money amounts is generally performed by using money, and if the declaration is performed by using var a ═ 0, where a represents the money amount, the money amount is wrong, and whether the declaration of the global variable is correct can be determined by comparing the declaration of the global variable with a preset specification.
In one embodiment, step S130 includes step S134.
And S134, detecting whether the code method function is multiplexed or not.
In this embodiment, detecting whether a code meets a preset specification includes detecting whether a method function in the code is multiplexed, multiplexing refers to whether multiple places exist for use, if one page or a plurality of pages use the function method, the method function is multiplexed, if the function method is not met with the preset specification, the method function needs to be written in a public method and moved to a public page, so that the whole project is convenient to call, and the same method function is prevented from being written in the code repeatedly.
In the retrieval process, the names of the method functions are counted, the counted times are the occurrence times, and if the occurrence times are more, the multiplexing is more.
Referring to FIG. 3, in one embodiment, step S134 includes steps S134a-S134 c.
S134a, obtaining the occurrence number of the method function in the code.
S134b, judging whether the occurrence frequency of the method function is larger than a preset value.
And S134c, if yes, writing the method function in a public method, and storing the written method function in a public page.
For steps S134a-S134c, the code on the front-end page is retrieved line by line, so that the retrieval information of the code can be obtained, the retrieval information includes method function information, the specific method function information includes data of the occurrence times of different method functions, the occurrence times of the statistical method functions are obtained, and it can be determined whether the method functions are multiplexed, when the method functions are multiplexed, a non-qualification is prompted, the method functions are written in a public method, and the written method functions are stored in a public page, so that the whole project is convenient to call, and the repeated writing of the code is avoided.
In one embodiment, step S130 includes step S135.
And S135, detecting whether the variables of the codes are multiplexed or not.
In this embodiment, when retrieving a code, statistics is performed on global variables and local variables, and if it is counted that a variable has been used only once, a local variable declaration may be used to prevent code exception, and a let command is preferentially used to declare a variable, so that the variable is only valid in a code block where the let command is located, and there is a constraint of a temporary dead zone.
Referring to FIG. 4, in one embodiment, step S135 includes steps S135a-S135 c.
S135a, obtaining the occurrence number of the variable declared in the code.
S135b, it is determined whether the number of occurrences of the variable is 1.
S135c, if yes, the variable is declared using the local variable so that the variable is valid only within the code block in which it is located.
For steps S135a-S135c, the code on the front-end page is searched line by line, so that the search information of the code can be obtained, the search information includes variable information, specifically, the variable information includes occurrence frequency data of different variables, the occurrence frequency of the statistical variable is obtained, and whether the occurrence frequency of the variable is 1 or not is judged, if the occurrence frequency is 1, the variable is declared by using a local variable, so that the variable is only valid in the code block where the variable is located.
In one embodiment, step S130 includes step S136.
S136, whether the comment explanation of the code is detected.
In one embodiment, step S130 includes step S137.
And S137, detecting whether the core codes are independent or not.
Specifically, detecting whether the code meets the preset specification includes detecting whether the code is annotated and explained, and detecting whether the core code is independent, wherein the code is annotated and explained, and the core code is independent, which is a guarantee that the code can be compiled and run smoothly.
In another embodiment, step S130 includes steps S131-S137, and steps S131-S137 are described in detail above and are not specifically discussed herein.
The method comprises the steps of acquiring codes to be compiled and run, sequentially retrieving the codes by taking a single line of codes as a single retrieval target, detecting whether the codes conform to a preset specification after retrieval, modifying the codes according to the preset specification after non-specification codes are detected so that the modified codes conform to the preset specification, detecting the codes before compiling and running, finding code problems in time, further unifying code specifications and habits, avoiding low-level defects and ensuring the quality of the codes on line.
Fig. 5 is a schematic block diagram of an apparatus for detecting front-end code quality according to an embodiment of the present invention. As shown in fig. 5, the present invention also provides an apparatus for detecting the quality of a front-end code, corresponding to the above method for detecting the quality of a front-end code. The apparatus for detecting the quality of the front-end code comprises a unit for executing the method for detecting the quality of the front-end code, and the apparatus can be configured in a desktop computer, a tablet computer, a portable computer, and the like. Specifically, referring to fig. 5, the apparatus for detecting front-end code quality includes a code obtaining unit 10, a code retrieving unit 20, and a detection modifying unit 30.
A code obtaining unit 10, configured to obtain a code to be compiled and run.
In this embodiment, the whole process of compiling and running the code is probably: the developer writes the code (. java file), then compiles the code into byte code (. class file), then the byte code is loaded into the memory, once the byte code enters the virtual machine, the byte code is interpreted by the interpreter to be executed, or is selectively converted into machine code to be executed by the instant code generator, wherein the code compiling is completed by the source code compiler. Due to the difference between the development habit and the development specification of a developer, after the code is written, the code may have the problem of being out of specification or incapable of running. Therefore, the server obtains the code to be compiled and run, and the code to be compiled and run is used as a target of subsequent retrieval, so that errors existing in the code development process can be found in time, and the problem that the development efficiency and the code quality are influenced due to the errors generated in the compiling or running process of the code is avoided.
And the code retrieval unit 20 is used for sequentially retrieving the codes by taking a single line of codes as a single retrieval target so as to obtain retrieval information of the codes.
In this embodiment, a front page is formed after the code is written, and the code is arranged and displayed in a line form on the front page. Specifically, the front page is formed by combining a series of HTML tags, and all the tag styles and JS written on the front page need to conform to the standard specification of W3C (the W3C standard is a set of standards including three parts, namely structure, presentation and behavior, the structure is a page, the presentation is a CSS style, and the behavior is JS).
As for the HTML tag, specifically: HTML is a hypertext markup language, markup tags are commonly referred to as HTML tags; HTML tags are the most basic units in HTML language, and HTML tags are the most important components of HTML (an application under the standard universal markup language).
The code on the front-end page is searched line by line, so that the search information of the code can be obtained, the search information comprises the label information, the class naming information, the global variable statement information, the method function information, the variable information, the code annotation description information, the core code state information and the like of the code, and whether the code meets the preset specification can be further detected according to the search information.
And a detection modification unit 30, configured to detect whether the code meets a preset specification according to the search information, and modify the code according to the preset specification when the code does not meet the preset specification, so that the modified code meets the preset specification.
In this embodiment, the preset specification may be preconfigured according to the code development specification and specific requirements, and then the codes are sequentially detected according to the preset specification, that is, the codes that do not meet the preset specification in the codes are obtained, and the corresponding codes are modified in time according to the preset specification, so that the codes are compiled and run subsequently and smoothly, thereby avoiding obvious low-level defects in the codes and ensuring the quality of the codes on line.
In one embodiment, as shown in fig. 6, the detection modification unit 30 includes a tag detection subunit 31, a tag detection subunit 32, a declaration detection subunit 33, a method detection subunit 34, a variable detection subunit 35, a comment detection subunit 36, and a code detection subunit 37.
And the label detection subunit 31 is used for detecting whether the label of the code is written regularly, closed or not and whether the nesting standard is met or not.
In this embodiment, detecting whether the code meets the preset specification specifically includes detecting whether a label of the code writes the specification, whether the nesting is correct, and whether the label is closed. The specific criteria are as follows: detecting whether the writing standard of the label is the label and all the attributes are lowercase; detecting whether all elements of the label are correctly nested and meeting the nesting standard; detecting that a double tag must be closed, a single tag (self-closing tag) is not closed; and detecting whether a double quote attribute value is used, etc.
And the label detection subunit 32 is used for detecting whether the class name of the code conforms to a large hump method.
In this embodiment, the class (class) is used to define the style in the front-end page, and the detecting whether the code meets the preset specification includes detecting whether the class name is named according to the { module _ element _ modifier } mode, and whether the file name conforms to the large hump naming method.
A declaration detecting subunit 33, configured to detect whether a global variable declaration of the code is correct.
In this embodiment, a variable is declared outside any function definition, then the variable is a global variable, and the value of the global variable can be accessed and modified throughout the persistence range. The declaration of the global variable is defined according to the required function, the assignment of similar money amounts is generally performed by using money, and if the declaration is performed by using var a ═ 0, where a represents the money amount, the money amount is wrong, and whether the declaration of the global variable is correct can be determined by comparing the declaration of the global variable with a preset specification.
A method detection subunit 34 for detecting whether a method function of the code is multiplexed.
In this embodiment, detecting whether a code meets a preset specification includes detecting whether a method function in the code is multiplexed, multiplexing refers to whether multiple places exist for use, if one page or a plurality of pages use the function method, the method function is multiplexed, if the function method is not met with the preset specification, the method function needs to be written in a public method and moved to a public page, so that the whole project is convenient to call, and the same method function is prevented from being written in the code repeatedly.
In the retrieval process, the names of the method functions are counted, the counted times are the occurrence times, and if the occurrence times are more, the multiplexing is more.
Referring to fig. 7, the method detection subunit 34 includes a method acquisition module 341, a second judgment module 342, and a method modification module 343.
A method obtaining module 341, configured to obtain the number of occurrences of the method function in the code;
a second determining module 342, configured to determine whether the occurrence number of the method function is greater than a preset value;
and a method modifying module 343, configured to write the method function in a public method and store the written method function in a public page if the occurrence frequency of the method function is greater than a preset value.
For the method obtaining module 341, the second determining module 342, and the method modifying module 343, the code on the front-end page is retrieved line by line, the retrieval information of the code can be obtained, the retrieval information includes method function information, the specific method function information includes occurrence frequency data of different method functions, the occurrence frequency of the statistical method function is obtained, whether the method function is multiplexed or not can be determined, when the method function is multiplexed, a non-qualification is prompted, the method function is written in a public method, and the written method function is stored in a public page, which facilitates the whole project call and avoids the repeated writing of the code.
And the variable detection subunit 35 is used for detecting whether the variables of the codes are multiplexed or not.
In this embodiment, when retrieving a code, statistics is performed on global variables and local variables, and if it is counted that a variable has been used only once, a local variable declaration may be used to prevent code exception, and a let command is preferentially used to declare a variable, so that the variable is only valid in a code block where the let command is located, and there is a constraint of a temporary dead zone.
Referring to fig. 8, in one embodiment, the variable detecting subunit 35 includes a variable acquiring module 351, a first judging module 352, and a variable declaring module 353.
The variable obtaining module 351 is configured to obtain the occurrence number of the declared variable in the code.
The first determining module 352 is configured to determine whether the occurrence number of the variable is 1.
And the variable declaration module 353 is used for declaring the variable by using the local variable when the occurrence number of the variable is 1, so that the variable is valid only in the code block where the variable is located.
For the variable obtaining module 351, the first judging module 352 and the variable declaring module 353, the code on the front-end page is searched line by line, so that the search information of the code can be obtained, the search information includes variable information, specifically, the variable information includes occurrence frequency data of different variables, the occurrence frequency of the statistical variable is obtained, whether the occurrence frequency of the variable is 1 or not is judged, if yes, the local variable is used for declaring the variable, so that the variable is only valid in the code block where the variable is located.
And an annotation detection subunit 36, configured to detect whether the code annotates the description.
A code detection subunit 37, configured to detect whether the core code is independent.
In this embodiment, detecting whether the code meets the preset specification includes detecting whether the code is annotated and describing, and detecting whether the core code is independent, wherein the code annotation and description are the guarantee that the core code is independent and the code can be compiled and run smoothly.
The method comprises the steps of acquiring codes to be compiled and run, sequentially retrieving the codes by taking a single line of codes as a single retrieval target, detecting whether the codes conform to a preset specification after retrieval, modifying the codes according to the preset specification after non-specification codes are detected so that the modified codes conform to the preset specification, detecting the codes before compiling and running, finding code problems in time, further unifying code specifications and habits, avoiding low-level defects and ensuring the quality of the codes on line.
It should be noted that, as can be clearly understood by those skilled in the art, the specific implementation process of the apparatus for detecting front-end code quality and each unit may refer to the corresponding description in the foregoing method embodiment, and for convenience and brevity of description, no further description is provided herein.
Referring to fig. 9, fig. 9 is a schematic block diagram of a computer device according to an embodiment of the present application. The computer device 500 may be a terminal or a server, where the terminal may be an electronic device with a communication function, such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, and a wearable device. The server may be an independent server or a server cluster composed of a plurality of servers.
Referring to fig. 9, the computer device 500 includes a processor 502, memory, and a network interface 505 connected by a system bus 501, where the memory may include a non-volatile storage medium 503 and an internal memory 504.
The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032 comprises program instructions that, when executed, cause the processor 502 to perform a method of detecting front-end code quality.
The processor 502 is used to provide computing and control capabilities to support the operation of the overall computer device 500.
The internal memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503, and when the computer program 5032 is executed by the processor 502, the processor 502 can be caused to perform a method for detecting the quality of the front-end code.
The network interface 505 is used for network communication with other devices. Those skilled in the art will appreciate that the configuration shown in fig. 9 is a block diagram of only a portion of the configuration associated with the present application and does not constitute a limitation of the computer device 500 to which the present application may be applied, and that a particular computer device 500 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
Wherein the processor 502 is adapted to run a computer program 5032 stored in the memory.
It should be understood that, in the embodiment of the present Application, the Processor 502 may be a Central Processing Unit (CPU), and the Processor 502 may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, and the like. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will be understood by those skilled in the art that all or part of the flow of the method implementing the above embodiments may be implemented by a computer program instructing associated hardware. The computer program includes program instructions, and the computer program may be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the flow steps of the embodiments of the method described above.
Accordingly, the present invention also provides a storage medium. The storage medium may be a computer-readable storage medium.
The storage medium may be a usb disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk, which can store various computer readable storage media.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative. For example, the division of each unit is only one logic function division, and there may be another division manner in actual implementation. For example, various elements or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented.
The steps in the method of the embodiment of the invention can be sequentially adjusted, combined and deleted according to actual needs. The units in the device of the embodiment of the invention can be merged, divided and deleted according to actual needs. In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a terminal, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A method for detecting front-end code quality, comprising the steps of:
acquiring a code to be compiled and run;
sequentially retrieving the codes by taking the single-line codes as a single retrieval target to obtain retrieval information of the codes;
and detecting whether the code conforms to a preset standard or not according to the retrieval information, and modifying the code according to the preset standard when the code does not conform to the preset standard so as to enable the modified code to conform to the preset standard.
2. The method for detecting the quality of the front-end code according to claim 1, wherein the step of detecting whether the code meets the preset specification according to the search information, and modifying the code according to the preset specification when the code does not meet the preset specification, so that the modified code meets the preset specification, comprises:
detecting whether a label of the code is written normally, closed and meets a nesting standard;
detecting whether class naming of the code conforms to a large hump method;
detecting whether the global variable statement of the code is correct;
detecting whether the method function of the code is multiplexed or not;
detecting whether the variables of the codes are multiplexed or not;
detecting whether the code annotates the description;
it is detected whether the core code is independent.
3. The method for detecting front-end code quality according to claim 1, wherein the step of detecting whether the variables of the code are multiplexed comprises:
acquiring the occurrence times of declared variables in the code;
judging whether the occurrence frequency of the variable is 1 or not;
if so, a local variable is used to declare the variable so that the variable is valid only within the code block in which it resides.
4. The method of claim 1, wherein the step of detecting whether the method function of the code is multiplexed comprises:
acquiring the occurrence times of method functions in the codes;
judging whether the occurrence frequency of the method function is greater than a preset value or not;
and if so, writing the method function in a public method, and storing the written method function in a public page.
5. An apparatus for detecting front-end code quality, comprising:
the code acquisition unit is used for acquiring a code to be compiled and run;
the code retrieval unit is used for sequentially retrieving the codes by taking a single line of codes as a single retrieval target so as to obtain retrieval information of the codes;
and the detection modification unit is used for detecting whether the code conforms to the preset specification or not according to the retrieval information, and modifying the code according to the preset specification when the code does not conform to the preset specification so as to enable the modified code to conform to the preset specification.
6. The apparatus for detecting front-end code quality according to claim 5, wherein said detection modification unit comprises a tag detection subunit, a declaration detection subunit, a method detection subunit, a variable detection subunit, a comment detection subunit, and a code detection subunit;
the label detection subunit is used for detecting whether a label of the code is written in a standard way, closed or not and whether the label meets a nesting standard or not;
the label detection subunit is used for detecting whether the class name of the code conforms to a large hump method;
the statement detection subunit is used for detecting whether the global variable statement of the code is correct or not;
the method detection subunit is used for detecting whether the method function of the code is multiplexed or not;
the variable detection subunit is used for detecting whether the variable of the code is multiplexed or not;
the comment detection subunit is used for detecting whether the code is annotated or not;
and the code detection subunit is used for detecting whether the core codes are independent or not.
7. The apparatus for detecting front-end code quality according to claim 5, wherein the variable detecting subunit includes a variable obtaining module, a first judging module and a variable declaring module;
the variable acquisition module is used for acquiring the occurrence times of the declared variables in the codes;
the first judging module is used for judging whether the occurrence frequency of the variable is 1 or not;
and the variable declaration module is used for declaring the variable by using a local variable when the occurrence frequency of the variable is 1, so that the variable is only valid in the code block where the variable is located.
8. The apparatus for detecting front-end code quality according to claim 5, wherein the method detection subunit includes a method acquisition module, a second judgment module and a method modification module;
the method acquisition module is used for acquiring the occurrence times of the method functions in the codes;
the second judging module is used for judging whether the occurrence frequency of the method function is greater than a preset value or not;
and the method modification module is used for writing the method function in a public method and storing the written method function in a public page when the occurrence frequency of the method function is larger than a preset value.
9. A computer arrangement, characterized in that the computer arrangement comprises a memory having stored thereon a computer program and a processor implementing the method of detecting front-end code quality according to any of claims 1-4 when executing the computer program.
10. A storage medium, characterized in that the storage medium stores a computer program which, when executed by a processor, implements a method of detecting front-end code quality as claimed in any one of claims 1 to 4.
CN201911310711.8A 2019-12-18 2019-12-18 Method and device for detecting quality of front-end code, computer equipment and storage medium Pending CN111061488A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911310711.8A CN111061488A (en) 2019-12-18 2019-12-18 Method and device for detecting quality of front-end code, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911310711.8A CN111061488A (en) 2019-12-18 2019-12-18 Method and device for detecting quality of front-end code, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN111061488A true CN111061488A (en) 2020-04-24

Family

ID=70302283

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911310711.8A Pending CN111061488A (en) 2019-12-18 2019-12-18 Method and device for detecting quality of front-end code, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111061488A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113312152A (en) * 2021-06-25 2021-08-27 上海华瑞银行股份有限公司 Method and device for automatically creating private cloud release task and electronic equipment
CN113703736A (en) * 2021-08-31 2021-11-26 四川启睿克科技有限公司 Web project code optimization method
CN113946340A (en) * 2021-09-30 2022-01-18 北京五八信息技术有限公司 Code processing method and device, electronic equipment and storage medium
CN114489756A (en) * 2022-01-29 2022-05-13 建信金融科技有限责任公司 Code quality evaluation method, device and equipment and readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050066319A1 (en) * 2003-09-22 2005-03-24 Deline Robert Anthony Persisted specifications of method pre-and post-conditions for static checking
CN109032949A (en) * 2018-08-02 2018-12-18 郑州悉知信息科技股份有限公司 A kind of front-end code quality determining method and device
CN109857641A (en) * 2018-12-29 2019-06-07 北京奇安信科技有限公司 The method and device of defects detection is carried out to program source file
CN110309050A (en) * 2019-05-22 2019-10-08 深圳壹账通智能科技有限公司 Detection method, device, server and the storage medium of code specification

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050066319A1 (en) * 2003-09-22 2005-03-24 Deline Robert Anthony Persisted specifications of method pre-and post-conditions for static checking
CN109032949A (en) * 2018-08-02 2018-12-18 郑州悉知信息科技股份有限公司 A kind of front-end code quality determining method and device
CN109857641A (en) * 2018-12-29 2019-06-07 北京奇安信科技有限公司 The method and device of defects detection is carried out to program source file
CN110309050A (en) * 2019-05-22 2019-10-08 深圳壹账通智能科技有限公司 Detection method, device, server and the storage medium of code specification

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113312152A (en) * 2021-06-25 2021-08-27 上海华瑞银行股份有限公司 Method and device for automatically creating private cloud release task and electronic equipment
CN113703736A (en) * 2021-08-31 2021-11-26 四川启睿克科技有限公司 Web project code optimization method
CN113946340A (en) * 2021-09-30 2022-01-18 北京五八信息技术有限公司 Code processing method and device, electronic equipment and storage medium
CN114489756A (en) * 2022-01-29 2022-05-13 建信金融科技有限责任公司 Code quality evaluation method, device and equipment and readable storage medium

Similar Documents

Publication Publication Date Title
CN111061488A (en) Method and device for detecting quality of front-end code, computer equipment and storage medium
US7321988B2 (en) Identifying a code library from the subset of base pointers that caused a failure generating instruction to be executed
CN110741354B (en) Presenting differences between code entity calls
US7240340B2 (en) System and method for browse information parsing without compilation
CN100405294C (en) System, method and program product to optimize code during run time
CN108762743B (en) Data table operation code generation method and device
US8719797B2 (en) System and method for debugging dynamically generated code of an application
CN109313547B (en) Query optimizer for CPU utilization and code reformulation
US9424168B2 (en) System and method for automatic generation of software test
US20140006010A1 (en) Parsing rules for data
WO2005055051A2 (en) Determining the possibility of adverse effects arising from a code change
WO2018161509A1 (en) Conditional compilation preprocessing method, terminal and storage medium
CN109917978B (en) BiM model-based annotation corresponding component display method and device and storage device
CN111679976A (en) Method and device for searching page object
JP2005301859A (en) Code search program and device
US10282398B1 (en) Editing tool for domain-specific objects with reference variables corresponding to preceding pages
CN115599359A (en) Code generation method, device, equipment and medium
CN111427577A (en) Code processing method and device and server
US20220206788A1 (en) Version control method for program project and associated electric device
CN110058849A (en) Generation method, device, computer equipment and the storage medium of flow chart
KR101767481B1 (en) Method and device for analyzing program
CN110347471B (en) Hierarchical display component system, display component calling method and device
CN112667502A (en) Page testing method, device and medium
CN111488144A (en) Data processing method and equipment
US11971807B2 (en) Software-development tool for presenting telemetry data with associated source code

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20200424