Skip to content

Commit ccdd7f5

Browse files
style: modernize eslint & apply code-style cb9013d691 (#1170)
based on #1169 --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent efe2ff6 commit ccdd7f5

30 files changed

+105
-56
lines changed

.github/workflows/nodejs.yml

+25-7
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,20 @@ jobs:
8080
run: npm run test:lint
8181

8282
test-standard:
83+
needs: [ 'build' ]
8384
name: test standard
8485
runs-on: ubuntu-latest
8586
timeout-minutes: 10
8687
steps:
8788
- name: Checkout
8889
# see https://github.com/actions/checkout
8990
uses: actions/checkout@v4
91+
- name: fetch build artifact
92+
# see https://github.com/actions/download-artifact
93+
uses: actions/download-artifact@v4
94+
with:
95+
name: dist.d
96+
path: dist.d
9097
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
9198
# see https://github.com/actions/setup-node
9299
uses: actions/setup-node@v4
@@ -99,6 +106,17 @@ jobs:
99106
echo "::group::install deps"
100107
npm i --ignore-scripts --loglevel=silly
101108
echo "::endgroup::"
109+
echo "::group::install example javascript"
110+
npm --prefix examples/node/javascript i --ignore-scripts --loglevel=silly
111+
echo "::endgroup::"
112+
echo "::group::install example typescript cjs"
113+
npm --prefix examples/node/typescript/example.cjs i --ignore-scripts --loglevel=silly
114+
echo "::endgroup::"
115+
echo "::group::install examples typescript mjs"
116+
npm --prefix examples/node/typescript/example.mjs i --ignore-scripts --loglevel=silly
117+
echo "::endgroup::"
118+
- name: setup tools
119+
run: |
102120
echo "::group::install docs-gen deps"
103121
npm --prefix tools/docs-gen i --ignore-scripts --loglevel=silly
104122
echo "::endgroup::"
@@ -110,15 +128,15 @@ jobs:
110128
- name: test
111129
run: >
112130
npm run -- test:standard
113-
--format checkstyle
114-
--output-file "$PWD/$REPORTS_DIR/eslint.xml"
115-
- name: Publish Checkstyle report
116-
# see https://github.com/Juuxel/publish-checkstyle-report
117-
uses: Juuxel/publish-checkstyle-report@v1
131+
--format json
132+
--output-file "$PWD/$REPORTS_DIR/eslint.json"
133+
- name: Annotate Code
118134
if: ${{ failure() || success() }}
135+
# see https://github.com/DerLev/eslint-annotations
136+
uses: DerLev/eslint-annotations@v2
119137
with:
120-
reports: ${{ env.REPORTS_DIR }}/eslint.xml
121-
- name: artifact build result
138+
eslint-report: ${{ env.REPORTS_DIR }}/eslint.json
139+
- name: artifact eslint result
122140
# see https://github.com/actions/upload-artifact
123141
uses: actions/upload-artifact@v4
124142
if: ${{ failure() }}

examples/node/typescript/example.mjs/src/example.ts

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const serializedJson = jsonSerializer.serialize(bom)
5454
console.log(serializedJson)
5555
const jsonValidator = new CDX.Validation.JsonStrictValidator(serializeSpec.version)
5656
try {
57+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- intended */
5758
const validationErrors = await jsonValidator.validate(serializedJson)
5859
if (validationErrors === null) {
5960
console.info('JSON valid')
@@ -75,6 +76,7 @@ const serializedXML = xmlSerializer.serialize(bom)
7576
console.log(serializedXML)
7677
const xmlValidator = new CDX.Validation.XmlValidator(serializeSpec.version)
7778
try {
79+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- intended */
7880
const validationErrors = await xmlValidator.validate(serializedXML)
7981
if (validationErrors === null) {
8082
console.info('XML valid')

src/_helpers/packageJson.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2525
* Having multiple slashes(`/`) is basically no issue.
2626
*/
2727
export function splitNameGroup (data: string): [string, string?] {
28-
const delimGroup = data[0] === '@'
28+
const delimGroup = data.startsWith('@')
2929
? data.indexOf('/', 2)
3030
: 0
3131
return delimGroup > 0

src/_optPlug.node/__jsonValidators/ajv.ts

+4
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,19 @@ const ajvOptions: AjvOptions = Object.freeze({
3636

3737
/** @internal */
3838
export default (async function (schemaPath: string, schemaMap: Record<string, string> = {}): Promise<Validator> {
39+
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return -- intended */
3940
const [schema, schemas] = await Promise.all([
4041
readFile(schemaPath, 'utf-8').then(c => JSON.parse(c)),
4142
Promise.all(Object.entries(schemaMap).map(
4243
async ([k, v]) => await readFile(v, 'utf-8').then(c => [k, JSON.parse(c)])
4344
)).then(es => Object.fromEntries(es))
4445
])
46+
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return */
4547

48+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- intended */
4649
const ajv = new Ajv({ ...ajvOptions, schemas })
4750
addFormats(ajv)
51+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-call -- intended */
4852
addFormats2019(ajv, { formats: ['idn-email'] })
4953
// there is just no working implementation for format "iri-reference": see https://github.com/luzlab/ajv-formats-draft2019/issues/22
5054
ajv.addFormat('iri-reference', true)

src/_optPlug.node/errors.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class OptPlugError extends Error {
2222

2323
constructor (message: string, cause?: any) {
2424
super(message)
25+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- intended */
2526
this.cause = cause
2627
}
2728
}

src/_optPlug.node/jsonValidator.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ export type Validator = (data: string) => null | ValidationError
2424
export type Functionality = (schemaPath: string, schemaMap: Record<string, string>) => Promise<Validator>
2525

2626
export default opWrapper<Functionality>('JsonValidator', [
27-
/* eslint-disable @typescript-eslint/no-var-requires */
27+
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports
28+
-- needed */
29+
2830
['( ajv && ajv-formats && ajv-formats-draft2019 )', () => require('./__jsonValidators/ajv').default]
2931
// ... add others here, pull-requests welcome!
30-
/* eslint-enable @typescript-eslint/no-var-requires */
32+
33+
/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports */
3134
]) satisfies Functionality | WillThrow

src/_optPlug.node/xmlStringify.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ import opWrapper, { type WillThrow } from './_wrapper'
2424
export type Functionality = (element: SimpleXml.Element, options?: SerializerOptions) => string
2525

2626
export default opWrapper<Functionality>('XmlStringifier', [
27-
/* eslint-disable @typescript-eslint/no-var-requires */
27+
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports
28+
-- needed */
29+
2830
['xmlbuilder2', () => require('./__xmlStringifiers/xmlbuilder2').default]
2931
// ... add others here, pull-requests welcome!
30-
/* eslint-enable @typescript-eslint/no-var-requires */
32+
33+
/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports */
3134
]) satisfies Functionality | WillThrow

src/_optPlug.node/xmlValidator.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ export type Validator = (data: string) => null | ValidationError
2424
export type Functionality = (schemaPath: string) => Promise<Validator>
2525

2626
export default opWrapper<Functionality>('XmlValidator', [
27-
/* eslint-disable @typescript-eslint/no-var-requires */
27+
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports
28+
-- needed */
29+
2830
['libxmljs2', () => require('./__xmlValidators/libxmljs2').default]
2931
// ... add others here, pull-requests welcome!
30-
/* eslint-enable @typescript-eslint/no-var-requires */
32+
33+
/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports */
3134
]) satisfies Functionality | WillThrow

src/builders/fromNodePackageJson.node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class ComponentBuilder {
127127
if (Array.isArray(data.licenses)) {
128128
/* see https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json */
129129
for (const licenseData of data.licenses) {
130-
if (typeof licenseData?.type === 'string') {
130+
if (typeof licenseData.type === 'string') {
131131
const license = this.#licenseFactory.makeDisjunctive(licenseData.type)
132132
license.url = typeof licenseData.url === 'string'
133133
? licenseData.url

src/factories/fromNodePackageJson.node.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export class ExternalReferenceFactory {
5454
makeVcs (data: PackageJson): ExternalReference | undefined {
5555
/* see https://docs.npmjs.com/cli/v9/configuring-npm/package-json#repositoryc */
5656
const repository = data.repository
57-
let url
58-
let comment: string | undefined
57+
let url = undefined
58+
let comment: string | undefined = undefined
5959
if (typeof repository === 'object') {
6060
url = tryCanonicalizeGitUrl(repository.url)
6161
comment = 'as detected from PackageJson property "repository.url"'
@@ -87,8 +87,8 @@ export class ExternalReferenceFactory {
8787
makeIssueTracker (data: PackageJson): ExternalReference | undefined {
8888
/* see https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bugs */
8989
const bugs = data.bugs
90-
let url
91-
let comment: string | undefined
90+
let url = undefined
91+
let comment: string | undefined = undefined
9292
if (typeof bugs === 'object') {
9393
url = bugs.url
9494
comment = 'as detected from PackageJson property "bugs.url"'
@@ -113,6 +113,7 @@ const npmDefaultRepositoryMatcher = /^https?:\/\/registry\.npmjs\.org(:?\/|$)/
113113
* @see {@link https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#npm}
114114
*/
115115
export class PackageUrlFactory extends PlainPackageUrlFactory<'npm'> {
116+
/* eslint-disable-next-line @typescript-eslint/no-inferrable-types -- docs */
116117
override makeFromComponent (component: Component, sort: boolean = false): PackageURL | undefined {
117118
const purl = super.makeFromComponent(component, sort)
118119
return purl === undefined

src/factories/packageUrl.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ export class PackageUrlFactory<PurlType extends PackageURL['type'] = PackageURL[
3434
return this.#type
3535
}
3636

37+
/* eslint-disable-next-line @typescript-eslint/no-inferrable-types -- docs */
3738
makeFromComponent (component: Component, sort: boolean = false): PackageURL | undefined {
3839
const qualifiers: PackageURL['qualifiers'] = {}
39-
let subpath: PackageURL['subpath']
40+
let subpath: PackageURL['subpath'] = undefined
4041

4142
// sorting to allow reproducibility: use the last instance for a `extRef.type`, if multiples exist
4243
const extRefs = sort
@@ -51,6 +52,7 @@ export class PackageUrlFactory<PurlType extends PackageURL['type'] = PackageURL[
5152
// According to https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst
5253
// there is no formal requirement to a `..._url`.
5354
// Everything is possible: URL-encoded, not encoded, with schema, without schema
55+
/* eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- intended */
5456
switch (extRef.type) {
5557
case ExternalReferenceType.VCS:
5658
[qualifiers[PackageUrlQualifierNames.VcsUrl], subpath] = url.split('#', 2)

src/serialize/bomRefDiscriminator.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class BomRefDiscriminator {
2424

2525
readonly #prefix: string
2626

27+
/* eslint-disable-next-line @typescript-eslint/no-inferrable-types -- docs */
2728
constructor (bomRefs: Iterable<BomRef>, prefix: string = 'BomRef') {
2829
this.#originalValues = Array.from(bomRefs, r => [r, r.value])
2930
this.#prefix = prefix

src/serialize/index.common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2121

2222
export * from './bomRefDiscriminator'
2323
export * from './errors'
24+
/* eslint-disable-next-line @typescript-eslint/consistent-type-exports -- backwards-compat TS4 */
2425
export * as Types from './types'
2526

2627
// region base

src/serialize/json/types.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { HashContent } from '../../models'
2222
import type { SpdxId } from '../../spdx'
2323
import type { CPE, CWE, Integer } from '../../types'
2424

25-
// eslint-disable-next-line @typescript-eslint/no-namespace
25+
/* eslint-disable-next-line @typescript-eslint/no-namespace -- needed */
2626
export namespace JsonSchema {
2727

2828
/**
@@ -62,14 +62,15 @@ export namespace JsonSchema {
6262

6363
}
6464

65-
// eslint-disable-next-line @typescript-eslint/no-namespace
65+
/* eslint-disable-next-line @typescript-eslint/no-namespace -- needed */
6666
export namespace Normalized {
6767

6868
export type RefType = string
6969
export type RefLinkType = RefType
7070

7171
export type BomLinkDocumentType = string
7272
export type BomLinkElementType = string
73+
/* eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents -- as of spec */
7374
export type BomLink = BomLinkDocumentType | BomLinkElementType
7475

7576
export interface Bom {
@@ -218,6 +219,7 @@ export namespace Normalized {
218219
}
219220

220221
export interface ExternalReference {
222+
/* eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents -- as of spec */
221223
url: JsonSchema.IriReference | BomLink
222224
type: Enums.ExternalReferenceType
223225
hashes?: Hash[]
@@ -261,7 +263,7 @@ export namespace Normalized {
261263
properties?: Property[]
262264
}
263265

264-
// eslint-disable-next-line @typescript-eslint/no-namespace
266+
/* eslint-disable-next-line @typescript-eslint/no-namespace -- needed */
265267
export namespace Vulnerability {
266268
export interface Source {
267269
name?: string
@@ -300,6 +302,7 @@ export namespace Normalized {
300302
}
301303

302304
export interface Affect {
305+
/* eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents -- as of spec */
303306
ref: RefLinkType | BomLinkElementType
304307
versions?: AffectedVersion[]
305308
}

src/serialize/xml/normalize.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ export class BomNormalizer extends BaseXmlNormalizer<Models.Bom> {
221221
: undefined
222222
},
223223
children: [
224-
data.metadata
225-
? this._factory.makeForMetadata().normalize(data.metadata, options, 'metadata')
226-
: undefined,
224+
this._factory.makeForMetadata().normalize(data.metadata, options, 'metadata'),
227225
components,
228226
services,
229227
this._factory.spec.supportsDependencyGraph

src/serialize/xml/types.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
// eslint-disable-next-line @typescript-eslint/no-namespace
20+
/* eslint-disable-next-line @typescript-eslint/no-namespace -- needed */
2121
export namespace XmlSchema {
2222

2323
const _AnyUriSchemePattern = /^[a-z][a-z0-9+\-.]*$/i
@@ -47,15 +47,13 @@ export namespace XmlSchema {
4747
}
4848

4949
const fragmentPos = value.indexOf('#')
50-
let beforeFragment: string
50+
let beforeFragment = value
5151
if (fragmentPos >= 0) {
5252
if (value.includes('#', fragmentPos + 1)) {
5353
// has a second fragment marker
5454
return false
5555
}
5656
beforeFragment = value.slice(undefined, fragmentPos)
57-
} else {
58-
beforeFragment = value
5957
}
6058

6159
const schemePos = beforeFragment.indexOf(':')
@@ -71,7 +69,7 @@ export namespace XmlSchema {
7169

7270
}
7371

74-
// eslint-disable-next-line @typescript-eslint/no-namespace
72+
/* eslint-disable-next-line @typescript-eslint/no-namespace -- needed */
7573
export namespace SimpleXml {
7674

7775
/**

src/spdx.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const spdxLowerToActual: Readonly<Record<string, SpdxId>> = Object.freeze(Object
3838
))
3939

4040
export function isSupportedSpdxId (value: SpdxId | any): value is SpdxId {
41-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
41+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
4242
return spdxIds.has(value)
4343
}
4444

src/spec/_protocol.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class _Spec implements _SpecProtocol {
7878
readonly #supportsLicenseAcknowledgement: boolean
7979
readonly #supportsServices: boolean
8080

81+
/* eslint-disable-next-line @typescript-eslint/max-params -- architectural decision */
8182
constructor (
8283
version: Version,
8384
formats: Iterable<Format>,
@@ -125,17 +126,17 @@ export class _Spec implements _SpecProtocol {
125126
}
126127

127128
supportsFormat (f: Format | any): boolean {
128-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
129+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
129130
return this.#formats.has(f)
130131
}
131132

132133
supportsComponentType (ct: ComponentType | any): boolean {
133-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
134+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
134135
return this.#componentTypes.has(ct)
135136
}
136137

137138
supportsHashAlgorithm (ha: HashAlgorithm | any): boolean {
138-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
139+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
139140
return this.#hashAlgorithms.has(ha)
140141
}
141142

@@ -145,7 +146,7 @@ export class _Spec implements _SpecProtocol {
145146
}
146147

147148
supportsExternalReferenceType (ert: ExternalReferenceType | any): boolean {
148-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
149+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
149150
return this.#externalReferenceTypes.has(ert)
150151
}
151152

@@ -171,7 +172,7 @@ export class _Spec implements _SpecProtocol {
171172
}
172173

173174
supportsVulnerabilityRatingMethod (rm: Vulnerability.RatingMethod | any): boolean {
174-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
175+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- any */
175176
return this.#vulnerabilityRatingMethods.has(rm)
176177
}
177178

src/types/cwe.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ export function isCWE (value: any): value is CWE {
3535
return isPositiveInteger(value)
3636
}
3737

38+
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- docs */
3839
export class CweRepository extends SortableNumbers<CWE> {}

0 commit comments

Comments
 (0)