Visual front-end code quality detection method and device and computer storage medium
By converting front-end code into an abstract syntax tree and evaluating it using neural network models, the problem of lack of visual presentation of existing tools is solved, and the intuitive display and efficiency improvement of front-end code quality is achieved.
Patent Information
- Application Number
- CN202411406707.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-10
- Publication Date
- 2024-11-08
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing front-end code quality detection tools lack intuitive visualization methods, which makes it difficult for developers to quickly grasp the overall quality of the code, affecting the efficiency of code review and maintenance.
By converting the front-end code into an abstract syntax tree, static analysis is performed to generate a problem report, and input the code into the neural network model for quality evaluation, the quality detection results are displayed using a visual API.
It realizes intuitive visual display of front-end code quality, improves the efficiency and accuracy of code review, and improves the efficiency of code maintenance.
Smart Images

Figure CN118916296A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a visual front-end code quality detection method, device and computer storage medium. Background Art
[0002] In the field of front-end engineering, code quality testing is a key step to ensure that software products meet expected standards. Current front-end code quality testing tools, such as ESLint, Prettier, Stylelint, etc., can identify syntax errors, coding standard deviations, and potential logical defects in front-end code. However, these front-end code quality testing tools usually only provide quality reports in text form, lacking intuitive statistical charts and other visual means to display code quality problems, making it difficult for developers to quickly grasp the overall quality status of the code, which in turn affects the efficiency of code review and maintenance. Summary of the invention
[0003] The main purpose of this application is to provide a visual front-end code quality detection method, device and computer storage medium, aiming to solve the technical problem that front-end code quality detection tools lack intuitive visual display.
[0004] To achieve the above purpose, the present invention provides a visual front-end code quality detection method, which includes: Obtaining a front-end code to be tested, and converting the front-end code into an abstract syntax tree; Based on the abstract syntax tree, statically analyze the front-end code and generate a problem report; Inputting the front-end code into a neural network model to obtain quality assessment information and modification suggestions for the front-end code; Based on the problem report, the quality assessment information and the modification suggestion, a quality inspection result is obtained and displayed using a visualization API.
[0005] In one embodiment, the step of obtaining the front-end code to be detected and converting the front-end code into an abstract syntax tree includes: Extracting basic lexical units of the front-end code through a lexical analyzer; Combining the basic lexical units according to grammatical rules to form a grammatical structure that complies with the grammatical rules; The grammatical structure is mapped into nodes, the logical relationship of the grammatical structure is defined as edges, and an abstract syntax tree is constructed.
[0006] In one embodiment, the step of statically analyzing the front-end code and generating a problem report based on the abstract syntax tree includes: Traversing the abstract syntax tree and performing semantic analysis on each node of the abstract syntax tree; Identify all semantic errors during the traversal process, and associate and save the type, location, problem description, and repair suggestion of the problem corresponding to the semantic error into an error collection; After the traversal is completed, a problem report is output based on the information in the error set.
[0007] In one embodiment, before the step of performing semantic analysis on each node of the abstract syntax tree, the step includes: Establish a symbol table according to the identifiers in the front-end code and the declaration information corresponding to the identifiers, and save the symbol table; Constructing a scope chain to determine the scope level of each node in the abstract syntax tree; Define a type system, determine predefined types, user-defined types, and rules for conversion between the predefined types and the user-defined types; The semantic error is identified during the semantic analysis process based on the symbol table, the scope chain, and the type system.
[0008] In one embodiment, before the step of inputting the front-end code into the neural network model to obtain the quality assessment information and modification suggestions of the front-end code, the following steps are included: Obtaining text data of the front-end code and preprocessing the text data, wherein the preprocessing includes word segmentation, punctuation cleaning, and converting characters to lowercase format; Converting the preprocessed text data into a numerical vector through word embedding; or The preprocessed text data is converted into a numerical matrix using one-hot encoding.
[0009] In one embodiment, before the step of inputting the front-end code into the neural network model to obtain the quality assessment information and modification suggestions of the front-end code, the step further includes: Build a neural network model based on PyTorch; Dividing the preprocessed text data into a training set and a validation set, wherein the validation set includes detection results and modification suggestions for the preprocessed text data; Perform batch training using the training set, execute forward propagation to calculate the predicted output of the neural network model, and calculate the prediction error through a loss function; A back propagation algorithm is executed to adjust the weights of the neural network model according to the prediction error.
[0010] In one embodiment, after the step of executing the back propagation algorithm and adjusting the weight of the neural network model according to the prediction error, the following steps are performed: Running the neural network model on the validation set and outputting a prediction result; Comparing the predicted results with the actual results of the validation set, and evaluating the performance of the neural network model by calculating a performance evaluation index; Adjusting the parameters of the neural network model according to the results of the performance evaluation index to optimize the performance of the neural network model, the parameters including learning rate, batch size and network structure; The adjusted parameters of the neural network model are saved, and the trained neural network model is used to evaluate the quality of the front-end code.
[0011] In one embodiment, after the step of generating a visual quality inspection result based on the problem report, the quality assessment information and the modification suggestion, the following steps are included: Obtaining the modification record of the front-end code, and jumping to the step of obtaining the text data of the front-end code and preprocessing the text data; Marking the modification records of the preprocessed front-end code as training set data; When new training set data is generated, an incremental learning process is triggered to perform secondary training on the neural network model; After completing the incremental learning process, updating and saving the weights and parameters of the neural network model; Based on the updated neural network model, a quality assessment of the front-end code is performed.
[0012] An embodiment of the present application also provides a visual front-end code quality detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the visual front-end code quality detection method as described above.
[0013] An embodiment of the present application also provides a computer storage medium, which is a computer-readable storage medium. A computer program is stored on the computer storage medium. When the computer program is executed by a processor, the steps of the visual front-end code quality detection method described above are implemented.
[0014] The embodiment of the present application discloses a visual front-end code quality detection method, which obtains the front-end code to be detected and converts the front-end code into an abstract syntax tree; based on the abstract syntax tree, statically analyzes the front-end code and generates a problem report; inputs the front-end code into a neural network model to obtain quality assessment information and modification suggestions for the front-end code; based on the problem report, the quality assessment information and the modification suggestions, obtains the quality detection result and displays it using a visual API. The present application converts the code into an abstract syntax tree, statically analyzes the abstract syntax tree to generate a problem report, and then uses a neural network model to perform quality assessment on the code and provide modification suggestions, finally obtaining the quality detection result, and displays the quality detection result in a visual form, thereby achieving an intuitive visual display of the front-end code quality, improving the intuitiveness of the front-end code review, and thereby improving the efficiency of the front-end code review and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a flowchart of the first embodiment of the visual front-end code quality detection method involved in the embodiment scheme of the present application; Figure 2 This is a schematic diagram of an abstract syntax tree structure of a first embodiment of a visual front-end code quality detection method according to an embodiment of the present application; Figure 3 This is a schematic diagram of the visual quality assessment results of the first embodiment of the visual front-end code quality detection method involved in the embodiment of the present application; Figure 4 This is a flow chart of a second embodiment of a visual front-end code quality detection method according to an embodiment of the present application; Figure 5 This is a schematic diagram of the structure of the visual front-end code quality detection device for this application.
[0016] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0017] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0018] In the field of front-end engineering, code quality testing is a key step to ensure that software products meet expected standards. Current front-end code quality testing tools, such as ESLint, Prettier, Stylelint, etc., can identify syntax errors, coding standard deviations, and potential logical defects in front-end code. However, these front-end code quality testing tools usually only provide quality reports in text form, lacking intuitive statistical charts and other visual means to display code quality problems, making it difficult for developers to quickly grasp the overall quality status of the code, which in turn affects the efficiency of code review and maintenance.
[0019] In order to solve the above-mentioned defects existing in the related art, the embodiment of the present application proposes a visual front-end code quality detection method, which obtains the front-end code to be detected and converts the front-end code into an abstract syntax tree; based on the abstract syntax tree, the front-end code is statically analyzed and a problem report is generated; the front-end code is input into a neural network model to obtain quality assessment information and modification suggestions for the front-end code; based on the problem report, the quality assessment information and the modification suggestions, the quality detection result is obtained and displayed using a visual API. This application converts the code into an abstract syntax tree, and statically analyzes the abstract syntax tree to generate a problem report, and then uses a neural network model to perform quality assessment on the code and provide modification suggestions, and finally obtains the quality detection result, and displays the quality detection result in a visual form, thereby achieving an intuitive visual display of the front-end code quality, improving the intuitiveness of the front-end code review, and thus improving the efficiency of the front-end code review and maintenance.
[0020] For ease of understanding, the technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0021] The visual front-end code quality detection method of the first embodiment proposed in this application can be found in Figure 1 The method comprises steps S10 to S40: Step S10: Obtain the front-end code to be detected, and convert the front-end code into an abstract syntax tree.
[0022] It should be noted that lexical analysis is the process of converting the character sequence of the source code into words (tokens, representing the smallest semantic unit in the source code), such as keywords, identifiers, literals, operators, etc. This process is usually completed using a lexical analyzer (Lexer). When the lexical analyzer is executed, it will recognize various language constructs in the character sequence according to predefined lexical rules or patterns, and generate corresponding token sequences. The generated token sequences carry the structural information of the source code, but do not contain specific grammatical relationships. During the lexical analysis process, the lexical analyzer not only needs to identify various language elements, but is also responsible for processing special rules in the language, such as escape characters, string literals, and possible comment blocks.
[0023] Syntax analysis is based on lexical analysis. The syntax analyzer represents the token sequence in a hierarchical structure that builds the source code, namely the Abstract Syntax Tree (AST). During the syntax analysis process, the syntax analyzer checks whether the token sequence conforms to the grammatical structure of the language and combines the token sequence using grammatical rules. The grammar rules define how to combine simple language constructs into more complex structures. AST is a tree structure in which each node represents a grammatical construct in the source code, such as an expression, statement, or declaration. The relationship between nodes reflects the grammatical structure in the code.
[0024] In AST, each node represents a grammatical element or grammatical structure in the code. These grammatical structures can be simple, such as keywords or identifiers, or complex, such as expressions or statements, and the nodes represent the composition or nesting relationship between them through hierarchical relationships.
[0025] In an optional implementation scheme, the front-end code is converted into an abstract syntax tree using lexical analysis and grammatical analysis to achieve a structured representation of the front-end code. First, the basic lexical units of the front-end code, i.e., tokens, such as keywords, identifiers, literals, and operators, are extracted by a lexical analyzer. Then, the lexical analyzer combines the basic lexical units according to the grammatical rules according to the predefined grammatical rules to form a grammatical structure that conforms to the grammatical rules. These grammatical structures include expressions, declarations, or statements, and all grammatical structures together constitute the grammatical units of the front-end code. Subsequently, the grammatical structure is mapped to a node, and the logical relationship of the grammatical structure is defined as an edge, which is constructed into an abstract syntax tree. In the tree structure of the abstract syntax tree, each node represents a grammatical structure, and the hierarchical relationship between the nodes reflects the logical relationship between the grammatical structures of the front-end code. For example, a function call may exist as a child node under a conditional statement node.
[0026] For example, take a simple JavaScript code example: var x = 10; if (x>5) {console.log("x is greater than 5");}. In the lexical analysis stage, the above code is decomposed into tokens (the plural form of token, which represents multiple minimum semantic units, and can also be considered as a collection of minimum semantic units), including the keyword var, the identifier x, the assignment operator =, the numeric literal 10, the statement terminator;, the control flow keyword if, the comparison operator >, etc. Then, as Figure 2 As shown in the figure, during the syntax analysis phase, these tokens are combined into a grammatical structure of a conditional statement, which contains a reference to the variable x, a comparison expression, and a code block that contains a call to the console.log function. Finally, these structures are built into an abstract syntax tree, which contains nodes for variable declarations and conditional statements, accurately representing the grammatical structure and logical relationships of the original code. In this way, each part of the front-end code is converted into a node in the abstract syntax tree.
[0027] Optionally, the front-end code is converted into an abstract syntax tree. The lexical analyzer can be generated by the FastLexical Analyzer Generator (Flex), and the syntax analyzer generator (GNUbison) is used to build the syntax analyzer. Flex creates a lexical analyzer by defining regular expressions and corresponding actions. Regular expressions are used to match lexical units in the source code, and actions define the operations that should be performed when the match is successful, including saving the matching text, generating the corresponding token, etc. For example, when Flex recognizes a variable name, the corresponding action will encapsulate the name into the corresponding token and pass it to the subsequent syntax analysis stage. Bison generates a syntax analyzer by defining grammar and actions. The grammar defines how token sequences should be combined into higher-level syntax structures, and the actions are used to build the relationship between the nodes of the abstract syntax tree.
[0028] Exemplarily, Flex is first used to define the lexical rules of the front-end code and generate the source code of the lexical analyzer. The rules include how to identify various lexical units in the code, such as variable names, numbers, operators, etc. Flex generates the source code of the lexical analyzer through the rules. When reading the front-end code, the lexical analyzer converts the text of the front-end code into a token sequence. Then the token sequence generated by Flex is input into the syntax analyzer defined by Bison. Bison predefines grammar rules to parse the token sequence, where the grammar rules define the grammatical structure of the front-end code, such as expressions, statements, and program blocks. When parsing the token sequence, Bison constructs an abstract syntax tree according to the predefined grammar rules. Each node of the abstract syntax tree represents a grammatical structure in the front-end code, and the nodes represent the logical relationship between the grammatical structures.
[0029] Optionally, use ANTLR (Another Tool for Language Recognition) to create a lexical analyzer and a parser. ANTLR supports the definition of complex grammars and can generate code in multiple programming languages. Define the lexical rules and grammatical rules of the front-end code in ANTLR, and then use ANTLR's tools to generate the source code for the lexical analyzer and the parser.
[0030] Exemplarily, a .g4 file is created to define the lexical rules of the front-end code, and the lexical rules cover the lexical units such as identifiers, numbers, operators, etc. of the front-end code. Then another .g4 file is created to define the grammatical rules of the front-end code, and the grammatical rules include grammatical structures such as expressions, statements, and program blocks. Using the ANTLR tool, the source code of the lexical analyzer and the grammatical analyzer is generated according to the lexical rules and grammatical rules. The generated analyzer code is compiled into an executable file, and the compiled analyzer is integrated with the analysis process of the front-end code. When performing lexical analysis, the front-end code is lexically analyzed using the lexical analyzer to generate a token stream. Then the token stream is input into the grammatical analyzer generated by ANTLR, parsed according to the predefined grammatical rules, and an abstract syntax tree is constructed.
[0031] Step S20: Based on the abstract syntax tree, static analysis is performed on the front-end code and a problem report is generated.
[0032] It should be noted that static analysis is an in-depth code inspection process for front-end code, which is performed without actually running the front-end code. Static analysis relies on abstract syntax trees to identify and report quality issues of front-end code.
[0033] In an optional implementation scheme, the abstract syntax tree is traversed to perform semantic analysis on each node of the abstract syntax tree. During the traversal process, it is determined whether each node complies with the rules in the preset rule set, and then all semantic errors in the abstract syntax tree are identified, and the type, location, problem description and repair suggestions of the problem corresponding to the semantic error are associated and saved in the error set. The rules in the preset rule set may cover coding style. After the traversal is completed, a problem report is output based on the information in the error set.
[0034] It should be noted that semantic analysis includes checking variable declarations, type matching, scope rules, correctness of grammatical structure, control flow analysis, data flow analysis and other semantic checks, and may also cover coding style (such as indentation, naming conventions), etc.
[0035] Variable declaration checking is a fundamental step in semantic analysis, ensuring that all variables are correctly declared before use. This process involves verifying the existence of variable declarations, ensuring that variables are correctly initialized within the scope, and that the data type of the variable is consistent with the expected data type. In addition, variable declaration checking also includes identifying duplicate variable declarations and ensuring that variable names do not conflict with reserved words or existing identifiers. This process can prevent undefined variable reference errors during program execution, thereby improving the maintainability of the code.
[0036] Specifically, the check of variable declarations can include: (1) Determining that the variable declaration complies with the syntax rules of the front-end code. In the front-end code, variable declarations usually follow the format of "declaration keyword variable name = initial value". (2) Verifying whether the variable name is valid, which usually includes checking whether the variable name contains illegal characters, ensuring that no characters other than letters, numbers, underscores or dollar signs appear in the variable name, and no characters other than letters, underscores and dollar signs appear at the beginning, ensuring that the variable naming complies with the naming conventions of the front-end code. (3) Confirming that the variable name does not conflict with reserved words, that is, the variable name cannot be a keyword of the front-end programming language or a keyword reserved in the future. (4) Identifying and preventing repeated declarations. Variables with the same name must not be declared in the same scope to avoid overwriting existing variables or causing confusion. (5) Ensure that the variable has been declared before use to prevent reference errors caused by undeclared variables. (6) For variables declared as const, check whether an initial value is assigned during declaration and whether it cannot be reassigned later.
[0037] Type checking, as an important part of semantic analysis, ensures that the type usage logic in the code is correct. The compiler traverses the abstract syntax tree and performs type consistency checks, including checking whether the operator and operand types match, whether the parameter types in the function call are consistent with the parameter types in the function declaration, and verifying whether the data type conversion during variable assignment or operation is valid. In addition, type checking also includes identifying common errors such as uninitialized variable references, premature use of undeclared variables, and checking whether arrays have out-of-bounds access.
[0038] Exemplarily, when performing an addition operation, check whether both operands involved in the operation are of numeric type, such as integer or floating point. If one of the operands is a string or other non-numeric type, a type mismatch error will be thrown. When executing a function call, check whether the parameter type passed to the function is consistent with the parameter type defined in the function signature. For example, when a parameter is defined as an integer type in the function signature, the type of the value passed to the parameter is checked, and it is ensured that the passed type is a certificate, not other types, such as a string or an object. In the process of verifying variable assignment or operation, verify whether the data type conversion is valid. For example, when converting a string to a numeric type, check whether the string contains valid numeric characters and no type mismatch error will be thrown. In the type checking process, uninitialized variable references are also identified. For example, if the front-end code attempts to access an undeclared variable, an undefined variable error will be thrown. In addition, it is also checked whether the array is accessed out of bounds. For example, when the front-end code attempts to access a non-existent index in the array, an array out-of-bounds access error will be thrown because the array access index must be valid.
[0039] Scoping rules are checked to ensure that variables and functions are declared and used in the appropriate scope. The analyzer identifies the scope of each identifier and ensures that they are visible within the scope while avoiding illegal cross-scope references. This process includes checking the declaration order and lifetime of variables to ensure that they are not used before they are declared and that they are not referenced after they leave the scope.
[0040] Exemplarily, the scope rule check ensures that variables and functions are declared and used within the appropriate scope. For example, a variable declared inside a function can only be accessed inside the function, but not outside the function; if a variable is declared inside a function, then accessing the variable outside the function will be identified as an illegal cross-scope reference, etc.
[0041] Checking the correctness of the grammatical structure ensures that the code follows the grammatical rules of the language, including verifying whether the statement is terminated, the brackets are matched, and whether the use of keywords complies with the language specification. The correctness of the grammatical structure is the basis for the code to be correctly parsed and executed.
[0042] For example, each statement should have the correct end marker, such as a semicolon. In the front-end code, you need to ensure that the brackets match, that is, the number of left and right brackets is the same. Ensure that the use of keywords conforms to the language specification, such as in JavaScript, each function declaration should be followed by a left curly bracket, etc.
[0043] Control flow analysis is used to check the control structures in the program, such as loops, conditional branches, and jump statements, to ensure that the control structures are logically valid and reasonable, without causing infinite loops or unreachable code paths. This process helps identify logical errors and abnormal conditions in the control flow.
[0044] Data flow analysis is used to track the flow of variable values in a program, including variable assignment, transfer, and use, as well as expression calculation and pointer analysis. This process helps identify dead code, undefined variable usage, and possible data race conditions. Data flow analysis is essential for optimizing code performance and preventing potential runtime errors.
[0045] Other semantic checks include checking compliance with coding style specifications, such as code indentation, variable and function naming conventions, etc., to ensure code readability and consistency. This process helps maintain a clean and standardized code base, making it easier for developers to understand and maintain the code.
[0046] Optionally, before the step of semantically analyzing each node of the abstract syntax tree, the compiler usually builds a symbol table (Symbol Table) to store all identifiers (such as variables, functions, classes, etc.) in the source code and the declaration information corresponding to the identifiers, such as name, type, scope, declaration location, and possible initialization status. Then a scope chain is built to determine the scope level of each node in the abstract syntax tree. The scope chain ensures that scope rules, such as visibility and life cycle of variables, can be correctly parsed and applied during the semantic analysis process. Through the scope chain, static analysis tools can identify semantic problems such as variable declaration conflicts within the scope and the use of uninitialized variables. In addition, a type system needs to be defined to determine predefined types (such as primitive types) and user-defined types (such as custom classes and interfaces). In addition, the type system also includes rules for mutual conversion between predefined types and user-defined types to identify potential type mismatch errors. Based on the constructed symbol table, scope chain, and type system, semantic errors in the front-end code are identified during the semantic analysis process.
[0047] Step S30: input the front-end code into a neural network model to obtain quality assessment information and modification suggestions for the front-end code.
[0048] It should be noted that a neural network model is an algorithm that learns and makes predictions through a large amount of data. It simulates the working principle of human brain neurons and consists of multiple layers of nodes (neurons) connected by weighted edges. The neural network model learns the pattern of input data by adjusting the connection weights between layers. Batch codes are unique identifiers used to track the code quality assessment results of a specific batch.
[0049] It is understandable that when evaluating code quality, it is necessary to select a neural network model that is suitable for text data, especially for text classification or regression tasks. Using the PyTorch framework, you can build a network structure designed for sequence prediction, such as LSTM. This type of model is suitable for processing sequence data and can identify and utilize time dependencies in text, thereby providing accurate prediction results for front-end code quality assessment.
[0050] In an optional implementation, before inputting the front-end code into the neural network model, it is first necessary to obtain the text data of the front-end code and pre-process the obtained text data. The pre-processing includes word segmentation, that is, dividing the continuous text string into independent vocabulary units; cleaning, removing punctuation marks and irrelevant characters in the vocabulary units to reduce interference with model analysis; and character conversion, converting the characters of all vocabulary units to lowercase format to eliminate the impact of uppercase and lowercase differences on the analysis results.
[0051] After preprocessing, the preprocessed text data needs to be converted into a numerical input form acceptable to the neural network model. This conversion process can be achieved through word embedding, using a pre-trained word vector model or building a word embedding model through training data, mapping each word in the preprocessed text data to a vector of fixed dimension, ensuring that each word unit is converted into a corresponding numerical vector according to its representation in the word embedding model; or through one-hot encoding, the preprocessed text data is converted into a numerical matrix. This method involves creating a unique index for each unique word in the preprocessed text data and building a vocabulary index table. For each vocabulary unit, according to its position in the vocabulary index table, a vector with the same length as the number of entries in the vocabulary index table is generated, in which all elements except the element corresponding to the vocabulary index table position are set to 1 and the remaining elements are set to 0.
[0052] Optionally, after the text data is prepared, the neural network model is then built and trained. Using the deep learning framework of PyTorch, a neural network model suitable for text classification or regression, such as a long short-term memory network (LSTM), can be built. Subsequently, the preprocessed text data is divided into a training set and a validation set, where the training set is used for model learning, and the validation set includes the detection results and modification suggestions for the preprocessed text data, which are used to evaluate the prediction performance of the neural network model and adjust the parameters of the neural network model. Using the training set, the neural network model is learned through batch training, where each batch contains a certain number of sample data. In the forward propagation stage, the neural network model processes the input text data and generates a predicted output, which is then compared with the actual label through a loss function to calculate the prediction error. The choice of loss function depends on the specific evaluation task, which may be mean square error or cross entropy loss, etc. After obtaining the prediction error, the back propagation algorithm is triggered to start calculating the gradient of the loss relative to the parameters of the neural network model. These gradient information indicates how to adjust the model weights to reduce the error.
[0053] Weight adjustment is a key step in the training process of neural network models. The weights and biases of the neural network model are updated through optimization algorithms such as Stochastic Gradient Descent (SGD) or Adaptive Moment Estimation (Adam) to minimize the loss function and improve the prediction accuracy of the neural network model.
[0054] Optionally, during the training process of the neural network model, the performance of the neural network model is evaluated by running the neural network model on a validation set. The neural network model is run on the validation set and the prediction results are output; the prediction results are compared with the actual results of the validation set, and the performance of the neural network model is evaluated by calculating the performance evaluation index; the parameters of the neural network model are adjusted according to the results of the performance evaluation index to optimize the performance of the neural network model, and the parameters include the learning rate, batch size, and network structure; the adjusted parameters of the neural network model are saved, and the quality evaluation of the front-end code is performed using the trained neural network model.
[0055] After multiple rounds of iterative training and parameter optimization, when the performance of the neural network model on the validation set reaches the expected target, the parameters of the neural network model at this time are saved, and the trained neural network model is deployed to the actual application. The deployed neural network model can receive new front-end code text data, perform quality assessment, and provide quality assessment information and modification suggestions to help developers maintain code quality.
[0056] For example, in the training process of the neural network model, in order to evaluate the performance of the neural network model, the neural network model will be run on the validation set and the prediction results will be output. The prediction results are then compared with the actual results of the validation set, and performance evaluation indicators are calculated, such as the accuracy of the neural network model on the validation set is 80%, the recall rate is 70%, and the F1 score is 0.65. The accuracy of the neural network model on the validation set is only 80%, which is lower than the expected target. In this case, the learning rate can be appropriately increased or the training time of the neural network model can be increased. The recall rate of the neural network model on the validation set is 70%, which is also lower than the expected target. This may be because the neural network model is not sensitive enough to the recognition of positive samples. Therefore, the weights of positive and negative samples can be adjusted, or the batch size can be appropriately reduced; the F1 score of the neural network model on the validation set is only 0.65, which is lower than the expected target value. In this case, the network structure can be adjusted, such as increasing or decreasing the number of network layers, and the loss function of the neural network model during training can also be adjusted.
[0057] Step S40: Based on the problem report, the quality assessment information and the modification suggestion, a quality inspection result is obtained and displayed using a visualization API.
[0058] It should be noted that after the neural network model completes the quality assessment, the problem report, quality assessment information and modification suggestions are associated to obtain the quality test results. The problem report, quality assessment information and modification suggestions are all output through the interface API, and the output format is JSON format.
[0059] Optionally, after obtaining the quality inspection results, the server generates a corresponding batch code and associates the batch code with the quality inspection results to ensure that the quality assessment results of the front-end code can be accurately recorded and identified each time. Then, the local browser is automatically opened through the preset batch processing command, and the URL with the batch code attached to the server address is accessed to trigger the local browser to display the visual chart converted according to the quality assessment results and the corresponding front-end code quality indicators.
[0060] It should be noted that batch commands are an automation scripting language for Windows systems, which is used to sequentially execute a series of predefined instructions in the operating system. These scripts usually exist in the form of .bat or .cmd files, and can automatically perform file operations, system management tasks, program startup, error handling, user interaction, and logging.
[0061] In the automated quality assessment process, the batch command is used to automatically open the browser and access the URL containing the batch code after the neural network model completes the front-end code quality assessment. The batch code is a unique identifier generated by the server and associated with the quality assessment result, which is used to display a visual representation of the quality assessment result in the browser. The use of batch commands simplifies user operations, realizes seamless automation from front-end code quality assessment to display, and provides intuitive quality feedback.
[0062] For example, when the neural network model completes the quality assessment, the batch processing command will be automatically executed, the local browser will be opened, and the quality assessment results will be displayed. The quality assessment results are mainly displayed from seven dimensions (code rules, potential defects, code complexity, code duplication, code annotations, unit tests, dependency coupling, etc.). Please refer to Figure 3 , Figure 3 It mainly shows the basic data related to code quality and the changing trend of the number of code quality problems over time. In the attached figure, basic data such as code readability, repetition, number of scanned code lines, commented code, and unit test passing are shown, and the number of code quality problems in the past 7 days is shown below. The line chart shows the changing trend of the number of front-end code problems over time.
[0063] Please refer to Figure 4 The visual front-end code quality detection method of the second embodiment proposed in this application includes the following steps S401 to S405 after step S40: Step S401: Acquire the modification record of the front-end code, and jump to execute the steps of acquiring the text data of the front-end code and preprocessing the text data.
[0064] It should be noted that after the quality assessment results are displayed in a visual way, the developer modifies the front-end code according to the problem report, quality assessment information and modification suggestions in the quality assessment results. By obtaining the latest modification records of the front-end code, including the submission log in the version control system, the comments of the code review, and the modifications made by the developer to the front-end code. After obtaining the modification records, it will jump back to the method steps of preprocessing the front-end code, that is, jump to the steps of obtaining the text data of the front-end code and preprocessing it. The preprocessing steps include word segmentation, cleaning, and character conversion. After preprocessing the text data of the latest modified front-end code, it is converted into the form of a numerical vector or a numerical matrix and re-input into the neural network model for quality assessment.
[0065] Step S402: Mark the modification records of the preprocessed front-end code as training set data.
[0066] Step S403: When new training set data is generated, an incremental learning process is triggered to perform secondary training on the neural network model.
[0067] It should be noted that the pre-processed and latest modified front-end code is marked as training set data, and the incremental learning process of the neural network model is triggered, so that the neural network model can be trained twice, so that the neural network model can learn the pattern and trend of code modification, and how the modification operations in the code modification record affect the code quality. In this way, the neural network model can not only evaluate the code quality, but also optimize and adjust itself over time according to the developer's front-end code modification ideas and feedback.
[0068] Step S404: After completing the incremental learning process, the weights and parameters of the neural network model are updated and saved.
[0069] Step S405: Based on the updated neural network model, perform quality assessment on the front-end code.
[0070] It should be noted that when the incremental learning process is completed, the neural network model will be updated. The parameters of the neural network model, including weights and biases, will be adjusted according to the latest training data to reflect the knowledge learned by the neural network model from the new training data. The updated neural network model will have improved performance and more accurate evaluation capabilities, enabling it to better adapt to the developer's code modification ideas and quality evaluation needs.
[0071] It is understandable that the purpose of updating the model is to ensure that the visual front-end code quality detection method can continue to provide high-quality quality assessment results, and that the neural network model can continue to evolve over time to adapt to the changing code base and development practices. This update mechanism is the key to achieving the long-term effectiveness and adaptability of the neural network model, because it allows the neural network model to learn from each development cycle and improve its own prediction capabilities.
[0072] The present application provides a visual front-end code quality detection device, which includes: at least one processor; and a memory that is communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the visual front-end code quality detection method in the above-mentioned embodiment one.
[0073] Reference below Figure 5, which shows a schematic diagram of the structure of a visual front-end code quality detection device suitable for implementing the embodiment of the present application. The visual front-end code quality detection device in the embodiment of the present application may include various hardware and software components for implementing the scheduling method of the inspection task. Figure 5 The visual front-end code quality detection device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0074] like Figure 5 As shown, the visual front-end code quality detection device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM: Read Only Memory) 1002 or the program loaded from the storage device 1003 to the random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the visual front-end code quality detection device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. The input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the visual front-end code quality detection device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a visual front-end code quality detection device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.
[0075] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0076] The visual front-end code quality detection device provided by the present application adopts the visual front-end code quality detection device method in the above embodiment, which can solve the technical problem that the front-end code quality detection tool lacks intuitive visual display. Compared with the prior art, the beneficial effects of the visual front-end code quality detection device provided by the present application are the same as the beneficial effects of the visual front-end code quality detection method provided by the above embodiment, and the other technical features in the visual front-end code quality detection device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0077] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0078] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0079] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the visual front-end code quality detection method in the above-mentioned embodiment.
[0080] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0081] The computer-readable storage medium may be included in the visual front-end code quality detection device; or may exist independently without being assembled into the visual front-end code quality detection device.
[0082] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by a visual front-end code quality detection device, the visual front-end code quality detection device: obtains the front-end code to be detected, and converts the front-end code into an abstract syntax tree; based on the abstract syntax tree, performs static analysis on the front-end code and generates a problem report; inputs the front-end code into a neural network model to obtain quality assessment information and modification suggestions for the front-end code; based on the problem report, the quality assessment information and the modification suggestions, obtains the quality detection results and displays them using a visual API.
[0083] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0084] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0085] The modules involved in the embodiments described in the present application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0086] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned visual front-end code quality detection method, and can solve the technical problem that the front-end code quality detection tool lacks intuitive visual display. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the visual front-end code quality detection method provided in the above-mentioned embodiment, and will not be repeated here.
[0087] An embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the above-mentioned visual front-end code quality detection method.
[0088] The computer program product provided by this application can solve the technical problem of how the front-end code quality detection tool lacks intuitive visual display. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiment of this application are the same as the beneficial effects of the visual front-end code quality detection method provided by the above embodiment, which will not be repeated here.
[0089] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent processing scope of the present application.
[0090] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0091] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.
[0092] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A visual front-end code quality detection method, characterized in that: The method includes: Obtaining a front-end code to be tested, and converting the front-end code into an abstract syntax tree; Based on the abstract syntax tree, statically analyze the front-end code and generate a problem report; Inputting the front-end code into a neural network model to obtain quality assessment information and modification suggestions for the front-end code; Based on the problem report, the quality assessment information and the modification suggestion, a quality inspection result is obtained and displayed using a visualization API.
2. The method according to claim 1, characterized in that The step of obtaining the front-end code to be detected and converting the front-end code into an abstract syntax tree comprises: Extracting basic lexical units of the front-end code through a lexical analyzer; Combining the basic lexical units according to grammatical rules to form a grammatical structure that complies with the grammatical rules; The grammatical structure is mapped into nodes, the logical relationship of the grammatical structure is defined as edges, and an abstract syntax tree is constructed.
3. The method according to claim 1, characterized in that The step of statically analyzing the front-end code and generating a problem report based on the abstract syntax tree comprises: Traversing the abstract syntax tree and performing semantic analysis on each node of the abstract syntax tree; Identify all semantic errors during the traversal process, and associate and save the type, location, problem description, and repair suggestion of the problem corresponding to the semantic error into an error collection; After the traversal is completed, a problem report is output based on the information in the error set.
4. The method according to claim 3, characterized in that Before the step of performing semantic analysis on each node of the abstract syntax tree, the method includes: Establish a symbol table according to the identifiers in the front-end code and the declaration information corresponding to the identifiers, and save the symbol table; Constructing a scope chain to determine the scope level of each node in the abstract syntax tree; Define a type system, determine predefined types, user-defined types, and rules for conversion between the predefined types and the user-defined types; The semantic error is identified during the semantic analysis process based on the symbol table, the scope chain, and the type system.
5. The method according to claim 1, characterized in that Before the step of inputting the front-end code into the neural network model to obtain the quality assessment information and modification suggestions of the front-end code, the method includes: Obtaining text data of the front-end code and preprocessing the text data, wherein the preprocessing includes word segmentation, punctuation cleaning, and converting characters to lowercase format; Converting the preprocessed text data into a numerical vector through word embedding; or The preprocessed text data is converted into a numerical matrix using one-hot encoding.
6. The method according to claim 1, characterized in that Before the step of inputting the front-end code into the neural network model to obtain the quality assessment information and modification suggestions of the front-end code, the method further includes: Build a neural network model based on PyTorch; Dividing the preprocessed text data into a training set and a validation set, wherein the validation set includes detection results and modification suggestions for the preprocessed text data; Perform batch training using the training set, execute forward propagation to calculate the predicted output of the neural network model, and calculate the prediction error through a loss function; A back propagation algorithm is executed to adjust the weights of the neural network model according to the prediction error.
7. The method according to claim 6, characterized in that After the step of executing the back propagation algorithm and adjusting the weight of the neural network model according to the prediction error, the method further comprises: Running the neural network model on the validation set and outputting a prediction result; Comparing the predicted results with the actual results of the validation set, and evaluating the performance of the neural network model by calculating a performance evaluation index; Adjusting the parameters of the neural network model according to the results of the performance evaluation index to optimize the performance of the neural network model, the parameters including learning rate, batch size and network structure; The adjusted parameters of the neural network model are saved, and the trained neural network model is used to evaluate the quality of the front-end code.
8. The method according to claim 1, characterized in that After the step of generating a visual quality inspection result based on the problem report, the quality assessment information and the modification suggestion, the method further includes: Obtaining the modification record of the front-end code, and jumping to the step of obtaining the text data of the front-end code and preprocessing the text data; Marking the modification records of the preprocessed front-end code as training set data; When new training set data is generated, an incremental learning process is triggered to perform secondary training on the neural network model; After completing the incremental learning process, updating and saving the weights and parameters of the neural network model; Based on the updated neural network model, a quality assessment of the front-end code is performed.
9. A visual front-end code quality detection device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the visual front-end code quality detection method as described in any one of claims 1 to 8.
10. A computer storage medium, characterized in that: The computer storage medium is a computer-readable storage medium, and a computer program is stored on the computer storage medium. When the computer program is executed by the processor, the steps of the visual front-end code quality detection method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Code visualization analysis method and device based on abstract syntax
CN112306479A
Source code defect detection method and device
CN112579469A
Code quality improving method and system based on machine learning
CN114116469A
Front-end code quality detection method
CN118467387A
Code auditing method, system and equipment based on GitLab and medium
CN118585451A
Cited By
Large model assisted static code scanning result analysis method and device, electronic equipment and computer readable storage medium
CN119690807A
A command line based interactive automated evaluation method and system
CN119782072A
Code quality inspection method, system and equipment, medium and program product
CN119807004A
Code error detection method and device and storage medium
CN120353713A
