Skip to content

Commit

Permalink
fix(core): do not use --verify-no-changes false for linting (#802)
Browse files Browse the repository at this point in the history
* fix(core): do not use --verify-no-changes false for linting

* fix(core): apply fix to check command as well
  • Loading branch information
kellyrbourg committed Nov 29, 2023
1 parent 7eda7fe commit 9026fcf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
16 changes: 16 additions & 0 deletions packages/core/src/executors/format/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,20 @@ describe('Format Executor', () => {
const verifyNoChangesFlag = formatOptions?.verifyNoChanges;
expect(verifyNoChangesFlag).toBeTruthy();
});

it('does not pass the --verify-no-changes when fix option is used', async () => {
(dotnetClient as jest.Mocked<DotNetClient>).getSdkVersion.mockReturnValue(
'6.0.101',
);

const fixOptions = { ...options, fix: true };
const res = await executor(fixOptions, context, dotnetClient);
expect(res.success).toBeTruthy();

const formatOptions = (dotnetClient as jest.Mocked<DotNetClient>).format
.mock.calls[0][1];
const verifyNoChangesFlag = formatOptions?.verifyNoChanges;

expect(verifyNoChangesFlag).toBeUndefined();
});
});
15 changes: 12 additions & 3 deletions packages/core/src/executors/format/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ function normalizeOptions(
isNet6OrHigher: boolean,
): Record<string, string | boolean | undefined> {
const { diagnostics, include, exclude, check, fix, ...flags } = options;
return {

const result = {
...flags,
diagnostics: Array.isArray(diagnostics)
? diagnostics.join(' ')
: diagnostics,
include: Array.isArray(include) ? include.join(' ') : include,
exclude: Array.isArray(exclude) ? exclude.join(' ') : exclude,
check: fix ? false : check && !isNet6OrHigher, // The --check flag is for .NET 5 and older
verifyNoChanges: fix ? false : check && isNet6OrHigher, // The --verify-no-changes flag is for .NET 6 and newer
};

// Specifying --verify-no-changes false does not work, so we only add the switch when we want to run the check only
if (!fix && check) {
if (isNet6OrHigher) {
return { ...result, verifyNoChanges: true };
}
return { ...result, check: true }; // The --check flag is for .NET 5 and older
}

return result;
}

export default async function runExecutor(
Expand Down

0 comments on commit 9026fcf

Please sign in to comment.