Skip to content

Commit 695af05

Browse files
fix: add jsdoc
1 parent 4b48f99 commit 695af05

10 files changed

+32
-38
lines changed

tools/spectral/ipa/metrics/collector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ class Collector {
3636
});
3737
}
3838

39-
add(type, componentId, ruleName, exceptionReason = null ) {
39+
add(type, componentId, ruleName, exceptionReason = null) {
4040
if (componentId && ruleName && type) {
4141
if (!Object.values(EntryType).includes(type)) {
4242
throw new Error(`Invalid entry type: ${type}`);
4343
}
4444

4545
componentId = componentId.join('.');
46-
const entry = {componentId, ruleName};
46+
const entry = { componentId, ruleName };
4747

48-
if(type === EntryType.EXCEPTION && exceptionReason) {
48+
if (type === EntryType.EXCEPTION && exceptionReason) {
4949
entry.exceptionReason = exceptionReason;
5050
}
5151

tools/spectral/ipa/rulesets/functions/eachCustomMethodMustBeGetOrPost.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { isCustomMethod } from './utils/resourceEvaluation.js';
22
import { collectException, hasException } from './utils/exceptions.js';
3-
import {
4-
collectAdoption,
5-
collectAndReturnViolation,
6-
} from './utils/collectionUtils.js';
3+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
74

85
const RULE_NAME = 'xgen-IPA-109-custom-method-must-be-GET-or-POST';
96
const ERROR_MESSAGE = 'The HTTP method for custom methods must be GET or POST.';

tools/spectral/ipa/rulesets/functions/eachCustomMethodMustUseCamelCase.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { getCustomMethodName, isCustomMethod } from './utils/resourceEvaluation.js';
22
import { collectException, hasException } from './utils/exceptions.js';
33
import { casing } from '@stoplight/spectral-functions';
4-
import {
5-
collectAdoption,
6-
collectAndReturnViolation,
7-
} from './utils/collectionUtils.js';
4+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
85

96
const RULE_NAME = 'xgen-IPA-109-custom-method-must-use-camel-case';
107

tools/spectral/ipa/rulesets/functions/eachEnumValueMustBeUpperSnakeCase.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { collectException, hasException } from './utils/exceptions.js';
22
import { resolveObject } from './utils/componentUtils.js';
33
import { casing } from '@stoplight/spectral-functions';
4-
import {
5-
collectAdoption,
6-
collectAndReturnViolation,
7-
} from './utils/collectionUtils.js';
4+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
85

96
const RULE_NAME = 'xgen-IPA-123-enum-values-must-be-upper-snake-case';
107
const ERROR_MESSAGE = 'enum value must be UPPER_SNAKE_CASE.';
@@ -43,5 +40,4 @@ export default (input, _, { path, documentInventory }) => {
4340
} else {
4441
return collectAndReturnViolation(path, RULE_NAME, errors);
4542
}
46-
4743
};

tools/spectral/ipa/rulesets/functions/eachPathAlternatesBetweenResourceNameAndPathParam.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { isPathParam } from './utils/componentUtils.js';
22
import { collectException, hasException } from './utils/exceptions.js';
3-
import {
4-
collectAdoption,
5-
collectAndReturnViolation,
6-
} from './utils/collectionUtils.js';
3+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
74

85
const RULE_NAME = 'xgen-IPA-102-path-alternate-resource-name-path-param';
96
const ERROR_MESSAGE = 'API paths must alternate between resource name and path params.';

tools/spectral/ipa/rulesets/functions/eachResourceHasGetMethod.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import {
77
getResourcePaths,
88
} from './utils/resourceEvaluation.js';
99
import { collectException, hasException } from './utils/exceptions.js';
10-
import {
11-
collectAdoption,
12-
collectAndReturnViolation,
13-
} from './utils/collectionUtils.js';
10+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
1411

1512
const RULE_NAME = 'xgen-IPA-104-resource-has-GET';
1613
const ERROR_MESSAGE = 'APIs must provide a get method for resources.';

tools/spectral/ipa/rulesets/functions/exceptionExtensionFormat.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
collectAdoption,
3-
collectAndReturnViolation,
4-
} from './utils/collectionUtils.js';
1+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
52

63
const RULE_NAME = 'xgen-IPA-005-exception-extension-format';
74
const ERROR_MESSAGE = 'IPA exceptions must have a valid rule name and a reason.';

tools/spectral/ipa/rulesets/functions/singletonHasNoId.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import {
77
} from './utils/resourceEvaluation.js';
88
import { collectException, hasException } from './utils/exceptions.js';
99
import { getAllSuccessfulGetResponseSchemas } from './utils/methodUtils.js';
10-
import {
11-
collectAdoption,
12-
collectAndReturnViolation,
13-
} from './utils/collectionUtils.js';
10+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
1411

1512
const RULE_NAME = 'xgen-IPA-113-singleton-must-not-have-id';
1613
const ERROR_MESSAGE = 'Singleton resources must not have a user-provided or system-generated ID.';
@@ -23,7 +20,7 @@ export default (input, opts, { path, documentInventory }) => {
2320
}
2421

2522
if (hasException(input, RULE_NAME)) {
26-
collectException(input, RULE_NAME, path)
23+
collectException(input, RULE_NAME, path);
2724
return;
2825
}
2926

tools/spectral/ipa/rulesets/functions/utils/collectionUtils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import collector, { EntryType } from '../../../metrics/collector.js';
22

3+
/**
4+
* Collects a violation entry and returns formatted error data.
5+
*
6+
* @param {string} path - The JSON path for the object where the rule violation occurred.
7+
* @param {string} ruleName - The name of the rule that was violated.
8+
* @param {string|Array<Object>} errorData - The error information. Can be either a string message or an array of error objects.
9+
* @returns {Array<Object>} An array of error objects. Each object has a 'message' property.
10+
* @throws {Error} Throws an error if errorData is neither a string nor an array.
11+
*
12+
*/
313
export function collectAndReturnViolation(path, ruleName, errorData) {
414
collector.add(EntryType.VIOLATION, path, ruleName);
515

@@ -12,6 +22,12 @@ export function collectAndReturnViolation(path, ruleName, errorData) {
1222
}
1323
}
1424

25+
/**
26+
* Collects an adoption entry.
27+
*
28+
* @param {string} path - The JSON path for the object where the rule adoption occurred.
29+
* @param {string} ruleName - The name of the rule that was adopted.
30+
*/
1531
export function collectAdoption(path, ruleName) {
1632
collector.add(EntryType.ADOPTION, path, ruleName);
17-
}
33+
}

tools/spectral/ipa/rulesets/functions/utils/exceptions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ export function hasException(object, ruleName) {
1717
}
1818

1919
/**
20-
* Collects the information about the object if the object has an exception defined for the given rule
20+
* Collects an exception entry.
2121
*
2222
* @param object the object to evaluate
23-
* @param ruleName the name of the exempted rule
24-
* @param path the JSON path to the object
23+
* @param {string} path - The JSON path for the object where the rule exception occurred.
24+
* @param {string} ruleName - The name of the rule that the exception is defined for.
2525
*/
2626
export function collectException(object, ruleName, path) {
2727
let exceptionReason = object[EXCEPTION_EXTENSION][ruleName];
28-
if(exceptionReason) {
28+
if (exceptionReason) {
2929
collector.add(EntryType.EXCEPTION, path, ruleName, exceptionReason);
3030
}
3131
}

0 commit comments

Comments
 (0)