|
| 1 | +/** |
| 2 | + * Prints a greeting to the console. |
| 3 | + *@param {string} name |
| 4 | + *@param {string} surname |
| 5 | + */ |
| 6 | +exportfunctiongreet(name,surname){ |
| 7 | +console.log(`Hello,${name}${surname}!`) |
| 8 | +} |
| 9 | + |
| 10 | +/** |
| 11 | + * Prints a welcome message to the console. |
| 12 | + *@param {string} name |
| 13 | + *@param {string} surname |
| 14 | + */ |
| 15 | +exportfunctionwelcome(name,surname){ |
| 16 | +console.log(`Welcome,${name}${surname}!`) |
| 17 | +} |
| 18 | + |
| 19 | +importReactfrom'react' |
| 20 | +importPropTypesfrom'prop-types' |
| 21 | + |
| 22 | +functionHelloWorld({ |
| 23 | +greeting="hello", |
| 24 | +greeted='"World"', |
| 25 | +silent=false, |
| 26 | +onMouseOver, |
| 27 | +}){ |
| 28 | +if(!greeting){ |
| 29 | +console.log("No greeting") |
| 30 | +returnnull |
| 31 | +} |
| 32 | + |
| 33 | +// TODO: Don't use random in render |
| 34 | +constnum=Math.floor(Math.random()*1e7) |
| 35 | +.toString() |
| 36 | +.replace(/.d+/gi,"") |
| 37 | + |
| 38 | +return( |
| 39 | +<div |
| 40 | +className="HelloWorld" |
| 41 | +title={`You are visitor number${num}`} |
| 42 | +onMouseOver={onMouseOver} |
| 43 | +> |
| 44 | +<strong> |
| 45 | +{greeting.slice(0,1).toUpperCase()+greeting.slice(1).toLowerCase()} |
| 46 | +</strong> |
| 47 | +{greeting.endsWith(",") ?( |
| 48 | +" " |
| 49 | +) :( |
| 50 | +<spanstyle={{color:"grey"}}>", "</span> |
| 51 | +)} |
| 52 | +<em>{greeted}</em> |
| 53 | +{silent ?"." :"!"} |
| 54 | +</div> |
| 55 | +) |
| 56 | +} |
| 57 | + |
| 58 | +HelloWorld.propTypes={ |
| 59 | +greeting:PropTypes.string, |
| 60 | +greeted:PropTypes.string, |
| 61 | +silent:PropTypes.bool, |
| 62 | +onMouseOver:PropTypes.func, |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * Fails ast-grep because of console.log used in the function |
| 67 | + *@param {string} text |
| 68 | + *@param {string} string |
| 69 | + *@returns {boolean} |
| 70 | + */ |
| 71 | +exportfunctionfindInString(text,string,logFn=console.error){ |
| 72 | +logFn("text",text) |
| 73 | +returntext.includes(string) |
| 74 | +} |
| 75 | +returntext.includes(string) |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * Fails ast-grep because of console.log used in the catch block |
| 80 | + *@param {string} text |
| 81 | + *@param {string} string |
| 82 | + *@returns {boolean} |
| 83 | + */ |
| 84 | +exportasyncfunctionfindInStringAsync(text,string){ |
| 85 | +try{ |
| 86 | +returntext.includes(string) |
| 87 | +}catch(error){ |
| 88 | +console.log("error",error) |
| 89 | +} |
| 90 | +} |
| 91 | + |
| 92 | +/** |
| 93 | + * Doesn't fail ast-grep since console.error is allowed in catch block |
| 94 | + *@param {string} text |
| 95 | + *@param {string} string |
| 96 | + *@returns {boolean} |
| 97 | + */ |
| 98 | +exportasyncfunctionfindInStringTreated(text,string){ |
| 99 | +try{ |
| 100 | +returntext.includes(string) |
| 101 | +}catch(error){ |
| 102 | +console.error("error",error) |
| 103 | +} |
| 104 | +} |