Skip to content

Commit 9026fcf

Browse files
authored
fix(core): do not use --verify-no-changes false for linting (#802)
* fix(core): do not use --verify-no-changes false for linting * fix(core): apply fix to check command as well
1 parent 7eda7fe commit 9026fcf

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/core/src/executors/format/executor.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,20 @@ describe('Format Executor', () => {
123123
const verifyNoChangesFlag = formatOptions?.verifyNoChanges;
124124
expect(verifyNoChangesFlag).toBeTruthy();
125125
});
126+
127+
it('does not pass the --verify-no-changes when fix option is used', async () => {
128+
(dotnetClient as jest.Mocked<DotNetClient>).getSdkVersion.mockReturnValue(
129+
'6.0.101',
130+
);
131+
132+
const fixOptions = { ...options, fix: true };
133+
const res = await executor(fixOptions, context, dotnetClient);
134+
expect(res.success).toBeTruthy();
135+
136+
const formatOptions = (dotnetClient as jest.Mocked<DotNetClient>).format
137+
.mock.calls[0][1];
138+
const verifyNoChangesFlag = formatOptions?.verifyNoChanges;
139+
140+
expect(verifyNoChangesFlag).toBeUndefined();
141+
});
126142
});

packages/core/src/executors/format/executor.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@ function normalizeOptions(
1616
isNet6OrHigher: boolean,
1717
): Record<string, string | boolean | undefined> {
1818
const { diagnostics, include, exclude, check, fix, ...flags } = options;
19-
return {
19+
20+
const result = {
2021
...flags,
2122
diagnostics: Array.isArray(diagnostics)
2223
? diagnostics.join(' ')
2324
: diagnostics,
2425
include: Array.isArray(include) ? include.join(' ') : include,
2526
exclude: Array.isArray(exclude) ? exclude.join(' ') : exclude,
26-
check: fix ? false : check && !isNet6OrHigher, // The --check flag is for .NET 5 and older
27-
verifyNoChanges: fix ? false : check && isNet6OrHigher, // The --verify-no-changes flag is for .NET 6 and newer
2827
};
28+
29+
// Specifying --verify-no-changes false does not work, so we only add the switch when we want to run the check only
30+
if (!fix && check) {
31+
if (isNet6OrHigher) {
32+
return { ...result, verifyNoChanges: true };
33+
}
34+
return { ...result, check: true }; // The --check flag is for .NET 5 and older
35+
}
36+
37+
return result;
2938
}
3039

3140
export default async function runExecutor(

0 commit comments

Comments
 (0)