* Strip Comments * @param {string} contents * @return {string}
(contents)
| 1071 | * @return {string} |
| 1072 | */ |
| 1073 | function stripComments(contents) { |
| 1074 | // Multi-line comments |
| 1075 | contents = contents.replace(/\/\*(?!.*\*\/)(.|\n)*?\*\//g, function (match) { |
| 1076 | // Preserve the newlines |
| 1077 | const newlines = []; |
| 1078 | for (let i = 0; i < match.length; i++) { |
| 1079 | if (match[i] === '\n') { |
| 1080 | newlines.push('\n'); |
| 1081 | } |
| 1082 | } |
| 1083 | return newlines.join(''); |
| 1084 | }); |
| 1085 | // Single line comments either on its own line or following a space, |
| 1086 | // semi-colon, or closing brace |
| 1087 | return contents.replace(/( |}|;|^) *\/\/.*/gm, '$1'); |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Collects any forbidden terms (regex patterns) in the contents of a file, |
no test coverage detected