mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-09 12:47:48 +00:00
chore: add rule for min length property and reworked assertionsFn (#1029)
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
module.exports = {
|
||||
id: 'local',
|
||||
assertions: {
|
||||
checkWordsStarts: (value, opts, location) => {
|
||||
checkWordsStarts: (value, opts, ctx) => {
|
||||
const regexp = new RegExp(`^${opts.words.join('|')}`);
|
||||
if (regexp.test(value)) {
|
||||
return [];
|
||||
}
|
||||
return [{ message: `Should start with one of ${opts.words.join(', ')}`, location }];
|
||||
return [
|
||||
{
|
||||
message: `Should start with one of ${opts.words.join(', ')}`,
|
||||
location: ctx.baseLocation,
|
||||
},
|
||||
];
|
||||
},
|
||||
checkWordsCount: (value, opts, location) => {
|
||||
checkWordsCount: (value, opts, ctx) => {
|
||||
const words = value.split(' ');
|
||||
if (words.length >= opts.min) {
|
||||
return [];
|
||||
}
|
||||
return [{ message: `Should have at least ${opts.min} words`, location }];
|
||||
return [
|
||||
{
|
||||
message: `Should have at least ${opts.min} words`,
|
||||
location: ctx.baseLocation,
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user