Skip to content

style: streamline readability of constructor param types #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2022
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
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

## unreleased

* Misc
* Improved readability of constructor parameter types. (via [#166])

[#166]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/166

## 1.3.1 - 2022-08-04

* Fixed
Expand Down
6 changes: 3 additions & 3 deletions src/builders/fromNodePackageJson.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { PackageJson, splitNameGroup } from '../helpers/packageJson'
export class ToolBuilder {
readonly #extRefFactory: Factories.FromNodePackageJson.ExternalReferenceFactory

constructor (extRefFactory: Factories.FromNodePackageJson.ExternalReferenceFactory) {
constructor (extRefFactory: ToolBuilder['extRefFactory']) {
this.#extRefFactory = extRefFactory
}

Expand Down Expand Up @@ -58,8 +58,8 @@ export class ComponentBuilder {
readonly #licenseFactory: Factories.LicenseFactory

constructor (
extRefFactory: Factories.FromNodePackageJson.ExternalReferenceFactory,
licenseFactory: Factories.LicenseFactory
extRefFactory: ComponentBuilder['extRefFactory'],
licenseFactory: ComponentBuilder['licenseFactory']
) {
this.#extRefFactory = extRefFactory
this.#licenseFactory = licenseFactory
Expand Down
4 changes: 2 additions & 2 deletions src/factories/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class LicenseFactory {
makeFromString (value: string): License {
try {
return this.makeExpression(value)
} catch (Error) {
} catch {
return this.makeDisjunctive(value)
}
}
Expand All @@ -39,7 +39,7 @@ export class LicenseFactory {
makeDisjunctive (value: string): DisjunctiveLicense {
try {
return this.makeDisjunctiveWithId(value)
} catch (error) {
} catch {
return this.makeDisjunctiveWithName(value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/factories/packageUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ExternalReferenceType } from '../enums'
export class PackageUrlFactory {
readonly #type: PackageURL['type']

constructor (type: PackageURL['type']) {
constructor (type: PackageUrlFactory['type']) {
this.#type = type
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Attachment {
content: string
encoding?: AttachmentEncoding

constructor (content: string, op: OptionalProperties = {}) {
constructor (content: Attachment['content'], op: OptionalProperties = {}) {
this.contentType = op.contentType
this.content = content
this.encoding = op.encoding
Expand Down
2 changes: 1 addition & 1 deletion src/models/bom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Bom {
// The dependency graph can be normalized on render-time, no need to store it in the bom model.

/**
* @throws {TypeError} if {@see op.version} is not {@see PositiveInteger} nor {@see undefined}
* @throws {TypeError} if {@see op.version} is neither {@see PositiveInteger} nor {@see undefined}
* @throws {TypeError} if {@see op.serialNumber} is neither {@see UrnUuid} nor {@see undefined}
*/
constructor (op: OptionalProperties = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/models/bomRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
export class BomRef {
value?: string

constructor (value?: string) {
constructor (value?: BomRef['value']) {
this.value = value
}

compare (other: BomRef): number {
return (this.toString()).localeCompare(other.toString())
return this.toString().localeCompare(other.toString())
}

toString (): string {
Expand Down
2 changes: 1 addition & 1 deletion src/models/externalReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ExternalReference implements Comparable {
type: ExternalReferenceType
comment?: string

constructor (url: URL | string, type: ExternalReferenceType, op: OptionalProperties = {}) {
constructor (url: ExternalReference['url'], type: ExternalReference['type'], op: OptionalProperties = {}) {
this.url = url
this.type = type
this.comment = op.comment
Expand Down
6 changes: 3 additions & 3 deletions src/models/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class LicenseExpression {
/**
* @throws {RangeError} if {@see expression} is not eligible({@see LicenseExpression.isEligibleExpression})
*/
constructor (expression: string) {
constructor (expression: LicenseExpression['expression']) {
this.expression = expression
}

Expand Down Expand Up @@ -68,7 +68,7 @@ export class NamedLicense {
text?: Attachment
url?: URL | string

constructor (name: string, op: NamedLicenseOptionalProperties = {}) {
constructor (name: NamedLicense['name'], op: NamedLicenseOptionalProperties = {}) {
this.name = name
this.text = op.text
this.url = op.url
Expand All @@ -94,7 +94,7 @@ export class SpdxLicense {
/**
* @throws {RangeError} if {@see id} is not supported SPDX id({@see isSupportedSpdxId})
*/
constructor (id: SpdxId, op: SpdxLicenseOptionalProperties = {}) {
constructor (id: SpdxLicense['id'], op: SpdxLicenseOptionalProperties = {}) {
this.id = id
this.text = op.text
this.url = op.url
Expand Down
2 changes: 1 addition & 1 deletion src/models/swid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SWID {
/**
* @throws {TypeError} if {@see op.tagVersion} is neither {@see NonNegativeInteger} nor {@see undefined}
*/
constructor (tagId: string, name: string, op: OptionalProperties = {}) {
constructor (tagId: SWID['tagId'], name: SWID['name'], op: OptionalProperties = {}) {
this.tagId = tagId
this.name = name
this.version = op.version
Expand Down
13 changes: 8 additions & 5 deletions src/serialize/json/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { treeIterator } from '../../helpers/tree'
export class Factory {
readonly #spec: Spec

constructor (spec: Spec) {
constructor (spec: Factory['spec']) {
this.#spec = spec
}

Expand Down Expand Up @@ -104,7 +104,7 @@ interface Normalizer {
abstract class Base implements Normalizer {
protected readonly _factory: Factory

constructor (factory: Factory) {
constructor (factory: Base['factory']) {
this._factory = factory
}

Expand Down Expand Up @@ -203,7 +203,8 @@ export class HashNormalizer extends Base {
options.sortLists ?? false
? data.sorted()
: Array.from(data)
).map(h => this.normalize(h, options)
).map(
h => this.normalize(h, options)
).filter(isNotUndefined)
}
}
Expand Down Expand Up @@ -295,7 +296,8 @@ export class ComponentNormalizer extends Base {
options.sortLists ?? false
? data.sorted()
: Array.from(data)
).map(c => this.normalize(c, options)
).map(
c => this.normalize(c, options)
).filter(isNotUndefined)
}
}
Expand Down Expand Up @@ -389,7 +391,8 @@ export class ExternalReferenceNormalizer extends Base {
options.sortLists ?? false
? data.sorted()
: Array.from(data)
).map(r => this.normalize(r, options)
).map(
r => this.normalize(r, options)
).filter(isNotUndefined)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/serialize/jsonSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class JsonSerializer extends BaseSerializer<Normalized.Bom> {
/**
* @throws {UnsupportedFormatError} if {@see normalizerFactory.spec} does not support {@see Format.JSON}.
*/
constructor (normalizerFactory: NormalizerFactory) {
constructor (normalizerFactory: JsonSerializer['normalizerFactory']) {
if (!normalizerFactory.spec.supportsFormat(Format.JSON)) {
throw new UnsupportedFormatError('Spec does not support JSON format.')
}
Expand Down
13 changes: 8 additions & 5 deletions src/serialize/xml/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { treeIterator } from '../../helpers/tree'
export class Factory {
readonly #spec: Spec

constructor (spec: Spec) {
constructor (spec: Factory['spec']) {
this.#spec = spec
}

Expand Down Expand Up @@ -104,7 +104,7 @@ interface Normalizer {
abstract class Base implements Normalizer {
protected readonly _factory: Factory

constructor (factory: Factory) {
constructor (factory: Base['factory']) {
this._factory = factory
}

Expand Down Expand Up @@ -260,7 +260,8 @@ export class HashNormalizer extends Base {
options.sortLists ?? false
? data.sorted()
: Array.from(data)
).map(h => this.normalize(h, options, elementName)
).map(
h => this.normalize(h, options, elementName)
).filter(isNotUndefined)
}
}
Expand Down Expand Up @@ -392,7 +393,8 @@ export class ComponentNormalizer extends Base {
options.sortLists ?? false
? data.sorted()
: Array.from(data)
).map(c => this.normalize(c, options, elementName)
).map(
c => this.normalize(c, options, elementName)
).filter(isNotUndefined)
}
}
Expand Down Expand Up @@ -510,7 +512,8 @@ export class ExternalReferenceNormalizer extends Base {
options.sortLists ?? false
? data.sorted()
: Array.from(data)
).map(r => this.normalize(r, options, elementName)
).map(
r => this.normalize(r, options, elementName)
).filter(isNotUndefined)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/serialize/xmlBaseSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export abstract class XmlBaseSerializer extends BaseSerializer<SimpleXml.Element
/**
* @throws {UnsupportedFormatError} if {@see normalizerFactory.spec} does not support {@see Format.XML}.
*/
constructor (normalizerFactory: NormalizerFactory) {
constructor (normalizerFactory: XmlBaseSerializer['normalizerFactory']) {
if (!normalizerFactory.spec.supportsFormat(Format.JSON)) {
throw new UnsupportedFormatError('Spec does not support JSON format.')
}
Expand Down