CN110502427A - Code readability inspection method, device and server - Google Patents

Code readability inspection method, device and server Download PDF

Info

Publication number
CN110502427A
CN110502427A CN201910608791.9A CN201910608791A CN110502427A CN 110502427 A CN110502427 A CN 110502427A CN 201910608791 A CN201910608791 A CN 201910608791A CN 110502427 A CN110502427 A CN 110502427A
Authority
CN
China
Prior art keywords
code
readability
standardization
lack
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910608791.9A
Other languages
Chinese (zh)
Inventor
江虹
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
OneConnect Smart Technology Co Ltd
Original Assignee
OneConnect Smart Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by OneConnect Smart Technology Co Ltd filed Critical OneConnect Smart Technology Co Ltd
Priority to CN201910608791.9A priority Critical patent/CN110502427A/en
Publication of CN110502427A publication Critical patent/CN110502427A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3616Software analysis for verifying properties of programs using software metrics

Landscapes

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

Abstract

The invention discloses a kind of code readability inspection methods, this method comprises: the code readability inspection for receiving user obtains the source code information of the code after requesting;Then the source code information is checked according to preset format specification, marks and record position and the number of code lack of standardization;Then marking again includes stating that the particular code element of variable and cyclical function body carries out tracking and trial operation in the source code information, then records position and number that wrong particular code element lack of standardization occurs in the process in trial operation;Last output code readability audit report.The present invention also provides a kind of code readability check device, server and computer readable storage mediums.Code readability inspection method, device, server and computer readable storage medium provided by the invention can check the use of format and particular code element in the source code information with deeper time, so as to more accurately and effectively check place lack of standardization.

Description

Code readability inspection method, device and server
Technical field
The present invention relates to code readability Examined effect field more particularly to a kind of code readability inspection method, device, Server and computer readable storage medium.
Background technique
For any development platform or enterprise, generally there are at least one code specification, code rule for code development Include the style and rule requirement for written in code in model.But for each research staff, have oneself writes habit It is used, so the requirement that the code quality write out does not meet affiliated item code specification can be frequently resulted in;In addition, being passed through for research and development Test the requirement that the code quality that insufficient research staff is also easy to write out does not meet affiliated item code specification;In this way, can Program can be caused to be unable to successful operation.
The prior art can provide the detection instrument of code quality for developer, so that developer is when writing code, Detect the code specification the requirement whether code quality oneself write meets affiliated project.But most of detection instrument is all The simple format for checking code, without to code logic or implementation effect check that therefore, the effect of inspection is very not Accurately.
Summary of the invention
In view of this, the present invention proposes a kind of personal code work readability inspection method, device, computer equipment and computer Readable storage medium storing program for executing obtains the source code information of the code after capable of receiving the code readability inspection request of user;Then The source code information is checked according to preset format specification, marks and record position and the number of code lack of standardization; Then mark again in the source code information include statement variable and cyclical function body particular code element carry out tracking and Then trial operation records trial operation and occurs position and the number of the particular code element lack of standardization of mistake in the process;Finally export Code readability audit report.It therefore, can be with the secondary format and particular code element in the source code information of deeper Using being checked, so as to more accurately and effectively check place lack of standardization.
Firstly, to achieve the above object, the present invention provides a kind of code readability inspection method, and the method includes steps It is rapid:
The code readability inspection request for receiving user, obtains the source code information of the code;According to preset format Specification checks the source code information, and the source code lack of standardization for not meeting the format specification is marked, and remembers Record position and the number of the code lack of standardization;The particular code element in the source code information is marked, and to the spy Determine code element and carry out tracking and trial operation, wherein the particular code element includes statement variable and cyclical function body;Record Occur position and the number of the particular code element lack of standardization of mistake during trial operation;Output code readability audit report.
Optionally, the format specification includes: name format specification and code typesetting format specification, wherein code typesetting Format includes: null, retraction, annotation and duplicated code;It is described " the source code information to be carried out according to preset format specification The step of inspection " includes: to judge whether the title of the source code information meets Naming conventions in such a way that text compares, and is sentenced Whether null, retraction, annotation and duplicated code in the source code information of breaking meet format specification.
Optionally, described " occurring position and the number of the particular code element lack of standardization of mistake during record trial operation " Step includes: to find out the particular code element by text alignments;And: to the statement variable label found at first For original assertion variable, when then finding the statement variable every time, then the code segment for the statement variable occur is carried out Trial operation judges whether the statement variable is capable of calling original assertion variable, then judges institute when calling to original assertion variable Stating statement variable is the statement variable for mistake occur;Trial operation is carried out for the code segment of the cyclical function found out, judges institute Whether the time for stating cyclical function operation is more than preset time threshold, and the circulation letter is then judged when more than the time threshold The number cyclical function wrong for appearance.
Optionally, the step of described " output code readability audit report " includes: according to the code lack of standardization and institute out It states the number that particular code element lack of standardization occurs and Quantitative marking is carried out to the code respectively;Then Quantitative marking is lower than When preset point threshold, label is readable poor in the code readability audit report.
In addition, to achieve the above object, the present invention also provides a kind of code readability check device, described device includes:
Receiving module, the code readability inspection for receiving user are requested, and the source code information of the code is obtained;The One checks module, for being checked according to preset format specification the source code information, advises to the format is not met The source code lack of standardization of model is marked, and records position and the number of the code lack of standardization;Second checks module, for marking Remember the particular code element in the source code information out, and tracking and trial operation carried out to the particular code element, wherein The particular code element includes statement variable and cyclical function body;Described second checks module, is also used to record commissioned Occur position and the number of the particular code element lack of standardization of mistake in journey;Output module is used for the inspection of output code readability Report.
Optionally, the format specification includes: name format specification and code typesetting format specification, wherein code typesetting Format includes: null, retraction, annotation and duplicated code;The first inspection module is also used to sentence in such a way that text compares Whether the title for the source code information of breaking meets Naming conventions, judge null in the source code information, retraction, annotation and Whether duplicated code meets format specification.
Optionally, it described second checks module, is also used to find out the particular code element by text alignments;With And: it is original assertion variable to the statement variable label found at first, it is when then finding the statement variable every time, then right The code segment for the statement variable occur carries out trial operation, judges whether the statement variable is capable of calling original assertion variable, It calls and judges the statement variable when original assertion variable then to there is the statement variable of mistake;For the circulation letter found out Several code segments carries out trial operation, judges whether the time of the cyclical function operation is more than preset time threshold, is more than institute The cyclical function is judged when stating time threshold then to there is the cyclical function of mistake.
Optionally, the output module is also used to: according to the code lack of standardization out and the particular code element lack of standardization The number of appearance carries out Quantitative marking to the code respectively;When being then lower than preset point threshold for Quantitative marking, In Label is readable poor in the code readability audit report.
Further, the present invention also proposes that a kind of server, the server include memory, processor, the storage The computer program that can be run on the processor is stored on device, it is real when the computer program is executed by the processor Now such as the step of above-mentioned code readability inspection method.
Further, to achieve the above object, the present invention also provides a kind of computer readable storage medium, the computers Readable storage medium storing program for executing is stored with computer program, and the computer program can be executed by least one processor so that it is described extremely A few processor is executed such as the step of above-mentioned code readability inspection method.
Compared to the prior art, code readability inspection method, device, computer equipment and calculating proposed by the invention Machine readable storage medium storing program for executing obtains the source code information of the code after capable of receiving the code readability inspection request of user;So The source code information is checked according to preset format specification afterwards, mark and record code lack of standardization position and time Number;Then mark again in the source code information includes stating that the particular code element of variable and cyclical function body is tracked And trial operation, it then records trial operation and occurs position and the number of the particular code element lack of standardization of mistake in the process;It is last defeated Code readability audit report out.It therefore, can be with deeper time to the format and particular code element in the source code information Use checked, so as to more accurately and effectively check place lack of standardization.
Detailed description of the invention
Fig. 1 is the schematic diagram of the optional hardware structure of server one of the present invention;
Fig. 2 is the program module schematic diagram of one embodiment of code readability check device of the present invention;
Fig. 3 is the flow diagram of code readability inspection method first embodiment of the present invention.
Appended drawing reference:
The object of the invention is realized, the embodiments will be further described with reference to the accompanying drawings for functional characteristics and advantage.
Specific embodiment
In order to make the objectives, technical solutions, and advantages of the present invention clearer, with reference to the accompanying drawings and embodiments, right The present invention is further elaborated.It should be appreciated that described herein, specific examples are only used to explain the present invention, not For limiting the present invention.Based on the embodiments of the present invention, those of ordinary skill in the art are not before making creative work Every other embodiment obtained is put, shall fall within the protection scope of the present invention.
It should be noted that the description for being related to " first ", " second " etc. in the present invention is used for description purposes only, and cannot It is interpreted as its relative importance of indication or suggestion or implicitly indicates the quantity of indicated technical characteristic.Define as a result, " the One ", the feature of " second " can explicitly or implicitly include at least one of the features.In addition, the skill between each embodiment Art scheme can be combined with each other, but must be based on can be realized by those of ordinary skill in the art, when technical solution Will be understood that the combination of this technical solution is not present in conjunction with there is conflicting or cannot achieve when, also not the present invention claims Protection scope within.
As shown in fig.1, being the schematic diagram of the optional hardware structure of server 1 one of the present invention.
In the present embodiment, the server 1 may include, but be not limited only to, and can be in communication with each other connection by system bus and deposit Reservoir 11, processor 12, network interface 13.
The server 1 connects network (Fig. 1 is not marked) by network interface 13, by network connection to other systems or Person's terminal device such as mobile terminal, the end PC, development system and test macro etc..The network can be intranet (Intranet), internet (Internet), global system for mobile communications (Global System of Mobile Communication, GSM), wideband code division multiple access (Wideband Code Division Multiple Access, WCDMA), the wirelessly or non-wirelessly network such as 4G network, 5G network, bluetooth (Bluetooth), Wi-Fi, speech path network.
It should be pointed out that Fig. 1 illustrates only the server 1 with component 11-13, it should be understood that simultaneously should not Realistic to apply all components shown, the implementation that can be substituted is more or less component.
Wherein, the memory 11 includes at least a type of readable storage medium storing program for executing, and the readable storage medium storing program for executing includes Flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory etc.), random access storage device (RAM), it is static with Machine accesses memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable Read memory (PROM), magnetic storage, disk, CD etc..In some embodiments, the memory 11 can be the clothes The internal storage unit of business device 1, such as the hard disk or memory of the server 1.In further embodiments, the memory 11 It can be the External memory equipment of the server 1, such as the plug-in type hard disk that the server 1 is equipped with, intelligent memory card (Smart Media Card, SMC), secure digital (Secure Digital, SD) card, flash card (Flash Card) etc..When So, the memory 11 can also both including the server 1 internal storage unit and also including its External memory equipment.This reality It applies in example, the memory 11 is installed on the operating system and types of applications software of the server 1 commonly used in storage, such as The program code etc. of code readability check device 200.In addition, the memory 11 can be also used for temporarily storing it is defeated Out or the Various types of data that will export.
The processor 12 can be in some embodiments central processing unit (Central Processing Unit, CPU), controller, microcontroller, microprocessor or other data processing chips.The processor 12 is commonly used in the control clothes The overall operation of business device 1, such as execute data interaction or the relevant control of communication and processing etc..In the present embodiment, the place Reason device 12 is for running the program code stored in the memory 11 or processing data, such as to run the code readable Property check device 200 etc..
The network interface 13 may include radio network interface or wired network interface, which is commonly used in Between the server 1 and other systems or terminal device such as mobile terminal, the end PC, development system and test macro etc. Establish communication connection.
In the present embodiment, when installing in the server 1 and run code readability check device 200, when the generation When the readable check device 200 of code is run, the source that the code is obtained after the code readability inspection request of user can be received Code information;Then the source code information is checked according to preset format specification, marks and records code lack of standardization Position and number;Then marking again includes the particular code member for stating variable and cyclical function body in the source code information Element carry out tracking and trial operation, then record trial operation during occur mistake particular code element lack of standardization position and time Number;Last output code readability audit report.It therefore, can be with deeper time to format in the source code information and specific The use of code element is checked, so as to more accurately and effectively check place lack of standardization.
So far, oneself is through describing the application environment of each embodiment of the present invention and the hardware configuration and function of relevant device in detail Energy.In the following, above-mentioned application environment and relevant device will be based on, each embodiment of the invention is proposed.
Firstly, the present invention proposes a kind of code readability check device 200.
As shown in fig.2, being the Program modual graph of 200 1 embodiment of code readability check device of the present invention.
In the present embodiment, the code readability check device 200 includes a series of meter being stored on memory 11 The code of various embodiments of the present invention may be implemented when the computer program instructions are executed by processor 12 in calculation machine program instruction Readable audit function.In some embodiments, the specific operation realized based on the computer program instructions each section, generation The readable check device 200 of code can be divided into one or more modules.For example, in Fig. 2, the code readability inspection Device 200 can be divided into receiving module 201, first and check that module 202, second checks module 203 and output module 204. Wherein:
The receiving module 201, the code readability inspection for receiving user are requested, and the source code of the code is obtained Information.
It specifically,, then can be by institute after developer has newly write the code of an application function in R&D process It states code and is submitted to development system, and submit to the server 1 request of the code readability inspection of the code.So, The receiving module 201 of opening then receives the code readability inspection request, and obtains the source code information of the code.Its In, the server 1 is preset can carry out readable inspection, including JAVA, C+ to the application code that different language is write +/C, Android, the code that the language such as iOS, H5 are write.
Described first checks module 202, right for being checked according to preset format specification the source code information The source code lack of standardization for not meeting the format specification is marked, and records position and the number of the code lack of standardization.
In the present embodiment, the format specification includes: name format specification and code typesetting format specification, wherein generation Code typesetting format includes: null, retraction, annotation and duplicated code;Described first checks module 202 in such a way that text compares Judge whether the title of the source code information meets Naming conventions, and judge null in the source code information, retraction, Whether annotation and duplicated code meet format specification.
Specifically, the receiving module 201 is receiving the request of the code readability inspection and is getting source code After information, the first inspection module 202 can then be checked the source code.In the present embodiment, first inspection It looks into module 202 to check the source code of the code according to preset name format specification, marks in source program and name Nonstandard position;Wherein, name format includes catalogue name and file designation.For example, source program corresponding to code, is to belong to In what project, then the catalogue name of the code then accordingly uses before identical title with other codes of the project Sew or suffix;Also, the title of the code is also required to consistent with the title of project, could make so subsequent for generation The identification or lookup of code, it is more convenient.That is, the code of specification needs to accomplish to advise in terms of catalogue name and file designation Model, such mode could preferably manage and maintain the code.The first inspection module 202 is named the code It after format specification checks, can be also marked in the part for not meeting Naming conventions of the code, for example, the exploitation is managed Reason system exports the partial content of the name lack of standardization of the code in the form of inspection result.For example, working as belonging to the code Project include " AAA " printed words, then the related data of the code can all store " AAA " word according to Naming conventions principle Under the catalogue of sample, and the relevant data of the project can all be named as the title including " AAA " printed words such as " AAA executes file ". When the code belongs to the project, but it is named as " BBB code ", then, the first inspection module 202 can then named Outgoing inspection is reported such as after normalization checks: file name " BBB code " name is lack of standardization, and name should include " AAA " word Sample.
Then, described first check that module 202, can also be according to default after being named normalized checking to the code Typesetting format specification the source code of the code is checked, then mark the nonstandard position of typesetting in source code; Wherein, typesetting format includes null, retraction and annotation and duplicated code.In the present embodiment, described first check that module 202 is examined It looks into after directory name and the file name of the code, then can read the source code of the code, and according to source code The due typesetting format specification of body part checks the source program of the code.For example, typesetting format packet in source program It includes: being retracted two characters before every row content, two rows must be separated in code among every two function, annotation is no more than 3 rows Content.Nima, the development management system then can be using the format specifications of the typesetting as foundation, and to the source journey of the code Sequence text is checked.When more than appearance nonstandard place in the source program code, then described first checks module 202 The progress of the source code of the code can then be marked accordingly.For example, when the first inspection module 202 identifies more annotation languages When sentence head " // * " symbol of sentence, then judge whether 3 rows then write source code content.When more than 3 row contents, then described First inspection module 202 then thinks the typesetting format and lack of standardization, and then the first inspection module 202 is not advised to described then The place of model or content are marked.In addition, it is described first inspection module 202 can also the source code to the code carry out weight Multiplexed code inspection.In general, if any a large amount of duplicated codes it is extractable go out public function, can call later the public function with The size of source program is reduced, so, when there are many duplicated codes, then it can carry out code reuse.Therefore, first inspection Whether look into module 202 includes identifying in the source program of the code to go out according to the mode that text compares for the inspection of duplicated code Existing identical function body then judges the source code when the number for identical function body occur is more than preset first threshold There is duplicated code, then then the source code can be marked.
Described second checks module 203, for marking the particular code element in the source code information, and to described Particular code element carries out tracking and trial operation, wherein the particular code element includes statement variable and cyclical function body;And It records trial operation and occurs position and the number of the particular code element lack of standardization of mistake in the process.
Specifically, the second inspection module 203 finds out the particular code element by text alignments;And: It is original assertion variable to the statement variable label found at first, when then finding the statement variable every time, then to out The code segment of the existing statement variable carries out trial operation, judges whether the statement variable is capable of calling original assertion variable, when It does not call and judges the statement variable when original assertion variable then to there is the statement variable of mistake;It is followed for what is found out The code segment of ring function carries out trial operation, judges whether the time of the cyclical function operation is more than preset time threshold, is surpassed The cyclical function is judged when crossing the time threshold then to there is the cyclical function of mistake.
In the present embodiment, it described second checks the problem unreferenced for statement variable of module 203, may search for stating The defined function head of variable, then obtain statement variable title and be labeled as original assertion variable, then again to source code into Row retrieval, when it is subsequent there is the statement variable name when, then to occur it is described statement variable code segment carry out trial operation, judge institute It states whether statement variable is capable of calling original assertion variable, the statement change is then judged when not having and calling to original assertion variable The amount statement variable wrong for appearance.Such as " define () " is the function header of variable-definition, then described second checks module 203 search for the function header, then obtain the statement name variable in function, such as X, then carry out full-text search, look into when subsequent When finding X, then trial operation is carried out to the function body where the X, then traces whether X is " define by log information The X stated in () " function header.If it is not, the X that the so described second inspection module 203 then judges subsequent appearance is mistake Statement variable.And the inspection for cyclical function, described second checks module 203 first according to cyclical function predetermined Cyclical function head retrieve in the source code of the code, for example, " if () " and " for () ";Then described in inquiry The corresponding function body of cyclical function head, and the trial operation of preset time is carried out to the function body, such as each circulation Function body is executed, and calculates the execution time of the cyclical function body.In the present embodiment, described second module is checked 203 carry out trial operation according to 1/10 variable of the cycle-index of each cyclical function, for example, in " for () " function, variable model It encloses are as follows: N≤i≤M, then the range of variables of trial operation is N≤i≤(M-N)/M, wherein (M-N)/M is rounded;It is opened when described When the time that hair management system records the cyclical function body trial operation is more than preset third threshold value, then illustrate to follow described in operation The overlong time of ring function body, it is too long to causing Caton crash phenomenon to may result in the code execution time, therefore, institute Can then the corresponding source code of the cyclical function be marked by stating the second inspection module 203, labeled as following for appearance mistake Ring function.
The output module 204 is used for output code readability audit report.
Specifically, it is checked in the first inspection module 202 and the second inspection module 203 lack of standardization in the code After code and particular code element lack of standardization, the data module 204 is then further according to the code lack of standardization and described The number that particular code element lack of standardization occurs carries out Quantitative marking to the code respectively, then for Quantitative marking lower than pre- If point threshold when, label is readable poor in the code readability audit report.
For example, code is initially divided into 100, occur once when code lack of standardization is every, then 1 point of button, and particular code lack of standardization Element code is every to be occurred once, then detaining 3 points;Then the output module 204 finally scores and preset point according to the code Such as 60 points of value threshold value are compared, when the final scoring of the code is lower than 60 points in the code readability audit report It is readable poor labeled as code.
It will be recalled from above that the code readability inspection that the server 1 can receive user obtains the code after requesting Source code information;Then the source code information is checked according to preset format specification, marks and records lack of standardization The position of code and number;Then marking again includes the specific generation for stating variable and cyclical function body in the source code information Data code carries out tracking and trial operation, then records the position that the particular code element lack of standardization of mistake occurs in the process in trial operation And number;Last output code readability audit report.Therefore, can with deeper time in the source code information format and The use of particular code element is checked, so as to more accurately and effectively check place lack of standardization.
In addition, the present invention also proposes that a kind of code readability inspection method, the method are applied to server.
As shown in fig.3, being the flow diagram of code readability inspection method first embodiment of the present invention.In this implementation In example, the execution sequence of the step in flow chart shown in Fig. 3 be can change according to different requirements, and certain steps can save Slightly.
Step S500 receives the code readability inspection request of user, obtains the source code information of the code.
It specifically,, then can be by institute after developer has newly write the code of an application function in R&D process It states code and is submitted to development system, and submit to the server request of the code readability inspection of the code.So, institute It states server and then receives the code readability inspection request, and obtain the source code information of the code.Wherein, the service Device is preset can carry out readable inspection, including JAVA, C++/C, Android to the application code that different language is write, The code that the language such as iOS, H5 are write.
Step S502 checks the source code information according to preset format specification, to not meeting the format The source code lack of standardization of specification is marked, and records position and the number of the code lack of standardization.
In the present embodiment, the format specification includes: name format specification and code typesetting format specification, wherein generation Code typesetting format includes: null, retraction, annotation and duplicated code;Described first checks module 202 in such a way that text compares Judge whether the title of the source code information meets Naming conventions, and judge null in the source code information, retraction, Whether annotation and duplicated code meet format specification.
Specifically, the server receive the request of the code readability inspection and get source code information it Afterwards, the server can then check the source code.In the present embodiment, the server is according to preset name lattice Formula specification checks the source code of the code, marks and names nonstandard position in source program;Wherein, format is named Including catalogue name and file designation.For example, source program corresponding to code, is to belong in what project, then the code Catalogue name then accordingly with other codes of the project use identical name prefix or suffix;Also, the code Title be also required to consistent with the title of project, subsequent identification or lookup for code could be made in this way, it is more convenient. That is, the code of specification needs to accomplish to standardize in terms of catalogue name and file designation, such mode could be managed preferably Manage and safeguard the code.It, can also be in the code after the server is named format specification inspection to the code The part for not meeting Naming conventions be marked, for example, described in the development management system exports in the form of inspection result The partial content of the name lack of standardization of code.For example, working as project belonging to the code includes " AAA " printed words, then according to life Name regulative principle, the related data of the code can all store under the catalogue of " AAA " printed words, and the relevant data of the project The title including " AAA " printed words such as " AAA executes file " will be named as.When the code belongs to the project, but name For " BBB code ", then, the server then can outgoing inspection report be such as: file name after Naming conventions inspection " BBB code " name is lack of standardization, and name should include " AAA " printed words.
Then, the server, can also be according to preset typesetting lattice after being named normalized checking to the code Formula specification checks the source code of the code, then marks the nonstandard position of typesetting in source code;Wherein, typesetting Format includes null, retraction and annotation and duplicated code.In the present embodiment, the server checks the directory name of the code Claim then to can read the source code of the code, and according to the due typesetting of the body part of source code with after file name Format specification checks the source program of the code.For example, typesetting format includes: to be retracted two before every row content in source program A character must separate two rows, content of the annotation no more than 3 rows in code among every two function.Nima, the exploitation pipe Reason system then can be using the format specification of the typesetting as foundation, and checks the source text of the code.Work as institute It states in source program code and the above nonstandard place occurs, then described first checks that module 202 then can be to the source of the code The progress of code marks accordingly.For example, then judging when the server identifies sentence head " // * " symbol of more comment statements Whether 3 rows then write source code content.When more than 3 row contents, then the server then thinks the typesetting format simultaneously It is lack of standardization, then the nonstandard place or content are marked.In addition, the server can also be to the code Source code carries out duplicated code inspection.In general, it if any the extractable public function out of a large amount of duplicated codes, can call later The public function to reduce the size of source program, so, when there are many duplicated codes, then can carry out code reuse.Cause This, the server, which includes in the source program for identify the code according to the mode that text compares for the inspection of duplicated code, is It is no identical function body occur, when the number for identical function body occur is more than preset first threshold, then judge the source There is duplicated code in code, then then the source code can be marked.
Step S504, marks the particular code element in the source code information, and to the particular code element into Line trace and trial operation, wherein the particular code element includes statement variable and cyclical function body;And record trial operation process The position of the middle particular code element lack of standardization for mistake occur and number.
Specifically, the server finds out the particular code element by text alignments;And: to searching at first The statement variable label arrived is original assertion variable, when then finding the statement variable every time, then to the appearance statement The code segment of variable carries out trial operation, judges whether the statement variable is capable of calling original assertion variable, arrives when not having to call The statement variable is judged when original assertion variable then to there is the statement variable of mistake;Generation for the cyclical function found out Code section carries out trial operation, judges whether the time of the cyclical function operation is more than preset time threshold, is more than the time The cyclical function is judged when threshold value then to there is the cyclical function of mistake.
In the present embodiment, the server problem unreferenced for statement variable, may search for determining for statement variable Then adopted function header obtains the title of statement variable and is labeled as original assertion variable, then retrieves again to source code, when It is subsequent that trial operation then is carried out to the code segment for the statement variable occur when there is the statement variable name, judge the statement change Whether amount is capable of calling original assertion variable, then judges the statement variable for appearance when not having and calling to original assertion variable The statement variable of mistake.Such as " define () " is the function header of variable-definition, then the server search function header, Then obtain the statement name variable in function, such as X then carries out full-text search, when it is subsequent find X when, then to the X The function body at place carries out trial operation, then traces whether X is the X stated in " define () " function header by log information. If it is not, the X that the so described server then judges subsequent appearance is wrong statement variable.And the inspection for cyclical function It looks into, progress of the server first according to the cyclical function head of cyclical function predetermined in the source code of the code Retrieval, for example, " if () " and " for () ";Then the corresponding function body of the cyclical function head is inquired, and to the function body The trial operation of preset time is carried out, such as each cyclical function body is executed, and calculate the cyclical function body Execute the time.In the present embodiment, the server carries out trial operation according to 1/10 variable of the cycle-index of each cyclical function, For example, in " for () " function, range of variables are as follows: N≤i≤M, then the range of variables of trial operation be N≤i≤(M-N)/ M, wherein (M-N)/M is rounded;It is more than preset when the time that the development management system records the cyclical function body trial operation When third threshold value, then illustrates the overlong time for running the cyclical function body, it is too long to may result in the code execution time To cause Caton crash phenomenon, therefore, the server can be then marked the corresponding source code of the cyclical function, Labeled as the cyclical function for mistake occur.
Step S506, output code readability audit report.
Specifically, the server check code lack of standardization in the code and particular code element lack of standardization it Afterwards, the number that can be also further occurred according to the code lack of standardization and the particular code element lack of standardization is respectively to the generation Code carries out Quantitative marking, when being then lower than preset point threshold for Quantitative marking, in the code readability audit report Middle label is readable poor.
For example, code is initially divided into 100, occur once when code lack of standardization is every, then 1 point of button, and particular code lack of standardization Element code is every to be occurred once, then detaining 3 points;Then the server finally scores and preset point threshold according to the code Such as 60 points be compared, when the code final scoring lower than 60 points in the code readability audit report label for Code is readable poor.
After the code readability that the code readability inspection method that the present embodiment is proposed can receive user checks request Obtain the source code information of the code;Then the source code information is checked according to preset format specification, is marked And record position and the number of code lack of standardization;Then mark again in the source code information includes statement variable and circulation letter The particular code element of number body carries out tracking and trial operation, then records the specific generation lack of standardization of appearance mistake during trial operation The position of data code and number;Last output code readability audit report.Therefore, the source code can be believed with deeper time The use of format and particular code element in breath checked, so as to more accurately and effectively check it is lack of standardization it Place.
The serial number of the above embodiments of the invention is only for description, does not represent the advantages or disadvantages of the embodiments.
Through the above description of the embodiments, those skilled in the art can be understood that above-described embodiment side Method can be realized by means of software and necessary general hardware platform, naturally it is also possible to by hardware, but in many cases The former is more preferably embodiment.Based on this understanding, technical solution of the present invention substantially in other words does the prior art The part contributed out can be embodied in the form of software products, which is stored in a storage medium In (such as ROM/RAM, magnetic disk, CD), including some instructions are used so that a terminal device (can be mobile phone, computer, clothes Business device, air conditioner or the network equipment etc.) execute method described in each embodiment of the present invention.
The above is only a preferred embodiment of the present invention, is not intended to limit the scope of the invention, all to utilize this hair Equivalent structure or equivalent flow shift made by bright specification and accompanying drawing content is applied directly or indirectly in other relevant skills Art field, is included within the scope of the present invention.

Claims (10)

1. a kind of code readability inspection method, which is characterized in that the method includes the steps:
The code readability inspection request for receiving user, obtains the source code information of the code;
The source code information is checked according to preset format specification, to the source lack of standardization for not meeting the format specification Code is marked, and records position and the number of the code lack of standardization;
The particular code element in the source code information is marked, and tracking and test run are carried out to the particular code element Row, wherein the particular code element includes statement variable and cyclical function body;
It records trial operation and occurs position and the number of the particular code element lack of standardization of mistake in the process;
Output code readability audit report.
2. code readability inspection method as described in claim 1, which is characterized in that
The format specification includes: name format specification and code typesetting format specification, wherein code typesetting format includes: sky Row, retraction, annotation and duplicated code;
The step of described " being checked according to preset format specification the source code information " includes: to be compared by text Mode judges whether the title of the source code information meets Naming conventions, judge null in the source code information, retraction, Whether annotation and duplicated code meet format specification.
3. code readability inspection method as described in claim 1, which is characterized in that described " to go out during record trial operation The position of the particular code element lack of standardization of existing mistake and number " step includes:
The particular code element is found out by text alignments;And:
It is original assertion variable to the statement variable label found at first, when then finding the statement variable every time, then Trial operation is carried out to the code segment for the statement variable occur, judges whether the statement variable is capable of calling original assertion change Amount then judges that the statement variable is appearance wrong statement variable when calling to original assertion variable;
Trial operation is carried out for the code segment of cyclical function found out, judge the cyclical function operation time whether be more than Preset time threshold judges the cyclical function then to there is the cyclical function of mistake when more than the time threshold.
4. code readability inspection method as described in claim 1, which is characterized in that " the output code readability inspection Report " the step of include:
Quantitative marking is carried out respectively to the code lack of standardization and particular code element lack of standardization according to frequency of occurrence;
When being then lower than preset point threshold for Quantitative marking, label is in the code readability audit report It is readable poor.
5. a kind of code readability check device, which is characterized in that described device includes:
Receiving module, the code readability inspection for receiving user are requested, and the source code information of the code is obtained;
First checks module, described to not meeting for being checked according to preset format specification the source code information The source code lack of standardization of format specification is marked, and records position and the number of the code lack of standardization;
Second checks module, for marking the particular code element in the source code information, and to the particular code member Element carries out tracking and trial operation, wherein the particular code element includes statement variable and cyclical function body;
Described second checks module, is also used to record the position that the particular code element lack of standardization of mistake occurs in the process in trial operation And number;
Output module is used for output code readability audit report.
6. code readability check device as claimed in claim 5, which is characterized in that the format specification includes: name lattice Formula specification and code typesetting format specification, wherein code typesetting format includes: null, retraction, annotation and duplicated code;It is described First checks that module is also used to judge whether the title of the source code information meets Naming conventions in such a way that text compares, Judge whether null, retraction, annotation and duplicated code in the source code information meet format specification.
7. such as code readability check device described in claim 5 or 6, it is characterised in that:
Described second checks module, is also used to find out the particular code element by text alignments;And:
It is original assertion variable to the statement variable label found at first, when then finding the statement variable every time, then Trial operation is carried out to the code segment for the statement variable occur, judges whether the statement variable is capable of calling original assertion change Amount then judges that the statement variable is the wrong statement variable of appearance when not having and calling to original assertion variable;
Trial operation is carried out for the code segment of cyclical function found out, judge the cyclical function operation time whether be more than Preset time threshold judges the cyclical function then to there is the cyclical function of mistake when more than the time threshold.
8. code readability check device as claimed in claim 7, which is characterized in that the output module is also used to:
The number occurred according to the code lack of standardization out and the particular code element lack of standardization is respectively to the code amount of progress Change scoring;
When being then lower than preset point threshold for Quantitative marking, label is in the code readability audit report It is readable poor.
9. a kind of server, which is characterized in that the server includes memory, processor, and being stored on the memory can The computer program run on the processor realizes such as claim when the computer program is executed by the processor The step of 1-4 described in any item code readability inspection methods.
10. a kind of computer readable storage medium, which is characterized in that the computer-readable recording medium storage has computer journey Sequence, the computer program can be executed by least one processor, so that at least one described processor executes such as claim Described in any one of 1-4 the step of code readability inspection method.
CN201910608791.9A 2019-07-08 2019-07-08 Code readability inspection method, device and server Pending CN110502427A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910608791.9A CN110502427A (en) 2019-07-08 2019-07-08 Code readability inspection method, device and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910608791.9A CN110502427A (en) 2019-07-08 2019-07-08 Code readability inspection method, device and server

Publications (1)

Publication Number Publication Date
CN110502427A true CN110502427A (en) 2019-11-26

Family

ID=68586196

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910608791.9A Pending CN110502427A (en) 2019-07-08 2019-07-08 Code readability inspection method, device and server

Country Status (1)

Country Link
CN (1) CN110502427A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112276263A (en) * 2020-10-14 2021-01-29 宁波市博虹机械制造开发有限公司 G code-based special motion control method for electric spark forming machine
CN116980296A (en) * 2022-04-21 2023-10-31 慧与发展有限责任合伙企业 Automatic global configuration error removal for clustered network devices

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112276263A (en) * 2020-10-14 2021-01-29 宁波市博虹机械制造开发有限公司 G code-based special motion control method for electric spark forming machine
CN116980296A (en) * 2022-04-21 2023-10-31 慧与发展有限责任合伙企业 Automatic global configuration error removal for clustered network devices

Similar Documents

Publication Publication Date Title
US8271470B2 (en) Auto-activation of fonts
CN110502608A (en) The interactive method and human-computer dialogue device of knowledge based map
US20080086718A1 (en) Method and Apparatus for Identifying Authors of Changes Between Multiple Versions of a File
CN107038256A (en) Business customizing device, method and computer-readable recording medium based on data source
CN104391725A (en) Page display method and page display device
CN102804147A (en) Code inspection executing system for performing a code inspection of ABAP source codes
CN111061742B (en) Method and device for marking data and service system thereof
CN111159982B (en) Document editing method, device, electronic equipment and computer readable storage medium
CN107800757B (en) User behavior recording method and device
CN110007906B (en) Script file processing method and device and server
CN107832676A (en) Form data line feed recognition methods, electronic equipment and computer-readable recording medium
CN112256849B (en) Model training method, text detection method, device, equipment and storage medium
CN107844468A (en) The cross-page recognition methods of form data, electronic equipment and computer-readable recording medium
CN110866258A (en) Method for quickly positioning bug, electronic device and storage medium
CN110502427A (en) Code readability inspection method, device and server
CN113157854B (en) API sensitive data leakage detection method and system
US9767086B2 (en) System and method for enablement of data masking for web documents
CN111754352A (en) Method, device, equipment and storage medium for judging correctness of viewpoint statement
WO2019041529A1 (en) Method, electronic apparatus, and computer readable storage medium for identifying company as subject of news report
CN113438216B (en) Access control method based on security marker
CN113468315B (en) Vulnerability vendor name matching method
CN107766228B (en) Multi-language-based automatic testing method and device
CN115186240A (en) Social network user alignment method, device and medium based on relevance information
CN111125567B (en) Equipment marking method, device, electronic equipment and storage medium
CN112364640A (en) Entity noun linking method, device, computer equipment and storage medium

Legal Events

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