Code detection methods, devices, electronic equipment and storage media
By using detection plugins and the Eslint plugin to detect and provide hints for object properties in front-end development, the problems of JavaScript errors and page crashes caused by missing or empty object properties are solved, thus improving the quality and reliability of the code.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2026-03-10
AI Technical Summary
In front-end development, user-written code may contain missing or empty object properties, leading to JavaScript errors, execution halts, rendering freezes, and page crashes.
By triggering the detection plugin in the code to be detected, the plugin detects object properties. It uses syntax tree parsing and the business logic built into the Eslint plugin to generate prompts based on preset detection conditions, and promptly notifies the user of the existence or null status of object properties.
It effectively avoids runtime errors and performance issues, improves code quality and reliability, ensures users can check and update the code in a timely manner, and prevents page crashes.
Smart Images

Figure CN114253551B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of program development technology, and in particular to a code detection method, apparatus, electronic device, and storage medium. Background Technology
[0002] Currently, when front-end developers use Vue projects, they need to obtain the properties of objects returned by APIs, other custom objects, or arrays, and perform corresponding business logic processing.
[0003] When writing front-end development code, users may encounter exceptions such as missing or null object properties. These exceptions can lead to JavaScript errors, execution halts, rendering freezes, and page crashes.
[0004] Therefore, how to quickly detect user-written code and provide timely alerts for abnormal object properties in the code is an important issue that the industry urgently needs to address. Summary of the Invention
[0005] This invention provides a code detection method, apparatus, electronic device, and storage medium to address the shortcomings of existing technologies where user-written front-end development code contains missing or empty object properties, leading to JavaScript errors, execution halts, rendering freezes, and page crashes. The invention enables rapid detection of object properties in the code, providing timely alerts for abnormal object properties.
[0006] This invention provides a code detection method, comprising:
[0007] If the code to be detected contains object properties, the detection plugin is triggered to detect the object properties.
[0008] The object attributes in the code to be detected that meet the preset detection conditions are taken as the target object attributes;
[0009] Based on the target object attributes in the code to be detected, a prompt is issued so that the user can check whether the target object attributes exist or are empty.
[0010] The code detection method provided by the present invention further includes:
[0011] The code to be detected is parsed based on the syntax tree;
[0012] The analysis results determine whether the code to be detected contains object properties.
[0013] According to a code detection method provided by the present invention, the detection plugin has built-in business logic;
[0014] The trigger detection plugin detects the object properties, including:
[0015] The detection plugin is triggered to execute the business logic and detect the object attributes.
[0016] According to a code detection method provided by the present invention, the business logic is determined based on the general syntax rules under the code type corresponding to the code to be detected.
[0017] According to a code detection method provided by the present invention, the business logic includes regular expressions and / or conditional judgment statements.
[0018] According to a code detection method provided by the present invention, the step of issuing a prompt based on the target object attribute in the code to be detected includes:
[0019] Based on the syntax rules in Eslint and the target object's properties, generate hint information for the target object's properties and issue a hint containing the hint information.
[0020] The code detection method provided by the present invention further includes:
[0021] Obtain the updated code to be detected generated by the user based on the prompt;
[0022] If the updated code to be detected contains a target object attribute whose detection result meets the preset detection conditions, a prompt is issued based on the target object attribute in the updated code to be detected.
[0023] The present invention also provides a code detection device, comprising:
[0024] The first detection module is used to trigger the detection plugin to detect the object attributes when the code to be detected contains object attributes;
[0025] The second detection module is used to take the object attributes in the code to be detected that meet the preset detection conditions as target object attributes.
[0026] The prompting module is used to issue prompts based on the target object attributes in the code to be detected, so that the user can check whether the target object attributes exist or are empty based on the prompts.
[0027] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the code detection methods described above.
[0028] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the code detection methods described above.
[0029] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the code detection methods described above.
[0030] The present invention provides a code detection method, apparatus, electronic device, and storage medium. The method acquires the code to be detected in real time, and when the code contains object attributes, triggers a detection plugin to detect the object attributes in the code. When a target object attribute that meets the preset detection conditions is found, a prompt is promptly issued to the user, allowing the user to receive the prompt in a timely manner and verify whether the target object attribute actually exists or is empty. This avoids problems such as script code errors, execution stoppage, rendering freeze, and page crashes that can occur when the code to be detected is run directly. This effectively improves the quality and reliability of the code to be detected. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0032] Figure 1 This is a flowchart illustrating the code detection method provided by the present invention;
[0033] Figure 2 This is a schematic diagram of the structure of the detection plugin in the code detection method provided by the present invention, which detects the code to be detected;
[0034] Figure 3 This is a schematic diagram of the structure of the code detection device provided by the present invention;
[0035] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0037] The following is combined Figure 1 The code detection method of the present invention is described, the method comprising: step 101, in the case that the code to be detected contains object attributes, triggering a detection plugin to detect the object attributes;
[0038] The code detection method in this embodiment can be applied to computer devices, such as personal computers and servers, but this embodiment does not specifically limit it.
[0039] The code to be detected is the code that needs to be detected. The code to be detected can be front-end development code or back-end development code, etc. This embodiment does not make specific limitations on this.
[0040] The number of object attributes contained in the code to be detected can be one or more, and this embodiment does not specifically limit this.
[0041] The following description uses the front-end development code in a Vue project as an example to illustrate the code detection method in this embodiment.
[0042] Among them, object properties can be properties of the object returned by the interface, properties of other custom objects, or properties of data content such as arrays. This embodiment does not specifically limit them.
[0043] Optionally, the code to be tested can be obtained in real time when the user is developing the front end based on a Vue project;
[0044] Then, it determines whether there are object properties in the code to be detected. If the code to be detected contains object properties, the detection plugin is triggered to detect each object property in the code to be detected.
[0045] The detection plugin is the Eslint plugin that is pre-inserted into the Vue project.
[0046] If the code to be detected does not contain any object properties, the detection plugin will not be triggered; the collection will continue to obtain the next code to be detected.
[0047] The methods for determining whether object attributes exist in the code to be detected include comparing each part of the code to be detected with each object attribute in the object attribute set to determine whether object attributes exist in the code to be detected; or comparing the writing format of the code to be detected with the writing format of general object attributes to determine whether object attributes exist in the code to be detected. This embodiment does not specifically limit the method for determining whether object attributes exist in the code to be detected.
[0048] Step 102: The object attributes in the code to be detected that meet the preset detection conditions are taken as the target object attributes;
[0049] Among them, the target object attribute is the object attribute that has the risk of not existing or being empty.
[0050] Optionally, after obtaining the detection results of each object attribute in the code to be detected, it is determined whether the detection results of each object attribute meet the preset detection conditions.
[0051] The preset detection conditions are defined as conditions that limit the risk of object attributes being non-existent or empty. The preset detection conditions are set according to the requirements of the embodiment, and this embodiment does not specifically limit them.
[0052] If the detection result of any object attribute meets the preset detection conditions, then the object attribute is at risk of not existing or being empty, and the object attribute is taken as the target object attribute.
[0053] If the detection result of any object attribute does not meet the preset detection conditions, then the object attribute does not have the risk of being non-existent or empty, and no operation is performed on the object attribute. The detection result of the next object attribute is then judged.
[0054] Step 103: Based on the target object attribute in the code to be detected, issue a prompt for the user to check whether the target object attribute exists or is empty.
[0055] Optionally, after obtaining the target object properties in the code to be detected, prompts can be provided for the target object properties.
[0056] Optionally, if a target object attribute that meets the preset detection conditions exists, it indicates that the target object attribute is at risk of not existing or being empty. A prompt is then issued to the user to alert them to this risk. Upon receiving the prompt, the user promptly verifies whether the target object attribute actually exists or is empty. If the user determines that the target object attribute does not exist or is empty, they promptly update the code to be detected, eliminating any non-existent or empty target object attributes, thereby effectively improving the reliability of the code's operation.
[0057] The prompting methods include, but are not limited to, voice or text, and this embodiment does not specifically limit them.
[0058] The verification method can be to search for the target object's attributes against a pre-acquired set of attributes. If the target object's attributes are found and are not empty, the prompt message is ignored; if they are not found or are empty, the code to be checked is updated.
[0059] This implementation uses a detection plugin to detect the code before it runs, so that users can receive prompts in time before the code runs and check whether the target object properties actually exist or are empty. This avoids problems such as JavaScript script errors, execution stoppage, rendering freeze, and page crashes that may occur when the code is run directly.
[0060] This embodiment acquires the code to be tested in real time. When the code contains object attributes, it triggers the detection plugin to detect the object attributes in the code. When a target object attribute that meets the preset detection conditions is found, a prompt is promptly sent to the user. This allows the user to receive the prompt in a timely manner and check whether the target object attribute actually exists or is empty. This avoids problems such as errors in the code to be tested, execution stoppage, rendering freeze, and page crashes that may occur if the code to be tested is run directly. This effectively improves the quality and reliability of the code to be tested.
[0061] Based on the above embodiments, this embodiment further includes: parsing the code to be detected based on a syntax tree; and determining whether the code to be detected contains object attributes based on the parsing results.
[0062] The Abstract Syntax Tree (AST) is a tree-like structure representing the syntax of source code. For source code in a specific programming language, statements in the source code are mapped to each node in the tree by constructing a syntax tree.
[0063] like Figure 2 As shown, after obtaining the code to be detected, it can be parsed based on the syntax tree to map the statements in the code to each node in the tree.
[0064] Based on the analysis results, the relationship between words in the code to be detected can be determined, which facilitates the understanding of the hierarchical structure of the sentence syntax. Furthermore, through this hierarchical relationship, the attribute corresponding to each object in the code to be detected can be quickly determined, thereby quickly determining whether there are object attribute operations in the code to be detected.
[0065] This embodiment uses a syntax tree to parse the code to be detected, which can quickly and accurately determine whether the code to be detected contains object properties.
[0066] Based on the above embodiments, the detection plugin in this embodiment has built-in business logic; triggering the detection plugin to detect the object attributes includes: triggering the detection plugin to execute the business logic to detect the object attributes.
[0067] The business logic includes, but is not limited to, conditional statements and / or operational statements, which are not specifically limited in this embodiment.
[0068] Optionally, the steps of triggering the detection plugin to detect object properties include: the triggering detection plugin using its internal business logic to perform logical operations on each object property in the code to be detected; and using the results of the logical operations as the detection results for each object property in the code to be detected.
[0069] The detection results can be in binary form or text description form, etc., and this embodiment does not specifically limit them.
[0070] This embodiment triggers the detection plugin to execute the corresponding business logic, which can quickly and accurately detect the attributes of each object in the code to be detected.
[0071] Based on the above embodiments, the business logic in this embodiment is determined according to the general syntax rules under the code type corresponding to the code to be detected.
[0072] Optionally, the business logic in the detection plugin can be determined based on the general syntax rules of the code type corresponding to the code to be detected.
[0073] For example, the code to be detected is JavaScript code; the business logic is determined according to the general syntax rules of the JavaScript code.
[0074] JavaScript is a lightweight, interpreted or just-in-time (JIT) programming language with a function-first approach. It is one of the scripting languages used for developing Web (World Wide Web) pages.
[0075] Optionally, the code to be detected in this embodiment can be JavaScript code.
[0076] Accordingly, in order to accurately detect whether the code to be detected has the risk of being non-existent or empty, the business logic inside the detection plugin can be written according to the general syntax rules of JavaScript code.
[0077] This embodiment uses the general syntax rules of the code type corresponding to the code to be detected to write and determine the business logic inside the detection plugin, making the code to be detected more reliable.
[0078] Based on the above embodiments, the business logic in this embodiment includes regular expressions and / or conditional statements.
[0079] Regular expressions are logical formulas for string manipulation. They use predefined specific characters and combinations of these characters to form a string with certain rules, which can then be used to perform corresponding filtering logic on the string.
[0080] Optionally, the business logic built into the code to be detected can be a regular expression, a conditional statement, or both a regular expression and a conditional statement. This embodiment does not specifically limit this.
[0081] Optionally, one or more conditional statements can be set to judge each object attribute in the code to be detected in order to obtain the detection result of each object attribute in the code to be detected.
[0082] Alternatively, one or more conditional statements can be set to filter the properties of each object in the code to be tested, so as to obtain the test results for each property of the object in the code to be tested.
[0083] Alternatively, one or more conditional statements can be set to perform conditional judgments and filtering logic on each object attribute in the code to be detected, so as to obtain the detection results of each object attribute in the code to be detected.
[0084] The business logic in this embodiment can be flexibly configured according to actual needs and is applicable to various scenarios, making the code detection method in this embodiment applicable to a variety of scenarios.
[0085] Based on the above embodiments, the step of issuing a prompt based on the target object attribute in the code to be detected in this embodiment includes: generating prompt information for the target object attribute according to the syntax rules in Eslint and the target object attribute, and issuing a prompt containing the prompt information.
[0086] Optionally, if it is determined that the target object property exists in the code to be detected, the target object property is returned to the Eslint side according to the error reporting rules in the syntax rules of Eslint. Eslint then generates a hint message for the target object property based on the target object property and the detection result, and issues a hint containing the hint message.
[0087] This embodiment uses Eslint to provide hints about the properties of the target object, which can promptly provide feedback to the user so that the user can make corresponding decisions about the code to be tested, such as modifying the code to be tested before compiling and running it.
[0088] In summary, this embodiment develops an ESLint plugin based on existing ESLint technology and integrates it into a Vue project. This allows users to receive friendly ESLint warnings when writing code to retrieve object properties, indicating that some object properties in the user's code may be non-existent or null, and issuing ESLint warning messages.
[0089] Based on the above embodiments, this embodiment further includes: obtaining the updated code to be detected generated by the user according to the prompt; and issuing a prompt based on the target object attribute in the updated code to be detected if there is a target object attribute in the updated code to be detected that satisfies the preset detection conditions.
[0090] Optionally, after receiving the prompt, the user can check the target object attributes in the code to be detected one by one according to the prompt, and update the code to be detected based on the verification results to generate the updated code to be detected.
[0091] For example, during the process of verifying the target object attributes in the code to be detected, if it is determined that any target object attribute does not exist or is empty, the target object attribute can be deleted or replaced from the code to be detected. This embodiment does not specifically limit this.
[0092] The code detection method in this embodiment allows developers to use a detection plugin to detect the code to be detected when writing business logic in a Vue project. The plugin then provides user-friendly prompts based on the detection results, enabling developers to self-check their code and reduce unnecessary errors, thereby effectively improving the quality of the code to be detected.
[0093] Optionally, if the updated code to be detected, generated by the user based on the prompt, is obtained, the following method can be used: Figure 1 The code detection method shown detects the updated code to be detected; and if it is determined that there is a target object attribute in the updated code to be detected that satisfies the preset detection conditions, a prompt is issued based on the target object attribute in the updated code to be detected.
[0094] Optionally, first, determine whether there are object properties in the updated code to be detected. If the updated code to be detected contains object properties, trigger the detection plugin to detect each object property in the updated code to be detected.
[0095] Then, after obtaining the detection results of each object attribute in the updated code to be detected, it is determined whether the detection results of each object attribute in the updated code to be detected meet the preset detection conditions.
[0096] If the detection result of any object attribute in the updated code to be detected meets the preset detection conditions, then the object attribute is at risk of not existing or being empty, and the object attribute is taken as the target object attribute.
[0097] If the detection result of any object attribute in the updated code to be detected does not meet the preset detection conditions, then the object attribute does not have the risk of being non-existent or empty, and no operation is performed on the object attribute. The detection result of the next object attribute in the updated code to be detected is then judged.
[0098] This embodiment performs real-time detection on the user-updated code to be tested. When the updated code contains object attributes, the detection plugin is triggered to detect the object attributes in the updated code. When a target object attribute that meets the preset detection conditions is found, a prompt is promptly sent to the user. This allows the user to receive the prompt in a timely manner and check whether the target object attribute actually exists or is empty. This avoids problems such as code errors, execution stoppage, rendering freezes, and page crashes that can occur if the updated code is run directly. This effectively improves the quality and reliability of the code.
[0099] The code detection device provided by the present invention is described below. The code detection device described below can be referred to in correspondence with the code detection method described above.
[0100] like Figure 3 As shown, this embodiment provides a code detection device, which includes a first detection module 301, a second detection module 302, and a prompting module 303, wherein:
[0101] The first detection module 301 is used to trigger the detection plugin to detect the object attributes when the code to be detected contains object attributes;
[0102] The code detection method in this embodiment can be applied to computer devices, such as personal computers and servers, but this embodiment does not specifically limit it.
[0103] The code to be detected is the code that needs to be detected. The code to be detected can be front-end development code or back-end development code, etc. This embodiment does not make specific limitations on this.
[0104] The following description uses the front-end development code in a Vue project as an example to illustrate the code detection method in this embodiment.
[0105] The object property can be the object returned by the interface, other custom objects, or the properties of data content such as arrays. This embodiment does not specifically limit this.
[0106] Optionally, the code to be detected can be obtained in real time by user input;
[0107] Then, it is determined whether there are object properties in the code to be detected. If the code to be detected contains object properties, the detection plugin is triggered to detect each object property.
[0108] The detection plugin is the Eslint plugin that is pre-inserted into the Vue project.
[0109] If the code to be detected does not contain object properties, the detection plugin will not be triggered; the collection will continue to obtain the next piece of code to be detected.
[0110] The methods for determining whether object attributes exist in the code to be detected include comparing each part of the code to be detected with each object attribute in the object attribute set to determine whether object attributes exist in the code to be detected; or comparing the writing format of the code to be detected with the writing format of general object attributes to determine whether object attributes exist in the code to be detected. This embodiment does not specifically limit the method for determining whether object attributes exist in the code to be detected.
[0111] The second detection module 302 is used to take the object attributes in the code to be detected that meet the preset detection conditions as target object attributes;
[0112] Among them, the target object attribute is the object attribute that has the risk of not existing or being empty.
[0113] Optionally, after obtaining the detection results of the object attributes, it is determined whether the detection result of each object attribute meets the preset detection conditions.
[0114] The preset detection conditions are set according to the requirements of the embodiment, and this embodiment does not specifically limit them. The preset detection conditions limit the risk that the object attribute is non-existent or empty.
[0115] If the detection result of any object attribute meets the preset detection conditions, then the object attribute is at risk of not existing or being empty, and the object attribute is taken as the target object attribute.
[0116] If the detection result of any object attribute does not meet the preset detection conditions, then the object attribute does not have the risk of being non-existent or empty, and no operation is performed on the object attribute. The detection result of the next object attribute is then judged.
[0117] The prompting module 303 is used to issue a prompt based on the target object attribute in the code to be detected, so that the user can check whether the target object attribute exists or is empty based on the prompt.
[0118] Optionally, after obtaining the target object properties in the code to be detected, prompts can be provided for the target object properties.
[0119] Optionally, if a target object attribute that meets the preset detection conditions exists, it indicates that the target object attribute is at risk of not existing or being empty. A prompt is then issued to the user to alert them to this risk. Upon receiving the prompt, the user promptly verifies whether the target object attribute actually exists or is empty. If the user determines that the target object attribute does not exist or is empty, they promptly update the code to be detected, eliminating any non-existent or empty target object attributes, thereby effectively improving the reliability of the code's operation.
[0120] The prompting methods include, but are not limited to, voice or text, and this embodiment does not specifically limit them.
[0121] The verification method can be to search for the target object's attributes against a pre-acquired set of attributes. If the target object's attributes are found and are not empty, the prompt message is ignored; if they are not found or are empty, the code to be checked is updated.
[0122] This implementation uses a detection plugin to detect the code before it runs, so that users can receive prompts in time before the code runs and check whether the target object's properties actually exist or are empty. This avoids problems such as errors in the code being detected, execution stopping, rendering freezing, and page crashes that can occur if the code is run directly.
[0123] This embodiment acquires the code to be tested in real time. When the code contains object attributes, it triggers the detection plugin to detect the object attributes in the code. When a target object attribute that meets the preset detection conditions is found, a prompt is promptly sent to the user. This allows the user to receive the prompt in a timely manner and check whether the target object attribute actually exists or is empty. This avoids problems such as JavaScript script errors, execution stoppage, rendering freeze, and page crashes that may occur when the code to be tested is run directly. This effectively improves the quality and reliability of the code to be tested.
[0124] Based on the above embodiments, this embodiment also includes a determination module, used for: parsing the code to be detected based on the syntax tree; and determining whether the code to be detected contains object attributes based on the parsing results.
[0125] Optionally, after obtaining the code to be detected, the code can be parsed based on the syntax tree to map the statements in the code to each node in the tree.
[0126] Based on the analysis results, the relationship between words in the code to be detected can be determined, which facilitates the understanding of the hierarchical structure of the sentence syntax. Furthermore, through this hierarchical relationship, the attribute corresponding to each object in the code to be detected can be quickly determined, thereby quickly determining whether there are object attribute operations in the code to be detected.
[0127] This embodiment uses a syntax tree to parse the code to be detected, which can quickly and accurately determine whether the code to be detected contains object properties.
[0128] Based on the above embodiments, the detection plugin in this embodiment has built-in business logic; the first detection module is specifically used to: trigger the detection plugin to execute the business logic and detect the object attributes.
[0129] Optionally, the triggering detection plugin uses its internal business logic to perform logical operations on each object attribute in the code to be detected; the result of the logical operation is used as the detection result for each object attribute in the code to be detected.
[0130] Based on the above embodiments, the business logic in this embodiment is determined according to the general syntax rules under the code type corresponding to the code to be detected.
[0131] Optionally, in order to accurately detect whether the code to be detected has the risk of being non-existent or empty, the business logic inside the detection plugin can be written according to the general syntax rules of JavaScript code.
[0132] This embodiment uses the general syntax rules of JavaScript code to determine the business logic inside the detection plugin, making the code to be detected more reliable.
[0133] Regular expressions are logical formulas for string manipulation. They use predefined specific characters and combinations of these characters to form a string with certain rules, which can then be used to perform corresponding filtering logic on the string.
[0134] Based on the above embodiments, the business logic in this embodiment includes regular expressions and / or conditional statements.
[0135] Optionally, the business logic built into the code to be detected can be a regular expression, a conditional statement, or both a regular expression and a conditional statement. This embodiment does not specifically limit this.
[0136] Based on the above embodiments, the prompting module in this embodiment is specifically used to: generate prompting information for the target object attributes according to the syntax rules in Eslint and the target object attributes, and issue a prompt containing the prompting information.
[0137] Optionally, if it is determined that the target object property exists in the code to be detected, the target object property is returned to the Eslint side according to the error reporting rules in the syntax rules of Eslint. Eslint then generates a hint message for the target object property based on the target object property and the detection result, and issues a hint containing the hint message.
[0138] This embodiment uses Eslint to provide hints about the properties of the target object, which can promptly provide feedback to the user so that the user can make corresponding decisions about the code to be tested, such as modifying the code to be tested before compiling and running it.
[0139] Based on the above embodiments, this embodiment further includes an acquisition module, used to: acquire the updated code to be detected generated by the user according to the prompt; the prompting module is further used to issue a prompt based on the target object attribute in the updated code to be detected if there is a target object attribute in the updated code to be detected whose detection result meets the preset detection conditions.
[0140] Optionally, after receiving the prompt, the user can check the target object attributes in the code to be detected one by one according to the prompt, and update the code to be detected based on the verification results to generate the updated code to be detected.
[0141] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include a processor 401, a communication interface 402, a memory 403, and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other via the communication bus 404. The processor 401 can call logical instructions in the memory 403 to execute a code detection method. This method includes: if the code to be detected contains object attributes, triggering a detection plugin to detect the object attributes; identifying object attributes in the code to be detected that meet preset detection conditions as target object attributes; and issuing a prompt based on the target object attributes in the code to be detected, allowing the user to verify whether the target object attribute exists or is empty.
[0142] Furthermore, the logical instructions in the aforementioned memory 403 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0143] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the code detection method provided by the above methods. The method includes: triggering a detection plugin to detect the object attributes when the code to be detected contains object attributes; taking the object attributes in the code to be detected that meet the preset detection conditions as target object attributes; and issuing a prompt based on the target object attributes in the code to be detected, so that the user can check whether the target object attributes exist or are empty according to the prompt.
[0144] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the code detection method provided by the above methods. The method includes: triggering a detection plugin to detect the object attribute when the code to be detected contains an object attribute; taking the object attribute in the code to be detected that satisfies the detection result of a preset detection condition as a target object attribute; and issuing a prompt based on the target object attribute in the code to be detected, for the user to check whether the target object attribute exists or is empty based on the prompt.
[0145] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0146] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0147] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still update the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features. Such updates or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A code detection method characterized by, The method comprises the following steps: In the case that the object attribute is contained in the code to be detected, the code to be detected is parsed based on a syntax tree; According to the parsing result, it is determined whether the object attribute is contained in the code to be detected, which comprises the following steps: according to the parsing result, the relationship between each word in the code to be detected is determined, the hierarchy of the sentence syntax structure is obtained, the attribute corresponding to each object in the code to be detected is quickly determined through the hierarchical relationship, and then it is determined whether the object attribute operation exists in the code to be detected; the detection plug-in is triggered to detect the object attribute; The object attribute in the code to be detected, the detection result of which meets the preset detection condition, is taken as a target object attribute; According to the target object attribute in the code to be detected, a prompt is issued, which is used for the user to check whether the target object attribute exists or is empty according to the prompt; The detection plug-in is built-in business logic; the detection plug-in is triggered to detect the object attribute, which comprises the following steps: the detection plug-in is triggered to execute the business logic to detect the object attribute. The code to be detected is the front-end development code in a Vue project, and the object attribute comprises the attribute of data content; the data content comprises an object returned by an interface, other custom objects or an array.
2. The code detection method of claim 1, wherein, The business logic is determined according to the general syntax rule under the code type corresponding to the code to be detected.
3. The code detection method of claim 2, wherein, The business logic comprises a regular expression and / or a conditional judgment statement.
4. The code detection method according to any one of claim 1, characterized in that, According to the target object attribute in the code to be detected, the prompt is issued, which comprises the following steps: According to the syntax rule in Eslint and the target object attribute, the prompt information of the target object attribute is generated, and the prompt containing the prompt information is issued.
5. The code detection method of claim 1, wherein Further comprising: The updated code to be detected generated by the user according to the prompt is obtained; In the case that the target object attribute, the detection result of which meets the preset detection condition, exists in the updated code to be detected, a prompt is issued according to the target object attribute in the updated code to be detected.
6. A code detection apparatus characterized by comprising: The method comprises the following steps: A first detection module is used for parsing the code to be detected based on a syntax tree in the case that the object attribute is contained in the code to be detected; According to the parsing result, it is determined whether the object attribute is contained in the code to be detected, which comprises the following steps: according to the parsing result, the relationship between each word in the code to be detected is determined, the hierarchy of the sentence syntax structure is obtained, the attribute corresponding to each object in the code to be detected is quickly determined through the hierarchical relationship, and then it is determined whether the object attribute operation exists in the code to be detected; the detection plug-in is triggered to detect the object attribute, which comprises the following steps: the detection plug-in is triggered to execute the business logic to detect the object attribute; the detection plug-in is built-in business logic; A second detection module is used for taking the object attribute in the code to be detected, the detection result of which meets the preset detection condition, as a target object attribute; A prompt module is used for issuing a prompt according to the target object attribute in the code to be detected, which is used for the user to check whether the target object attribute exists or is empty according to the prompt; The to-be-detected code is front-end development code in a Vue project, and the object attribute includes an attribute of data content.
7. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the steps of the code detection method according to any one of claims 1 to 5 when executing the program.
8. A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program implements the steps of the code detection method according to any one of claims 1 to 5 when executed by the processor.
Citation Information
Patent Citations
Method and device for source code inspection
CN103294598A
Code file detection method and device and electronic equipment
CN111881059A