Skip to content

Commit 1217f4e

Browse files
address the comments
1 parent fc990a0 commit 1217f4e

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ testRule('xgen-IPA-126-tag-names-should-use-title-case', [
128128
tags: [
129129
{ name: 'Api V1' },
130130
{ name: 'Version 2 Resources' },
131-
{ name: 'Push-Based Log Export' },
132-
{ name: 'AWS Clusters DNS' },
131+
{ name: 'Push-Based Log Export' }, //valid
132+
{ name: 'AWS Clusters DNS' }, // valid
133133
{ name: 'Encryption at Rest using Customer Key Management' },
134134
],
135135
},
@@ -146,18 +146,6 @@ testRule('xgen-IPA-126-tag-names-should-use-title-case', [
146146
path: ['tags', '1'],
147147
severity: DiagnosticSeverity.Warning,
148148
},
149-
{
150-
code: 'xgen-IPA-126-tag-names-should-use-title-case',
151-
message: 'Tag name should use Title Case, found: "Push-Based Log Export".',
152-
path: ['tags', '2'],
153-
severity: DiagnosticSeverity.Warning,
154-
},
155-
{
156-
code: 'xgen-IPA-126-tag-names-should-use-title-case',
157-
message: 'Tag name should use Title Case, found: "AWS Clusters DNS".',
158-
path: ['tags', '3'],
159-
severity: DiagnosticSeverity.Warning,
160-
},
161149
{
162150
code: 'xgen-IPA-126-tag-names-should-use-title-case',
163151
message: 'Tag name should use Title Case, found: "Encryption at Rest using Customer Key Management".',

tools/spectral/ipa/rulesets/IPA-126.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ rules:
1717
given: $.tags[?(@.name && @.name.length > 0)]
1818
then:
1919
function: 'IPA126TagNamesShouldUseTitleCase'
20+
functionOptions:
21+
ignoreList:
22+
- 'AWS'
23+
- 'DNS'
24+
- 'API'
25+
- 'IP'
26+
- 'MongoDB'
27+
- 'LDAP'
28+
- 'GCP'

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { hasException } from './utils/exceptions.js';
22
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
3-
import { casing } from '@stoplight/spectral-functions';
43

54
const RULE_NAME = 'xgen-IPA-126-tag-names-should-use-title-case';
65

7-
export default (input, options, { path }) => {
6+
export default (input, { ignoreList }, { path }) => {
87
const tagName = input.name;
98
if (hasException(input, RULE_NAME)) {
109
collectException(input, RULE_NAME, path);
1110
return;
1211
}
1312

1413
// Check if the tag name uses Title Case
15-
if (casing(tagName, { type: 'pascal', disallowDigits: true, separator: { char: ' ' } })) {
14+
if (!isTitleCase(tagName, ignoreList)) {
1615
return collectAndReturnViolation(path, RULE_NAME, [
1716
{
1817
path,
@@ -24,3 +23,26 @@ export default (input, options, { path }) => {
2423
// Tag name uses Title Case
2524
collectAdoption(path, RULE_NAME);
2625
};
26+
27+
function isTitleCase(str, ignoreList) {
28+
// Split by spaces to check each word/word-group
29+
const words = str.split(' ');
30+
31+
return words.every((wordGroup) => {
32+
// For hyphenated words, check each part
33+
if (wordGroup.includes('-')) {
34+
const hyphenatedParts = wordGroup.split('-');
35+
return hyphenatedParts.every((part) => {
36+
if (part === '') return true; // Skip empty parts
37+
if (ignoreList.includes(part)) return true;
38+
// First character should be uppercase, rest lowercase, all alphabetical
39+
return /^[A-Z][a-z]*$/.test(part);
40+
});
41+
}
42+
43+
// For regular words
44+
if (wordGroup === '') return true;
45+
if (ignoreList.includes(wordGroup)) return true;
46+
return /^[A-Z][a-z]*$/.test(wordGroup);
47+
});
48+
}

0 commit comments

Comments
 (0)