|
| 1 | +import testRule from './__helpers__/testRule.js'; |
| 2 | +import { DiagnosticSeverity } from '@stoplight/types'; |
| 3 | + |
| 4 | +testRule('xgen-IPA-126-tag-names-should-use-title-case', [ |
| 5 | + { |
| 6 | + name: 'valid Title Case tag names', |
| 7 | + document: { |
| 8 | + tags: [ |
| 9 | + { name: 'User Management' }, |
| 10 | + { name: 'Resource Groups' }, |
| 11 | + { name: 'Atlas' }, |
| 12 | + { name: 'User Profiles' }, |
| 13 | + { name: 'Api' }, |
| 14 | + { name: 'Users' }, |
| 15 | + { name: 'Resources' }, |
| 16 | + { name: 'Projects' }, |
| 17 | + ], |
| 18 | + }, |
| 19 | + errors: [], |
| 20 | + }, |
| 21 | + { |
| 22 | + name: 'invalid camelCase instead of Title Case', |
| 23 | + document: { |
| 24 | + tags: [{ name: 'userManagement' }], |
| 25 | + }, |
| 26 | + errors: [ |
| 27 | + { |
| 28 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 29 | + message: 'Tag name should use Title Case, found: "userManagement".', |
| 30 | + path: ['tags', '0'], |
| 31 | + severity: DiagnosticSeverity.Warning, |
| 32 | + }, |
| 33 | + ], |
| 34 | + }, |
| 35 | + { |
| 36 | + name: 'invalid kebab-case instead of Title Case', |
| 37 | + document: { |
| 38 | + tags: [{ name: 'user-management' }], |
| 39 | + }, |
| 40 | + errors: [ |
| 41 | + { |
| 42 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 43 | + message: 'Tag name should use Title Case, found: "user-management".', |
| 44 | + path: ['tags', '0'], |
| 45 | + severity: DiagnosticSeverity.Warning, |
| 46 | + }, |
| 47 | + ], |
| 48 | + }, |
| 49 | + { |
| 50 | + name: 'invalid snake_case instead of Title Case', |
| 51 | + document: { |
| 52 | + tags: [{ name: 'user_management' }], |
| 53 | + }, |
| 54 | + errors: [ |
| 55 | + { |
| 56 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 57 | + message: 'Tag name should use Title Case, found: "user_management".', |
| 58 | + path: ['tags', '0'], |
| 59 | + severity: DiagnosticSeverity.Warning, |
| 60 | + }, |
| 61 | + ], |
| 62 | + }, |
| 63 | + { |
| 64 | + name: 'invalid all lowercase instead of Title Case', |
| 65 | + document: { |
| 66 | + tags: [{ name: 'user management' }], |
| 67 | + }, |
| 68 | + errors: [ |
| 69 | + { |
| 70 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 71 | + message: 'Tag name should use Title Case, found: "user management".', |
| 72 | + path: ['tags', '0'], |
| 73 | + severity: DiagnosticSeverity.Warning, |
| 74 | + }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + { |
| 78 | + name: 'invalid ALL UPPERCASE instead of Title Case', |
| 79 | + document: { |
| 80 | + tags: [{ name: 'USER MANAGEMENT' }], |
| 81 | + }, |
| 82 | + errors: [ |
| 83 | + { |
| 84 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 85 | + message: 'Tag name should use Title Case, found: "USER MANAGEMENT".', |
| 86 | + path: ['tags', '0'], |
| 87 | + severity: DiagnosticSeverity.Warning, |
| 88 | + }, |
| 89 | + ], |
| 90 | + }, |
| 91 | + { |
| 92 | + name: 'mixed cases in multiple tags', |
| 93 | + document: { |
| 94 | + tags: [{ name: 'User Management' }, { name: 'resourceGroups' }, { name: 'API ENDPOINTS' }], |
| 95 | + }, |
| 96 | + errors: [ |
| 97 | + { |
| 98 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 99 | + message: 'Tag name should use Title Case, found: "resourceGroups".', |
| 100 | + path: ['tags', '1'], |
| 101 | + severity: DiagnosticSeverity.Warning, |
| 102 | + }, |
| 103 | + { |
| 104 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 105 | + message: 'Tag name should use Title Case, found: "API ENDPOINTS".', |
| 106 | + path: ['tags', '2'], |
| 107 | + severity: DiagnosticSeverity.Warning, |
| 108 | + }, |
| 109 | + ], |
| 110 | + }, |
| 111 | + { |
| 112 | + name: 'valid with exception', |
| 113 | + document: { |
| 114 | + tags: [ |
| 115 | + { |
| 116 | + name: 'legacy_tag', |
| 117 | + 'x-xgen-IPA-exception': { |
| 118 | + 'xgen-IPA-126-tag-names-should-use-title-case': 'Legacy tag that cannot be changed', |
| 119 | + }, |
| 120 | + }, |
| 121 | + ], |
| 122 | + }, |
| 123 | + errors: [], |
| 124 | + }, |
| 125 | + { |
| 126 | + name: 'invalid tag names', |
| 127 | + document: { |
| 128 | + tags: [ |
| 129 | + { name: 'Api V1' }, |
| 130 | + { name: 'Version 2 Resources' }, |
| 131 | + { name: 'Push-Based Log Export' }, |
| 132 | + { name: 'AWS Clusters DNS' }, |
| 133 | + { name: 'Encryption at Rest using Customer Key Management' }, |
| 134 | + ], |
| 135 | + }, |
| 136 | + errors: [ |
| 137 | + { |
| 138 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 139 | + message: 'Tag name should use Title Case, found: "Api V1".', |
| 140 | + path: ['tags', '0'], |
| 141 | + severity: DiagnosticSeverity.Warning, |
| 142 | + }, |
| 143 | + { |
| 144 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 145 | + message: 'Tag name should use Title Case, found: "Version 2 Resources".', |
| 146 | + path: ['tags', '1'], |
| 147 | + severity: DiagnosticSeverity.Warning, |
| 148 | + }, |
| 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 | + }, |
| 161 | + { |
| 162 | + code: 'xgen-IPA-126-tag-names-should-use-title-case', |
| 163 | + message: 'Tag name should use Title Case, found: "Encryption at Rest using Customer Key Management".', |
| 164 | + path: ['tags', '4'], |
| 165 | + severity: DiagnosticSeverity.Warning, |
| 166 | + }, |
| 167 | + ], |
| 168 | + }, |
| 169 | +]); |
0 commit comments