@dogfood-lab/findings 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/advise/advice-bundle.js +155 -155
- package/advise/index.js +5 -5
- package/advise/query.js +182 -182
- package/derive/dedupe.js +107 -107
- package/derive/derive-findings.js +187 -187
- package/derive/ids.js +48 -48
- package/derive/index.js +9 -9
- package/derive/load-records.js +153 -153
- package/derive/rules.js +415 -415
- package/derive/write-findings.js +63 -63
- package/index.js +11 -11
- package/lib/file-lock.js +359 -359
- package/package.json +2 -2
- package/reader.js +156 -156
- package/review/index.js +6 -6
- package/review/transitions.js +79 -79
- package/synthesis/doctrine-derivation.js +128 -128
- package/synthesis/index.js +8 -8
- package/synthesis/pattern-derivation.js +184 -184
- package/synthesis/recommendation-derivation.js +156 -156
- package/synthesis/validate-artifacts.js +46 -46
- package/synthesis/write-artifacts.js +75 -75
- package/validate.js +87 -87
package/validate.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finding schema validator.
|
|
3
|
-
* Validates YAML finding files against dogfood-finding.schema.json.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { readFileSync } from 'node:fs';
|
|
7
|
-
import { createRequire } from 'node:module';
|
|
8
|
-
import Ajv2020 from 'ajv/dist/2020.js';
|
|
9
|
-
import addFormats from 'ajv-formats';
|
|
10
|
-
import yaml from 'js-yaml';
|
|
11
|
-
|
|
12
|
-
const require = createRequire(import.meta.url);
|
|
13
|
-
|
|
14
|
-
/** Load and compile the finding schema once. */
|
|
15
|
-
function createValidator() {
|
|
16
|
-
const schemaPath = require.resolve('@dogfood-lab/schemas/json/dogfood-finding.schema.json');
|
|
17
|
-
const schema = JSON.parse(readFileSync(schemaPath, 'utf-8'));
|
|
18
|
-
|
|
19
|
-
const ajv = new Ajv2020({ allErrors: true, strict: false });
|
|
20
|
-
addFormats(ajv);
|
|
21
|
-
|
|
22
|
-
return ajv.compile(schema);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let _validator = null;
|
|
26
|
-
|
|
27
|
-
function getValidator() {
|
|
28
|
-
if (!_validator) {
|
|
29
|
-
_validator = createValidator();
|
|
30
|
-
}
|
|
31
|
-
return _validator;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Parse a YAML finding file and return the data.
|
|
36
|
-
* @param {string} filePath - Absolute path to a .yaml finding file.
|
|
37
|
-
* @returns {{ data: object | null, error: string | null }}
|
|
38
|
-
*/
|
|
39
|
-
export function parseFinding(filePath) {
|
|
40
|
-
try {
|
|
41
|
-
const raw = readFileSync(filePath, 'utf-8');
|
|
42
|
-
const data = yaml.load(raw);
|
|
43
|
-
if (!data || typeof data !== 'object') {
|
|
44
|
-
return { data: null, error: 'File did not parse to an object' };
|
|
45
|
-
}
|
|
46
|
-
return { data, error: null };
|
|
47
|
-
} catch (err) {
|
|
48
|
-
return { data: null, error: `YAML parse error: ${err.message}` };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Validate a parsed finding object against the schema.
|
|
54
|
-
* @param {object} finding - Parsed finding data.
|
|
55
|
-
* @returns {{ valid: boolean, errors: Array<{ path: string, message: string }> }}
|
|
56
|
-
*/
|
|
57
|
-
export function validateFinding(finding) {
|
|
58
|
-
const validate = getValidator();
|
|
59
|
-
const valid = validate(finding);
|
|
60
|
-
|
|
61
|
-
if (valid) {
|
|
62
|
-
return { valid: true, errors: [] };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const errors = (validate.errors || []).map(err => ({
|
|
66
|
-
path: err.instancePath || '/',
|
|
67
|
-
message: err.message || 'unknown error',
|
|
68
|
-
params: err.params
|
|
69
|
-
}));
|
|
70
|
-
|
|
71
|
-
return { valid: false, errors };
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Parse and validate a YAML finding file in one call.
|
|
76
|
-
* @param {string} filePath - Absolute path to a .yaml finding file.
|
|
77
|
-
* @returns {{ valid: boolean, data: object | null, errors: Array<{ path: string, message: string }> }}
|
|
78
|
-
*/
|
|
79
|
-
export function validateFindingFile(filePath) {
|
|
80
|
-
const { data, error } = parseFinding(filePath);
|
|
81
|
-
if (error) {
|
|
82
|
-
return { valid: false, data: null, errors: [{ path: '/', message: error }] };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const result = validateFinding(data);
|
|
86
|
-
return { ...result, data };
|
|
87
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Finding schema validator.
|
|
3
|
+
* Validates YAML finding files against dogfood-finding.schema.json.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import Ajv2020 from 'ajv/dist/2020.js';
|
|
9
|
+
import addFormats from 'ajv-formats';
|
|
10
|
+
import yaml from 'js-yaml';
|
|
11
|
+
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
|
|
14
|
+
/** Load and compile the finding schema once. */
|
|
15
|
+
function createValidator() {
|
|
16
|
+
const schemaPath = require.resolve('@dogfood-lab/schemas/json/dogfood-finding.schema.json');
|
|
17
|
+
const schema = JSON.parse(readFileSync(schemaPath, 'utf-8'));
|
|
18
|
+
|
|
19
|
+
const ajv = new Ajv2020({ allErrors: true, strict: false });
|
|
20
|
+
addFormats(ajv);
|
|
21
|
+
|
|
22
|
+
return ajv.compile(schema);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let _validator = null;
|
|
26
|
+
|
|
27
|
+
function getValidator() {
|
|
28
|
+
if (!_validator) {
|
|
29
|
+
_validator = createValidator();
|
|
30
|
+
}
|
|
31
|
+
return _validator;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Parse a YAML finding file and return the data.
|
|
36
|
+
* @param {string} filePath - Absolute path to a .yaml finding file.
|
|
37
|
+
* @returns {{ data: object | null, error: string | null }}
|
|
38
|
+
*/
|
|
39
|
+
export function parseFinding(filePath) {
|
|
40
|
+
try {
|
|
41
|
+
const raw = readFileSync(filePath, 'utf-8');
|
|
42
|
+
const data = yaml.load(raw);
|
|
43
|
+
if (!data || typeof data !== 'object') {
|
|
44
|
+
return { data: null, error: 'File did not parse to an object' };
|
|
45
|
+
}
|
|
46
|
+
return { data, error: null };
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return { data: null, error: `YAML parse error: ${err.message}` };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Validate a parsed finding object against the schema.
|
|
54
|
+
* @param {object} finding - Parsed finding data.
|
|
55
|
+
* @returns {{ valid: boolean, errors: Array<{ path: string, message: string }> }}
|
|
56
|
+
*/
|
|
57
|
+
export function validateFinding(finding) {
|
|
58
|
+
const validate = getValidator();
|
|
59
|
+
const valid = validate(finding);
|
|
60
|
+
|
|
61
|
+
if (valid) {
|
|
62
|
+
return { valid: true, errors: [] };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const errors = (validate.errors || []).map(err => ({
|
|
66
|
+
path: err.instancePath || '/',
|
|
67
|
+
message: err.message || 'unknown error',
|
|
68
|
+
params: err.params
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
return { valid: false, errors };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parse and validate a YAML finding file in one call.
|
|
76
|
+
* @param {string} filePath - Absolute path to a .yaml finding file.
|
|
77
|
+
* @returns {{ valid: boolean, data: object | null, errors: Array<{ path: string, message: string }> }}
|
|
78
|
+
*/
|
|
79
|
+
export function validateFindingFile(filePath) {
|
|
80
|
+
const { data, error } = parseFinding(filePath);
|
|
81
|
+
if (error) {
|
|
82
|
+
return { valid: false, data: null, errors: [{ path: '/', message: error }] };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const result = validateFinding(data);
|
|
86
|
+
return { ...result, data };
|
|
87
|
+
}
|