Skip to content

Commit 3c86c70

Browse files
authored
Merge pull request #415 from secvisogram/412-prettier-in-pipeline
chore: add prettier to test pipeline
2 parents 4c505d5 + 25951a7 commit 3c86c70

File tree

10 files changed

+74
-44
lines changed

10 files changed

+74
-44
lines changed

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/.github
2+
/.gitlab-ci.yml
3+
4+
/build
5+
/.nyc_output
6+
/coverage
7+
/.venv
8+
/csaf
9+
**/*.json
10+
/lib/shared/first

csaf_2_1/recommendedTests/recommendedTest_6_2_27.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ export function recommendedTest_6_2_27(doc) {
138138
const productToCategoriesMap = new Map()
139139

140140
const productStatus = new Map(
141-
Object.entries(vulnerability.product_status || {})
142-
);
141+
Object.entries(vulnerability.product_status || {})
142+
)
143143
vulnerability.remediations?.forEach((remediation, remediationIndex) => {
144144
const category = remediation.category
145145
if (!category) return
@@ -173,9 +173,9 @@ export function recommendedTest_6_2_27(doc) {
173173
for (const [productId, categories] of productToCategoriesMap) {
174174
for (const category of categories) {
175175
const status = discouragedRuleMap.get(category)
176-
if (!status) continue// There are no discouraged rules for this category.
176+
if (!status) continue // There are no discouraged rules for this category.
177177
status.forEach((s) => {
178-
const statusList = productStatus.get(s);
178+
const statusList = productStatus.get(s)
179179
if (Array.isArray(statusList) && statusList.includes(productId)) {
180180
ctx.warnings.push({
181181
instancePath: `/vulnerabilities/${vulnerabilityIndex}/remediations/${remediationIndex}`,

csaf_2_1/recommendedTests/recommendedTest_6_2_29.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Ajv from 'ajv/dist/jtd.js'
2-
import {NIL_UUID} from "../sharingGroup.js";
2+
import { NIL_UUID } from '../sharingGroup.js'
33

44
const ajv = new Ajv()
55

@@ -29,13 +29,13 @@ const validateInput = ajv.compile(inputSchema)
2929
/**
3030
* Test for the optional test 6.2.28
3131
* The Nil UUID should not be used as sharing group id.
32-
*
32+
*
3333
* @param {any} doc
3434
*/
3535
export function recommendedTest_6_2_29(doc) {
3636
const ctx = {
3737
warnings:
38-
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
38+
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
3939
}
4040

4141
if (!validateInput(doc)) {
@@ -50,4 +50,4 @@ export function recommendedTest_6_2_29(doc) {
5050
}
5151

5252
return ctx
53-
}
53+
}

lib/informativeTests/shared/testURL.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ const packageInfo = createRequire(import.meta.url)('../../../package.json')
1515
*/
1616
export default async function testURL(url, onError) {
1717
// set user-agent to csaf-validator-lib/VERSION
18-
const userAgent = `${packageInfo.name.split('/').at(-1)}/${packageInfo.version}`
18+
const userAgent = `${packageInfo.name.split('/').at(-1)}/${
19+
packageInfo.version
20+
}`
1921
try {
2022
const res = await request(url, {
2123
method: 'HEAD',
2224
headers: {
23-
'User-Agent': userAgent
24-
}
25+
'User-Agent': userAgent,
26+
},
2527
})
2628
if (res.statusCode < 200 || 400 <= res.statusCode) {
2729
onError()

lib/mandatoryTests/mandatoryTest_6_1_13.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ export default function mandatoryTest_6_1_13(doc) {
1616
/** @type {any} */ fullProductName,
1717
/** @type {number} */ fullProductNameIndex
1818
) => {
19-
checkProductIdentificationHelperPURL(fullProductName, (errorMessage) => {
20-
isValid = false
21-
errors.push({
22-
instancePath: `/product_tree/full_product_names/${fullProductNameIndex}/product_identification_helper/purl`,
23-
message: `invalid purl: ${errorMessage}`,
24-
})
25-
})
19+
checkProductIdentificationHelperPURL(
20+
fullProductName,
21+
(errorMessage) => {
22+
isValid = false
23+
errors.push({
24+
instancePath: `/product_tree/full_product_names/${fullProductNameIndex}/product_identification_helper/purl`,
25+
message: `invalid purl: ${errorMessage}`,
26+
})
27+
}
28+
)
2629
}
2730
)
2831
}
@@ -48,17 +51,20 @@ export default function mandatoryTest_6_1_13(doc) {
4851
}
4952

5053
if (doc.product_tree) {
51-
checkBranchesForInvalidPURLs(doc.product_tree, ({ branchIndexes, errorMessage }) => {
52-
isValid = false
53-
const branchPathPart = branchIndexes.reduce(
54-
(str, index) => `${str}/branches/${index}`,
55-
'/product_tree'
56-
)
57-
errors.push({
58-
instancePath: `${branchPathPart}/product/product_identification_helper/purl`,
59-
message: `invalid purl: ${errorMessage}`,
60-
})
61-
})
54+
checkBranchesForInvalidPURLs(
55+
doc.product_tree,
56+
({ branchIndexes, errorMessage }) => {
57+
isValid = false
58+
const branchPathPart = branchIndexes.reduce(
59+
(str, index) => `${str}/branches/${index}`,
60+
'/product_tree'
61+
)
62+
errors.push({
63+
instancePath: `${branchPathPart}/product/product_identification_helper/purl`,
64+
message: `invalid purl: ${errorMessage}`,
65+
})
66+
}
67+
)
6268
}
6369

6470
return { errors, isValid }
@@ -100,6 +106,6 @@ const checkProductIdentificationHelperPURL = (productALike, onError) => {
100106
PackageURL.fromString(productALike?.product_identification_helper?.purl)
101107
} catch (e) {
102108
const errorObject = /** @type {{message: string}} */ (e)
103-
onError(errorObject?.message ?? "Unknown purl error")
109+
onError(errorObject?.message ?? 'Unknown purl error')
104110
}
105111
}

lib/mandatoryTests/mandatoryTest_6_1_30.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export default function mandatoryTest_6_1_30(doc) {
6262
}
6363
}
6464
})
65-
if (versioningSchema != null && typeof doc.document.tracking.version === 'string') {
65+
if (
66+
versioningSchema != null &&
67+
typeof doc.document.tracking.version === 'string'
68+
) {
6669
if (
6770
versioningSchema !== detectVersionSchema(doc.document.tracking.version)
6871
) {

lib/mandatoryTests/mandatoryTest_6_1_31.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,21 @@ export default function mandatoryTest_6_1_31(doc) {
6464
(['<', '<=', '>', '>='].some((str) =>
6565
branch.name?.toLowerCase().includes(str)
6666
) ||
67-
['after', 'all', 'before', 'earlier', 'later', 'prior', 'versions'].some(
68-
(str) =>
69-
branch.name
70-
?.toLowerCase()
71-
.split(/\s/)
72-
.some((word) => {
73-
return str === word
74-
})
67+
[
68+
'after',
69+
'all',
70+
'before',
71+
'earlier',
72+
'later',
73+
'prior',
74+
'versions',
75+
].some((str) =>
76+
branch.name
77+
?.toLowerCase()
78+
.split(/\s/)
79+
.some((word) => {
80+
return str === word
81+
})
7582
))
7683
) {
7784
ctx.isValid = false

lib/shared/dateHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const compareZonedDateTimes = (a, b) => {
2727
} else {
2828
return -1
2929
}
30-
} catch(e) {
30+
} catch (e) {
3131
return 0
3232
}
3333
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"license": "MIT",
55
"scripts": {
66
"pretest": "tsc -b .",
7-
"test": "node scripts/test.js",
7+
"test": "prettier --check . && node scripts/test.js",
88
"pretest-report": "tsc -b .",
9-
"test-report": "node scripts/test.js --reporter json > test-results.json",
9+
"test-report": "prettier --check . && node scripts/test.js --reporter json > test-results.json",
1010
"test-coverage": "c8 node scripts/test.js",
1111
"test-coverage-lcov": "c8 --reporter lcovonly node scripts/test.js"
1212
},

prettier.config.cjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/** @type {import('prettier').Config} */
12
module.exports = {
23
bracketSpacing: true,
34
singleQuote: true,
4-
semi: false
5-
};
5+
semi: false,
6+
endOfLine: process.platform === 'win32' ? 'auto' : 'lf',
7+
}

0 commit comments

Comments
 (0)