Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Initialize CodeQL
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
uses: github/codeql-action/init@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7
with:
languages: javascript-typescript
build-mode: none

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
uses: github/codeql-action/analyze@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7
with:
category: '/language:javascript-typescript'
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ jobs:
retention-days: 5

- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
uses: github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7
with:
sarif_file: results.sarif
24 changes: 17 additions & 7 deletions packages/cli/src/services/processComparisonFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,33 @@ import type {
* Result of processing comparison file
*/
export interface ProcessComparisonResult {
/** The scan result after processing the comparison file */
scanResult: ScanResult;
/** The environment variables from the comparison file */
envVariables: Record<string, string | undefined>;
/** The file the comparison was made against */
comparedAgainst: string;
duplicatesFound: boolean;
/** The duplicate environment variables found in the comparison file */
dupsEnv: Duplicate[];
/** The duplicate example variables found in the comparison file */
dupsEx: Duplicate[];
/** The context of any fixes applied to the comparison file */
fix: FixContext;
/** The full contents of the example file, if it was found and read */
exampleFull?: Record<string, string> | undefined;
/** Basename of the example file `exampleFull` was read from. */
exampleFile?: string | undefined;
/** Uppercase keys found in the comparison file */
uppercaseWarnings?: UppercaseWarning[];
/** Expiration warnings found in the comparison file */
expireWarnings?: ExpireWarning[];
/** Inconsistent naming warnings found in the comparison file */
inconsistentNamingWarnings?: InconsistentNamingWarning[];
/** Comment warnings found in the comparison file */
commentWarnings?: CommentWarning[];
/** Drift warnings found in the comparison file */
driftWarnings?: DriftWarning[];
/** Any error encountered while processing the comparison file */
error?: { message: string; shouldExit: boolean };
}

Expand All @@ -65,7 +77,6 @@ export function processComparisonFile(
): ProcessComparisonResult {
let envVariables: Record<string, string | undefined> = {};
let comparedAgainst = '';
let duplicatesFound = false;
let dupsEnv: Duplicate[] = [];
let dupsEx: Duplicate[] = [];
let exampleFull: Record<string, string> | undefined = undefined;
Expand Down Expand Up @@ -155,7 +166,6 @@ export function processComparisonFile(
const duplicateResults = checkDuplicates(compareFile, opts);
dupsEnv = duplicateResults.dupsEnv;
dupsEx = duplicateResults.dupsEx;
duplicatesFound = dupsEnv.length > 0 || dupsEx.length > 0;
}

if (opts.expireWarnings) {
Expand Down Expand Up @@ -217,12 +227,14 @@ export function processComparisonFile(
scanResult.missing = [];
dupsEnv = [];
dupsEx = [];
duplicatesFound = false;
}
}

// Keep duplicates for output if not fixed
if (duplicatesFound && (!opts.fix || !fix.fixApplied)) {
if (
(dupsEnv.length > 0 || dupsEx.length > 0) &&
(!opts.fix || !fix.fixApplied)
) {
if (!scanResult.duplicates) scanResult.duplicates = {};
if (dupsEnv.length > 0) scanResult.duplicates.env = dupsEnv;
if (dupsEx.length > 0) scanResult.duplicates.example = dupsEx;
Expand All @@ -233,7 +245,6 @@ export function processComparisonFile(
scanResult,
envVariables,
comparedAgainst,
duplicatesFound,
dupsEnv,
dupsEx,
fix,
Expand All @@ -255,7 +266,6 @@ export function processComparisonFile(
scanResult,
envVariables,
comparedAgainst,
duplicatesFound,
dupsEnv,
dupsEx,
fix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ describe('processComparisonFile', () => {

expect(result.dupsEnv).toHaveLength(0);
expect(result.dupsEx).toHaveLength(0);
expect(result.duplicatesFound).toBe(false);
});

it('sets duplicatesFound via dupsEx when only example file has duplicates (lines 109, 154)', () => {
Expand All @@ -401,7 +400,6 @@ describe('processComparisonFile', () => {
{ ...baseOpts, allowDuplicates: false },
);

expect(result.duplicatesFound).toBe(true);
expect(result.dupsEnv).toHaveLength(0);
expect(result.dupsEx).toHaveLength(1);
// dupsEnv is empty → scanResult.duplicates.env NOT set (line 154 false branch)
Expand Down