@@ -12,7 +12,7 @@ import { scanJsonOutput } from '../ui/scan/scanJsonOutput.js';
1212import { printMissingExample } from '../ui/scan/printMissingExample.js' ;
1313import { processComparisonFile } from '../services/processComparisonFile.js' ;
1414import { printComparisonError } from '../ui/scan/printComparisonError.js' ;
15- import { hasIgnoreComment } from '../core/security/secretDetectors .js' ;
15+ import { skipCommentedUsages } from '../core/helpers/skipCommentedUsages .js' ;
1616import { frameworkValidator } from '../core/frameworks/frameworkValidator.js' ;
1717import { detectSecretsInExample } from '../core/security/exampleSecretDetector.js' ;
1818import {
@@ -192,51 +192,6 @@ export async function scanUsage(opts: ScanUsageOptions): Promise<ExitResult> {
192192 return { exitWithError : result . exitWithError } ;
193193}
194194
195- /**
196- * Filters out commented usages from the list.
197- * Skipping comments:
198- * // process.env.API_URL
199- * # process.env.API_URL
200- * /* process.env.API_URL
201- * * process.env.API_URL
202- * <!-- process.env.API_URL -->
203- * @param usages - List of environment variable usages
204- * @returns Filtered list of environment variable usages
205- */
206- function skipCommentedUsages ( usages : readonly EnvUsage [ ] ) : EnvUsage [ ] {
207- let insideHtmlComment = false ;
208- let insideIgnoreBlock = false ;
209-
210- return usages . filter ( ( u ) => {
211- if ( ! u . context ) return true ;
212- const line = u . context . trim ( ) ;
213-
214- if ( / < ! - - \s * d o t e n v [ \s - ] * d i f f [ \s - ] * i g n o r e [ \s - ] * s t a r t \s * - - > / i. test ( line ) ) {
215- insideIgnoreBlock = true ;
216- return false ;
217- }
218-
219- if ( / < ! - - \s * d o t e n v [ \s - ] * d i f f [ \s - ] * i g n o r e [ \s - ] * e n d \s * - - > / i. test ( line ) ) {
220- insideIgnoreBlock = false ;
221- return false ;
222- }
223-
224- if ( line . includes ( '<!--' ) ) insideHtmlComment = true ;
225- if ( line . includes ( '-->' ) ) {
226- insideHtmlComment = false ;
227- return false ;
228- }
229-
230- if ( insideIgnoreBlock ) return false ;
231-
232- return (
233- ! insideHtmlComment &&
234- ! / ^ \s * ( \/ \/ | # | \/ \* | \* | < ! - - | - - > ) / . test ( line ) &&
235- ! hasIgnoreComment ( line )
236- ) ;
237- } ) ;
238- }
239-
240195/**
241196 * Recalculates statistics for a scan result after filtering usages.
242197 * @param scanResult The current scan result
0 commit comments