Skip to content

Commit 694e2da

Browse files
fix
1 parent 4ce7f0c commit 694e2da

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
1+
import {
2+
collectAdoption,
3+
collectAndReturnViolation,
4+
collectException,
5+
handleInternalError,
6+
} from './utils/collectionUtils.js';
27
import { hasException } from './utils/exceptions.js';
38
import { resolveObject } from './utils/componentUtils.js';
49

@@ -20,11 +25,22 @@ export default (input, options, { path, documentInventory }) => {
2025
return;
2126
}
2227

23-
if (IS_PREFIX_REGEX.test(input)) {
24-
const suggestedName = input.charAt(2).toLowerCase() + input.slice(3);
25-
const errorMessage = `Boolean field "${input}" should not use the "is" prefix. Use "${suggestedName}" instead.`;
26-
return collectAndReturnViolation(path, RULE_NAME, errorMessage);
28+
const errors = checkViolationsAndReturnErrors(input, path);
29+
if (errors.length !== 0) {
30+
return collectAndReturnViolation(path, RULE_NAME, errors);
2731
}
28-
2932
collectAdoption(path, RULE_NAME);
3033
};
34+
35+
function checkViolationsAndReturnErrors(input, path) {
36+
try {
37+
if (IS_PREFIX_REGEX.test(input)) {
38+
const suggestedName = input.charAt(2).toLowerCase() + input.slice(3);
39+
const errorMessage = `Boolean field "${input}" should not use the "is" prefix. Use "${suggestedName}" instead.`;
40+
return [{ path, message: errorMessage }];
41+
}
42+
return [];
43+
} catch (e) {
44+
handleInternalError(RULE_NAME, path, e);
45+
}
46+
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { casing } from '@stoplight/spectral-functions';
2-
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
2+
import {
3+
collectAdoption,
4+
collectAndReturnViolation,
5+
collectException,
6+
handleInternalError,
7+
} from './utils/collectionUtils.js';
38
import { hasException } from './utils/exceptions.js';
49
import { resolveObject } from './utils/componentUtils.js';
510

@@ -15,14 +20,31 @@ export default (input, options, { path, documentInventory }) => {
1520
return;
1621
}
1722

23+
if (input === 'mongoDBEmployeeAccessGrant') {
24+
console.log(property);
25+
console.log(path);
26+
}
27+
1828
if (hasException(property, RULE_NAME)) {
1929
collectException(property, RULE_NAME, path);
2030
return;
2131
}
2232

23-
if (casing(input, { type: 'camel', disallowDigits: true })) {
24-
const errorMessage = `Property "${input}" must use camelCase format.`;
25-
return collectAndReturnViolation(path, RULE_NAME, errorMessage);
33+
const errors = checkViolationsAndReturnErrors(input, path);
34+
if (errors.length !== 0) {
35+
return collectAndReturnViolation(path, RULE_NAME, errors);
2636
}
2737
collectAdoption(path, RULE_NAME);
2838
};
39+
40+
function checkViolationsAndReturnErrors(input, path) {
41+
try {
42+
if (casing(input, { type: 'camel', disallowDigits: true })) {
43+
const errorMessage = `Property "${input}" must use camelCase format.`;
44+
return [{ path, message: errorMessage }];
45+
}
46+
return [];
47+
} catch (e) {
48+
handleInternalError(RULE_NAME, path, e);
49+
}
50+
}

0 commit comments

Comments
 (0)