Skip to content

Commit b4e1731

Browse files
fix(ipa): exception reason formatting
1 parent ad52670 commit b4e1731

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

tools/spectral/ipa/__tests__/IPA005ExceptionExtensionFormat.test.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,27 @@ testRule('xgen-IPA-005-exception-extension-format', [
4646
'xgen-IPA-100-rule-name': {},
4747
},
4848
},
49+
'/path5': {
50+
'x-xgen-IPA-exception': {
51+
'xgen-IPA-1001-rule-name': {},
52+
},
53+
},
54+
'/path6': {
55+
'x-xgen-IPA-exception': {
56+
'xgen-IPA-1001-rule_name': {},
57+
},
58+
},
59+
'/path7': {
60+
'x-xgen-IPA-exception': {
61+
'xgen-IPA_100_rule-name': {},
62+
},
63+
},
4964
},
5065
},
5166
errors: [
5267
{
5368
code: 'xgen-IPA-005-exception-extension-format',
54-
message: 'IPA exceptions must have a valid key with xgen-IPA- prefix.',
69+
message: 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.',
5570
path: ['paths', '/path1', 'x-xgen-IPA-exception'],
5671
severity: DiagnosticSeverity.Error,
5772
},
@@ -63,7 +78,7 @@ testRule('xgen-IPA-005-exception-extension-format', [
6378
},
6479
{
6580
code: 'xgen-IPA-005-exception-extension-format',
66-
message: 'IPA exceptions must have a valid key with xgen-IPA- prefix.',
81+
message: 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.',
6782
path: ['paths', '/path3', 'x-xgen-IPA-exception'],
6883
severity: DiagnosticSeverity.Error,
6984
},
@@ -73,6 +88,24 @@ testRule('xgen-IPA-005-exception-extension-format', [
7388
path: ['paths', '/path4', 'x-xgen-IPA-exception'],
7489
severity: DiagnosticSeverity.Error,
7590
},
91+
{
92+
code: 'xgen-IPA-005-exception-extension-format',
93+
message: 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.',
94+
path: ['paths', '/path5', 'x-xgen-IPA-exception'],
95+
severity: DiagnosticSeverity.Error,
96+
},
97+
{
98+
code: 'xgen-IPA-005-exception-extension-format',
99+
message: 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.',
100+
path: ['paths', '/path6', 'x-xgen-IPA-exception'],
101+
severity: DiagnosticSeverity.Error,
102+
},
103+
{
104+
code: 'xgen-IPA-005-exception-extension-format',
105+
message: 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.',
106+
path: ['paths', '/path7', 'x-xgen-IPA-exception'],
107+
severity: DiagnosticSeverity.Error,
108+
},
76109
],
77110
},
78111
]);

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import {
2-
evaluateAndCollectAdoptionStatusWithoutExceptions,
3-
handleInternalError,
4-
} from './utils/collectionUtils.js';
1+
import { evaluateAndCollectAdoptionStatusWithoutExceptions, handleInternalError } from './utils/collectionUtils.js';
52

6-
const ERROR_MESSAGE_RULENAME_FORMAT = 'IPA exceptions must have a valid key with xgen-IPA- prefix.';
7-
const ERROR_MESSAGE_REASON_FORMAT = 'IPA exceptions must have a non-empty reason that starts with uppercase and ends with a full stop.';
8-
const RULE_NAME_PREFIX = 'xgen-IPA-';
3+
const ERROR_MESSAGE_RULENAME_FORMAT = 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.';
4+
const ERROR_MESSAGE_REASON_FORMAT =
5+
'IPA exceptions must have a non-empty reason that starts with uppercase and ends with a full stop.';
6+
const RULE_NAME_PATTERN = /^xgen-IPA-\d{3}-[a-z-]+$/;
97

108
// Note: This rule does not allow exceptions
119
export default (input, _, { path, rule }) => {
@@ -15,7 +13,7 @@ export default (input, _, { path, rule }) => {
1513
};
1614

1715
function isRuleNameValid(ruleName) {
18-
return ruleName.startsWith(RULE_NAME_PREFIX);
16+
return RULE_NAME_PATTERN.test(ruleName);
1917
}
2018

2119
function isReasonFormatValid(reason) {

0 commit comments

Comments
 (0)