MCPcopy Create free account
hub / github.com/github/awesome-copilot / validateKeywords

Function validateKeywords

eng/external-plugin-validation.mjs:94–134  ·  view source on GitHub ↗
(keywords, prefix, errors, warnings, required)

Source from the content-addressed store, hash-verified

92}
93
94function validateKeywords(keywords, prefix, errors, warnings, required) {
95 if (keywords === undefined) {
96 if (required) {
97 errors.push(`${prefix}: "keywords" is required and must be an array of lowercase tags`);
98 }
99 return;
100 }
101
102 if (!Array.isArray(keywords)) {
103 errors.push(`${prefix}: "keywords" must be an array`);
104 return;
105 }
106
107 if (keywords.length > 10) {
108 errors.push(`${prefix}: "keywords" must contain no more than 10 entries`);
109 }
110
111 for (let i = 0; i < keywords.length; i++) {
112 const keyword = keywords[i];
113 if (!isNonEmptyString(keyword)) {
114 errors.push(`${prefix}: "keywords[${i}]" must be a non-empty string`);
115 continue;
116 }
117
118 if (!/^[a-z0-9-]+$/.test(keyword)) {
119 errors.push(`${prefix}: "keywords[${i}]" must contain only lowercase letters, numbers, and hyphens`);
120 }
121
122 if (keyword.length > 30) {
123 errors.push(`${prefix}: "keywords[${i}]" must be 30 characters or fewer`);
124 }
125 }
126
127 if (keywords.length === 0) {
128 if (required) {
129 errors.push(`${prefix}: "keywords" must contain at least one entry`);
130 } else {
131 warnings.push(`${prefix}: "keywords" is empty; at least one keyword is recommended for discovery`);
132 }
133 }
134}
135
136function validateHttpsUrl(value, fieldName, prefix, errors, options = {}) {
137 if (!isNonEmptyString(value)) {

Callers 1

validateExternalPluginFunction · 0.70

Calls 1

isNonEmptyStringFunction · 0.85

Tested by

no test coverage detected