mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-09 12:47:48 +00:00
feat: support for custom assertions functions (#837)
* feat: support for custom assertions functions * Comment * Prettier fix * Add test and doc * Prettier fix * Update .redocly.yaml * Update packages/core/src/config/types.ts Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> * fix: show 'referenced from' in the lint error message * Add Prettier changes * Add e2e and change format * Fixes after cross review * Fixes after cross review * Fixes after cross review * Change custom assertion syntax * Update test * add unit test * Add assertion to test * Update packages/core/src/config/config-resolvers.ts Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> * Update packages/core/src/config/types.ts Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> * Update packages/core/src/rules/common/assertions/asserts.ts Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> * Update packages/core/src/types/redocly-yaml.ts Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> * Update packages/core/src/config/config-resolvers.ts Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> * Remove console.lo * Fix types * fix prettier * fix prettier * change assertion return type * Group assertions message * Change assertions logic * Update docs/rules/assertions.md Co-authored-by: Adam Altman <adam@redoc.ly> * Update docs/rules/assertions.md Co-authored-by: Adam Altman <adam@redoc.ly> * Update documentation * Update test * fix comments * Fix comments * Fix assertId * fix tests * Fix tests * Documentation update * Update doc * Fix comments * Update snapshots * Update code * update assets messages Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> Co-authored-by: Anton Kozachuk <antonkozachuk@Antons-MacBook-Pro.local> Co-authored-by: Adam Altman <adam@redoc.ly>
This commit is contained in:
19
__tests__/lint/assertions-custom-function-options/plugin.js
Normal file
19
__tests__/lint/assertions-custom-function-options/plugin.js
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
id: 'local',
|
||||
assertions: {
|
||||
checkWordsStarts: (value, opts, location) => {
|
||||
const regexp = new RegExp(`^${opts.words.join('|')}`);
|
||||
if (regexp.test(value)) {
|
||||
return [];
|
||||
}
|
||||
return [{ message: `Should start with one of ${opts.words.join(', ')}`, location }];
|
||||
},
|
||||
checkWordsCount: (value, opts, location) => {
|
||||
const words = value.split(' ');
|
||||
if (words.length >= opts.min) {
|
||||
return [];
|
||||
}
|
||||
return [{ message: `Should have at least ${opts.min} words`, location }];
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user