Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Jul 16, 2023
1 parent bef6143 commit 31355f6
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/bin/jsii-pacmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ import { VERSION_DESC } from '../lib/version';
})
.version(VERSION_DESC).argv;

configureLogging({ level: argv.verbose !== undefined ? argv.verbose : 0 });
configureLogging({ level: argv.verbose ?? 0 });

// Default to 4 threads in case of concurrency, good enough for most situations
debug('command line arguments:', argv);
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/packaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class JsiiModule {
// problems if there are spaces or other special characters in the path.
args.push(JSON.stringify(this.moduleDirectory));

if (logging.level >= logging.LEVEL_VERBOSE) {
if (logging.level.valueOf() >= logging.LEVEL_VERBOSE) {
args.push('--loglevel=verbose');
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ export class DotNetGenerator extends Generator {
// Emit getters
if (backingFieldName != null) {
this.code.line(`get => ${backingFieldName};`);
} else if (datatype || prop.const || prop.abstract) {
} else if (datatype ?? prop.const ?? prop.abstract) {
this.code.line('get;');
} else {
// If the property is non-optional, add a bang to silence compiler warning
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/targets/go/types/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class GoClass extends GoType<ClassType> {
? (this.pkg.root.findType(this.type.base.fqn) as GoClass)
: null;
}
return this._extends == null ? undefined : this._extends;
return this._extends ?? undefined;
}

public get implements(): readonly GoInterface[] {
Expand Down
5 changes: 4 additions & 1 deletion packages/jsii-pacmak/lib/targets/go/types/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class GoEnumMember {
private readonly docs: Docs;
private readonly apiLocation: ApiLocation;

public constructor(private readonly parent: Enum, entry: EnumMember) {
public constructor(
private readonly parent: Enum,
entry: EnumMember,
) {
this.name = `${parent.name}_${entry.name}`;
this.rawValue = entry.name;
this.docs = entry.docs;
Expand Down
5 changes: 4 additions & 1 deletion packages/jsii-pacmak/lib/targets/go/types/go-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export abstract class GoType<T extends Type = Type> {
public readonly proxyName: string;
protected readonly apiLocation: ApiLocation;

public constructor(public readonly pkg: Package, public readonly type: T) {
public constructor(
public readonly pkg: Package,
public readonly type: T,
) {
this.name = type.name;

// Prefix with the nesting parent name(s), using an _ delimiter.
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/targets/go/types/type-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export abstract class GoMethod implements GoTypeMember {

public get returnsRef(): boolean {
if (
this.reference?.type?.type.isClassType() ||
this.reference?.type?.type.isClassType() ??
this.reference?.type?.type.isInterfaceType()
) {
return true;
Expand Down
17 changes: 10 additions & 7 deletions packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,13 +985,16 @@ class JavaGenerator extends Generator {
const inheritedOptionalProps = ifc.interfaces
.map(allOptionalProps.bind(this))
// Calculate how many direct parents brought a given optional property
.reduce((histogram, entry) => {
for (const [name, spec] of Object.entries(entry)) {
histogram[name] = histogram[name] ?? { spec, count: 0 };
histogram[name].count += 1;
}
return histogram;
}, {} as Record<string, { readonly spec: spec.Property; count: number }>);
.reduce(
(histogram, entry) => {
for (const [name, spec] of Object.entries(entry)) {
histogram[name] = histogram[name] ?? { spec, count: 0 };
histogram[name].count += 1;
}
return histogram;
},
{} as Record<string, { readonly spec: spec.Property; count: number }>,
);

const localProps = new Set(ifc.properties?.map((prop) => prop.name) ?? []);
for (const { spec, count } of Object.values(inheritedOptionalProps)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ abstract class BaseMethod implements PythonBase {
name: p.name,
docs: p.docs,
definingType: this.parent,
} as DocumentableArgument),
}) as DocumentableArgument,
)
// If there's liftedProps, the last argument is the struct and it won't be _actually_ emitted.
.filter((_, index) =>
Expand Down Expand Up @@ -665,7 +665,7 @@ abstract class BaseMethod implements PythonBase {
name: p.prop.name,
docs: p.prop.docs,
definingType: p.definingType,
} as DocumentableArgument),
}) as DocumentableArgument,
),
);
} else if (
Expand Down
1 change: 1 addition & 0 deletions packages/jsii-pacmak/lib/targets/python/type-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class Optional implements TypeName {
...context,
ignoreOptional: true,
});
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (context.ignoreOptional || this.#wrapped === Primitive.ANY) {
return optionalType;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-pacmak/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ export async function shell(
const stdout = new Array<Buffer>();
const stderr = new Array<Buffer>();
child.stdout.on('data', (chunk) => {
if (logging.level >= logging.LEVEL_SILLY) {
if (logging.level.valueOf() >= logging.LEVEL_SILLY) {
process.stderr.write(chunk); // notice - we emit all build output to stderr
}
stdout.push(Buffer.from(chunk));
});
child.stderr.on('data', (chunk) => {
if (logging.level >= logging.LEVEL_SILLY) {
if (logging.level.valueOf() >= logging.LEVEL_SILLY) {
process.stderr.write(chunk);
}
stderr.push(Buffer.from(chunk));
Expand Down
36 changes: 21 additions & 15 deletions packages/jsii-pacmak/test/generated-code/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,15 @@ export function checkTree(
entry,
subtree: checkTree(path.join(file, entry), { root, excludes }),
}))
.reduce((tree, { entry, subtree }) => {
if (subtree != null) {
tree[entry] = subtree;
}
return tree;
}, {} as { [name: string]: TreeStructure });
.reduce(
(tree, { entry, subtree }) => {
if (subtree != null) {
tree[entry] = subtree;
}
return tree;
},
{} as { [name: string]: TreeStructure },
);
}

export function diffTrees(
Expand Down Expand Up @@ -237,16 +240,19 @@ export function diffTrees(
{ root },
),
}))
.reduce((tree, { entry, subtree }) => {
if (subtree != null) {
tree = tree ?? {};
if (typeof subtree === 'string' && subtree.startsWith(entry)) {
entry = subtree;
.reduce(
(tree, { entry, subtree }) => {
if (subtree != null) {
tree = tree ?? {};
if (typeof subtree === 'string' && subtree.startsWith(entry)) {
entry = subtree;
}
tree[entry] = subtree;
}
tree[entry] = subtree;
}
return tree;
}, undefined as { [name: string]: TreeStructure } | undefined);
return tree;
},
undefined as { [name: string]: TreeStructure } | undefined,
);
}

function tryStat(at: string) {
Expand Down

0 comments on commit 31355f6

Please sign in to comment.