1- const fs = require ( 'fs' ) ;
2- const path = require ( ' path' ) ;
1+ const fs = require ( "fs" ) ;
2+ const path = require ( " path" ) ;
33
44function loadContent ( content ) {
55 const Module = module . constructor ;
@@ -15,7 +15,7 @@ function loadContent(content) {
1515}
1616
1717function readFile ( filePath ) {
18- return fs . readFileSync ( filePath , ' utf8' ) ;
18+ return fs . readFileSync ( filePath , " utf8" ) ;
1919}
2020
2121function contentToDiffLine ( key , value ) {
@@ -25,41 +25,41 @@ function contentToDiffLine(key, value) {
2525// This function is only called when no matching result was found and therefore will only display
2626// the diff between the two items.
2727function betterLookingDiff ( entry , data ) {
28- let output = ' {\n' ;
29- const spaces = ' ' ;
28+ let output = " {\n" ;
29+ const spaces = " " ;
3030 for ( const key in entry ) {
31- if ( ! entry . hasOwnProperty ( key ) ) {
31+ if ( ! Object . prototype . hasOwnProperty . call ( entry , key ) ) {
3232 continue ;
3333 }
34- if ( ! data || ! data . hasOwnProperty ( key ) ) {
35- output += '-' + spaces + contentToDiffLine ( key , entry [ key ] ) + '\n' ;
34+ if ( ! data || ! Object . prototype . hasOwnProperty . call ( data , key ) ) {
35+ output += "-" + spaces + contentToDiffLine ( key , entry [ key ] ) + "\n" ;
3636 continue ;
3737 }
3838 const value = data [ key ] ;
3939 if ( value !== entry [ key ] ) {
40- output += '-' + spaces + contentToDiffLine ( key , entry [ key ] ) + '\n' ;
41- output += '+' + spaces + contentToDiffLine ( key , value ) + '\n' ;
40+ output += "-" + spaces + contentToDiffLine ( key , entry [ key ] ) + "\n" ;
41+ output += "+" + spaces + contentToDiffLine ( key , value ) + "\n" ;
4242 } else {
43- output += spaces + contentToDiffLine ( key , value ) + '\n' ;
43+ output += spaces + contentToDiffLine ( key , value ) + "\n" ;
4444 }
4545 }
46- return output + ' }' ;
46+ return output + " }" ;
4747}
4848
4949function lookForEntry ( entry , data ) {
5050 return data . findIndex ( data_entry => {
5151 let allGood = true ;
5252 for ( const key in entry ) {
53- if ( ! entry . hasOwnProperty ( key ) ) {
53+ if ( ! Object . prototype . hasOwnProperty . call ( entry , key ) ) {
5454 continue ;
5555 }
5656 let value = data_entry [ key ] ;
5757 // To make our life easier, if there is a "parent" type, we add it to the path.
58- if ( key === ' path' && data_entry [ ' parent' ] !== undefined ) {
58+ if ( key === " path" && data_entry [ " parent" ] !== undefined ) {
5959 if ( value . length > 0 ) {
60- value += '::' + data_entry [ ' parent' ] [ ' name' ] ;
60+ value += "::" + data_entry [ " parent" ] [ " name" ] ;
6161 } else {
62- value = data_entry [ ' parent' ] [ ' name' ] ;
62+ value = data_entry [ " parent" ] [ " name" ] ;
6363 }
6464 }
6565 if ( value !== entry [ key ] ) {
@@ -95,7 +95,7 @@ function checkNeededFields(fullPath, expected, error_text, queryName, position)
9595 fieldsToCheck = [ ] ;
9696 }
9797 for ( const field of fieldsToCheck ) {
98- if ( ! expected . hasOwnProperty ( field ) ) {
98+ if ( ! Object . prototype . hasOwnProperty . call ( expected , field ) ) {
9999 let text = `${ queryName } ==> Mandatory key \`${ field } \` is not present` ;
100100 if ( fullPath . length > 0 ) {
101101 text += ` in field \`${ fullPath } \`` ;
@@ -117,22 +117,22 @@ function valueCheck(fullPath, expected, result, error_text, queryName) {
117117 error_text . push ( `${ queryName } ==> EXPECTED has extra value in array from field ` +
118118 `\`${ fullPath } \` (position ${ i } ): \`${ JSON . stringify ( expected [ i ] ) } \`` ) ;
119119 } else {
120- valueCheck ( fullPath + '[' + i + ']' , expected [ i ] , result [ i ] , error_text , queryName ) ;
120+ valueCheck ( fullPath + "[" + i + "]" , expected [ i ] , result [ i ] , error_text , queryName ) ;
121121 }
122122 }
123123 for ( ; i < result . length ; ++ i ) {
124124 error_text . push ( `${ queryName } ==> RESULT has extra value in array from field ` +
125125 `\`${ fullPath } \` (position ${ i } ): \`${ JSON . stringify ( result [ i ] ) } \` ` +
126- ' compared to EXPECTED' ) ;
126+ " compared to EXPECTED" ) ;
127127 }
128128 } else if ( expected !== null && typeof expected !== "undefined" &&
129- expected . constructor == Object ) {
129+ expected . constructor == Object ) { // eslint-disable-line eqeqeq
130130 for ( const key in expected ) {
131- if ( ! expected . hasOwnProperty ( key ) ) {
131+ if ( ! Object . prototype . hasOwnProperty . call ( expected , key ) ) {
132132 continue ;
133133 }
134- if ( ! result . hasOwnProperty ( key ) ) {
135- error_text . push ( ' ==> Unknown key "' + key + '"' ) ;
134+ if ( ! Object . prototype . hasOwnProperty . call ( result , key ) ) {
135+ error_text . push ( " ==> Unknown key \"" + key + "\"" ) ;
136136 break ;
137137 }
138138 let result_v = result [ key ] ;
@@ -147,13 +147,13 @@ function valueCheck(fullPath, expected, result, error_text, queryName) {
147147 } ) ;
148148 result_v = result_v . join ( "" ) ;
149149 }
150- const obj_path = fullPath + ( fullPath . length > 0 ? '.' : '' ) + key ;
150+ const obj_path = fullPath + ( fullPath . length > 0 ? "." : "" ) + key ;
151151 valueCheck ( obj_path , expected [ key ] , result_v , error_text , queryName ) ;
152152 }
153153 } else {
154154 const expectedValue = JSON . stringify ( expected ) ;
155155 const resultValue = JSON . stringify ( result ) ;
156- if ( expectedValue != resultValue ) {
156+ if ( expectedValue !== resultValue ) {
157157 error_text . push ( `${ queryName } ==> Different values for field \`${ fullPath } \`:\n` +
158158 `EXPECTED: \`${ expectedValue } \`\nRESULT: \`${ resultValue } \`` ) ;
159159 }
@@ -164,7 +164,7 @@ function runParser(query, expected, parseQuery, queryName) {
164164 const error_text = [ ] ;
165165 checkNeededFields ( "" , expected , error_text , queryName , null ) ;
166166 if ( error_text . length === 0 ) {
167- valueCheck ( '' , expected , parseQuery ( query ) , error_text , queryName ) ;
167+ valueCheck ( "" , expected , parseQuery ( query ) , error_text , queryName ) ;
168168 }
169169 return error_text ;
170170}
@@ -177,16 +177,16 @@ function runSearch(query, expected, doSearch, loadedFile, queryName) {
177177 const error_text = [ ] ;
178178
179179 for ( const key in expected ) {
180- if ( ! expected . hasOwnProperty ( key ) ) {
180+ if ( ! Object . prototype . hasOwnProperty . call ( expected , key ) ) {
181181 continue ;
182182 }
183- if ( ! results . hasOwnProperty ( key ) ) {
184- error_text . push ( ' ==> Unknown key "' + key + '"' ) ;
183+ if ( ! Object . prototype . hasOwnProperty . call ( results , key ) ) {
184+ error_text . push ( " ==> Unknown key \"" + key + "\"" ) ;
185185 break ;
186186 }
187187 const entry = expected [ key ] ;
188188
189- if ( exact_check == true && entry . length !== results [ key ] . length ) {
189+ if ( exact_check && entry . length !== results [ key ] . length ) {
190190 error_text . push ( queryName + "==> Expected exactly " + entry . length +
191191 " results but found " + results [ key ] . length + " in '" + key + "'" ) ;
192192 }
@@ -268,7 +268,7 @@ function runCheck(loadedFile, key, callback) {
268268function runChecks ( testFile , doSearch , parseQuery ) {
269269 let checkExpected = false ;
270270 let checkParsed = false ;
271- let testFileContent = readFile ( testFile ) + ' exports.QUERY = QUERY;' ;
271+ let testFileContent = readFile ( testFile ) + " exports.QUERY = QUERY;" ;
272272
273273 if ( testFileContent . indexOf ( "FILTER_CRATE" ) !== - 1 ) {
274274 testFileContent += "exports.FILTER_CRATE = FILTER_CRATE;" ;
@@ -277,11 +277,11 @@ function runChecks(testFile, doSearch, parseQuery) {
277277 }
278278
279279 if ( testFileContent . indexOf ( "\nconst EXPECTED" ) !== - 1 ) {
280- testFileContent += ' exports.EXPECTED = EXPECTED;' ;
280+ testFileContent += " exports.EXPECTED = EXPECTED;" ;
281281 checkExpected = true ;
282282 }
283283 if ( testFileContent . indexOf ( "\nconst PARSED" ) !== - 1 ) {
284- testFileContent += ' exports.PARSED = PARSED;' ;
284+ testFileContent += " exports.PARSED = PARSED;" ;
285285 checkParsed = true ;
286286 }
287287 if ( ! checkParsed && ! checkExpected ) {
@@ -325,7 +325,7 @@ function loadSearchJS(doc_folder, resource_suffix) {
325325 const searchWords = searchModule . initSearch ( searchIndex . searchIndex ) ;
326326
327327 return {
328- doSearch : function ( queryStr , filterCrate , currentCrate ) {
328+ doSearch : function ( queryStr , filterCrate , currentCrate ) {
329329 return searchModule . execQuery ( searchModule . parseQuery ( queryStr ) , searchWords ,
330330 filterCrate , currentCrate ) ;
331331 } ,
@@ -361,7 +361,7 @@ function parseOptions(args) {
361361 } ;
362362
363363 for ( let i = 0 ; i < args . length ; ++ i ) {
364- if ( correspondences . hasOwnProperty ( args [ i ] ) ) {
364+ if ( Object . prototype . hasOwnProperty . call ( correspondences , args [ i ] ) ) {
365365 i += 1 ;
366366 if ( i >= args . length ) {
367367 console . log ( "Missing argument after `" + args [ i - 1 ] + "` option." ) ;
@@ -405,17 +405,17 @@ function main(argv) {
405405 ) ;
406406 let errors = 0 ;
407407
408- const doSearch = function ( queryStr , filterCrate ) {
408+ const doSearch = function ( queryStr , filterCrate ) {
409409 return parseAndSearch . doSearch ( queryStr , filterCrate , opts [ "crate_name" ] ) ;
410410 } ;
411411
412412 if ( opts [ "test_file" ] . length !== 0 ) {
413- opts [ "test_file" ] . forEach ( function ( file ) {
413+ opts [ "test_file" ] . forEach ( file => {
414414 process . stdout . write ( `Testing ${ file } ... ` ) ;
415415 errors += runChecks ( file , doSearch , parseAndSearch . parseQuery ) ;
416416 } ) ;
417417 } else if ( opts [ "test_folder" ] . length !== 0 ) {
418- fs . readdirSync ( opts [ "test_folder" ] ) . forEach ( function ( file ) {
418+ fs . readdirSync ( opts [ "test_folder" ] ) . forEach ( file => {
419419 if ( ! file . endsWith ( ".js" ) ) {
420420 return ;
421421 }
0 commit comments