@accordproject/concerto-linter-default-ruleset
Version:
Default ruleset for the Accord Project Concerto Linter
40 lines • 1.65 kB
JavaScript
;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkLengthValidator = void 0;
/**
* Checks if a String object has a length validator.
*
* @param {unknown} targetVal The AST node to check, expected to be a StringProperty or StringScalar object.
* @returns {IFunctionResult[] | void} An array of results indicating declarations that lack a length validator.
* @throws {Error} If the input is not a valid object.
*/
const checkLengthValidator = (targetVal) => {
// Validate that targetVal is a non-null object
if (targetVal === null || typeof targetVal !== 'object') {
throw new Error('Input must be a valid String AST object.');
}
const stringObject = targetVal;
const results = [];
// Check for missing length validator
if (!stringObject.lengthValidator) {
results.push({
message: `String '${stringObject.name}' must have a length validator.`,
});
}
return results;
};
exports.checkLengthValidator = checkLengthValidator;
//# sourceMappingURL=check-length-validator.js.map