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

Lines changed: 25 additions & 7 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

0 commit comments

Comments
 (0)