Skip to content

Commit 1797114

Browse files
authored
fix(ibm-use-date-based-format): extend date-based-utils with exceptions (#776)
Signed-off-by: Lídia Tarcza <[email protected]>
1 parent b1764bd commit 1797114

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/ruleset/src/utils/date-based-utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ function isDateBasedName(name) {
6565
/.*timestamp.*/,
6666
];
6767

68-
return dateBasedNamePatterns.some(regex => regex.test(name));
68+
const exceptionNamePatterns = [/.*depends_on$/];
69+
70+
return (
71+
dateBasedNamePatterns.some(regex => regex.test(name)) &&
72+
!exceptionNamePatterns.some(regex => regex.test(name))
73+
);
6974
}
7075

7176
/**

packages/ruleset/test/rules/use-date-based-format.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,34 @@ describe(`Spectral rule: ${ruleId}`, () => {
284284
const results = await testRule(ruleId, rule, testDocument);
285285
expect(results).toHaveLength(0);
286286
});
287+
288+
it("depends_on doesn't yield error", async () => {
289+
const testDocument = makeCopy(rootDocument);
290+
testDocument.components.schemas.Movie.properties.metadata = {
291+
oneOf: [
292+
{
293+
type: 'object',
294+
properties: {
295+
depends_on: {
296+
maxLength: '25',
297+
type: 'string',
298+
},
299+
},
300+
},
301+
{
302+
type: 'object',
303+
properties: {
304+
irrelevant: {
305+
type: 'boolean',
306+
},
307+
},
308+
},
309+
],
310+
};
311+
312+
const results = await testRule(ruleId, rule, testDocument);
313+
expect(results).toHaveLength(0);
314+
});
287315
});
288316

289317
describe('Should yield errors', () => {

0 commit comments

Comments
 (0)