chore: add rule for min length property and reworked assertionsFn (#1029)

This commit is contained in:
Yevhen Smoliy
2023-03-30 15:08:59 +03:00
committed by GitHub
parent db5430515e
commit bdf0e7d8c2
18 changed files with 794 additions and 257 deletions

View File

@@ -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,
},
];
},
},
};