Skip to content

Commit 7fd6176

Browse files
authored
chore: migrate from istanbul to c8 ignore comments (#322)
Replace all instances of istanbul ignore comments with c8 ignore syntax across multiple files in the codebase. This change maintains the same code coverage exclusions while updating to the newer c8 coverage tool format. The changes include: - Converting single-line ignores to c8 ignore start/stop blocks - Updating existing ignore comments to maintain their original purpose - Preserving the explanatory comments for why certain sections are ignored --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 38d6443 commit 7fd6176

File tree

10 files changed

+28
-13
lines changed

10 files changed

+28
-13
lines changed

packages/@aws-cdk/tmp-toolkit-helpers/src/util/directories.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ export function cdkHomeDir() {
2020
try {
2121
let userInfoHome: string | undefined = os.userInfo().homedir;
2222
// Node returns this if the user doesn't have a home directory
23-
/* istanbul ignore if: will not happen in normal setups */
23+
/* c8 ignore start */ // will not happen in normal setups
2424
if (userInfoHome == '/var/empty') {
2525
userInfoHome = undefined;
2626
}
27+
/* c8 ignore stop */
2728
home = path.join((userInfoHome ?? os.homedir()).trim(), '.cdk');
2829
} catch {
2930
}

packages/@aws-cdk/tmp-toolkit-helpers/src/util/type-brands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ export type Branded<T, B> = T & Brand<B>;
3737
* values which are branded by construction (really just an elaborate
3838
* way to write 'as').
3939
*/
40-
/* c8 ignore next 3 */
40+
/* c8 ignore start */
4141
export function createBranded<A extends Branded<any, any>>(value: TypeUnderlyingBrand<A>): A {
4242
return value as A;
4343
}
44+
/* c8 ignore stop */
4445

4546
type TypeUnderlyingBrand<A> = A extends Branded<infer T, any> ? T : never;

packages/aws-cdk/lib/api/logs/logs-monitor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ export class CloudWatchLogEventMonitor {
146146
private async tick(): Promise<void> {
147147
// excluding from codecoverage because this
148148
// doesn't always run (depends on timing)
149-
/* c8 ignore next */
149+
/* c8 ignore start */
150150
if (!this.monitorId) {
151151
return;
152152
}
153+
/* c8 ignore stop */
153154

154155
try {
155156
const events = flatten(await this.readNewEvents());

packages/aws-cdk/lib/api/util/rwlock.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ToolkitError } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api';
1212
* This class is not 100% race safe, but in practice it should be a lot
1313
* better than the 0 protection we have today.
1414
*/
15-
/* istanbul ignore next: code paths are unpredictable */
15+
/* c8 ignore start */ // code paths are unpredictable
1616
export class RWLock {
1717
private readonly pidString: string;
1818
private readonly writerFile: string;
@@ -146,6 +146,7 @@ export class RWLock {
146146
return ret;
147147
}
148148
}
149+
/* c8 ignore stop */
149150

150151
/**
151152
* An acquired lock
@@ -164,7 +165,7 @@ export interface IWriterLock extends ILock {
164165
convertToReaderLock(): Promise<ILock>;
165166
}
166167

167-
/* istanbul ignore next: code paths are unpredictable */
168+
/* c8 ignore start */ // code paths are unpredictable
168169
async function readFileIfExists(filename: string): Promise<string | undefined> {
169170
try {
170171
return await fs.readFile(filename, { encoding: 'utf-8' });
@@ -175,17 +176,19 @@ async function readFileIfExists(filename: string): Promise<string | undefined> {
175176
throw e;
176177
}
177178
}
179+
/* c8 ignore stop */
178180

179181
let tmpCounter = 0;
180-
/* istanbul ignore next: code paths are unpredictable */
182+
/* c8 ignore start */ // code paths are unpredictable
181183
async function writeFileAtomic(filename: string, contents: string): Promise<void> {
182184
await fs.mkdir(path.dirname(filename), { recursive: true });
183185
const tmpFile = `${filename}.${process.pid}_${++tmpCounter}`;
184186
await fs.writeFile(tmpFile, contents, { encoding: 'utf-8' });
185187
await fs.rename(tmpFile, filename);
186188
}
189+
/* c8 ignore stop */
187190

188-
/* istanbul ignore next: code paths are unpredictable */
191+
/* c8 ignore start */ // code paths are unpredictable
189192
async function deleteFile(filename: string) {
190193
try {
191194
await fs.unlink(filename);
@@ -196,8 +199,9 @@ async function deleteFile(filename: string) {
196199
throw e;
197200
}
198201
}
202+
/* c8 ignore stop */
199203

200-
/* istanbul ignore next: code paths are unpredictable */
204+
/* c8 ignore start */ // code paths are unpredictable
201205
function processExists(pid: number) {
202206
try {
203207
process.kill(pid, 0);
@@ -206,3 +210,4 @@ function processExists(pid: number) {
206210
return false;
207211
}
208212
}
213+
/* c8 ignore stop */

packages/aws-cdk/lib/cli/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ function determineHotswapMode(hotswap?: boolean, hotswapFallback?: boolean, watc
595595
return hotswapMode;
596596
}
597597

598-
/* istanbul ignore next: we never call this in unit tests */
598+
/* c8 ignore start */ // we never call this in unit tests
599599
export function cli(args: string[] = process.argv.slice(2)) {
600600
exec(args)
601601
.then(async (value) => {
@@ -610,3 +610,4 @@ export function cli(args: string[] = process.argv.slice(2)) {
610610
process.exitCode = 1;
611611
});
612612
}
613+
/* c8 ignore stop */

packages/aws-cdk/lib/cli/pretty-print-error.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-console */
22
import * as chalk from 'chalk';
33

4+
/* c8 ignore start */
45
export function prettyPrintError(error: unknown, debug = false) {
56
const err = ensureError(error);
67
console.error(chalk.red(err.message));
@@ -34,3 +35,4 @@ function ensureError(value: unknown): Error {
3435
const error = new Error(`An unexpected error was thrown: ${stringified}`);
3536
return error;
3637
}
38+
/* c8 ignore stop */

packages/aws-cdk/lib/cli/util/npm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { debug } from '../../logging';
66

77
const exec = promisify(_exec);
88

9-
/* istanbul ignore next: not called during unit tests */
9+
/* c8 ignore start */ // not called during unit tests
1010
export async function getLatestVersionFromNpm(): Promise<string> {
1111
const { stdout, stderr } = await exec('npm view aws-cdk version', { timeout: 3000 });
1212
if (stderr && stderr.trim().length > 0) {
@@ -19,3 +19,4 @@ export async function getLatestVersionFromNpm(): Promise<string> {
1919

2020
return latestVersion;
2121
}
22+
/* c8 ignore stop */

packages/aws-cdk/lib/cli/version.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* istanbul ignore file */
1+
/* c8 ignore start */
22
import * as path from 'path';
33
import * as chalk from 'chalk';
44
import * as fs from 'fs-extra';
@@ -130,3 +130,4 @@ export async function displayVersionMessage(currentVersion = versionNumber(), ve
130130
debug(`Could not run version check - ${err.message}`);
131131
}
132132
}
133+
/* c8 ignore stop */

packages/aws-cdk/lib/commands/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ export async function contextHandler(options: ContextOptions): Promise<number> {
5656
} else {
5757
// List -- support '--json' flag
5858
if (options.json) {
59-
/* istanbul ignore next */
59+
/* c8 ignore start */
6060
const contextValues = options.context.all;
6161
result(JSON.stringify(contextValues, undefined, 2));
62+
/* c8 ignore stop */
6263
} else {
6364
listContext(options.context);
6465
}

packages/aws-cdk/lib/commands/init/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,11 @@ async function loadInitVersions(): Promise<Versions> {
509509
'aws-cdk': versionNumber(),
510510
};
511511
for (const [key, value] of Object.entries(ret)) {
512-
/* istanbul ignore next */
512+
/* c8 ignore start */
513513
if (!value) {
514514
throw new ToolkitError(`Missing init version from ${initVersionFile}: ${key}`);
515515
}
516+
/* c8 ignore stop */
516517
}
517518

518519
return ret;

0 commit comments

Comments
 (0)