Skip to content

Commit

Permalink
Add lint rules to ensure every key under prs is stage and each key tha
Browse files Browse the repository at this point in the history
t is there is a valid URL for a PR on emberjs/rfcs
  • Loading branch information
kategengler committed Sep 1, 2022
1 parent 7c3c7ce commit 0df230b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 5 deletions.
46 changes: 41 additions & 5 deletions lib/frontmatter-linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,50 @@ module.exports = class FrontmatterLinter {
prs: {
type: 'object',
required: true,
conform(value) {
let keys = Object.keys(value);
return keys.every((key) => stages.includes(key));
},
messages: {
conform: `must only include keys for RFC Stages: ${stages.join(', ')}`,
},
properties: {
accepted: {
required: true,
allowEmpty: false,
conform(url) {
let regex = /https:\/\/github.com\/emberjs\/rfcs\/pull\/\d+(\/|$)$/;
let cli = /https:\/\/github.com\/ember-cli\/rfcs\/pull\/\d+(\/|$)$/;
return regex.test(url) || cli.test(url);
},
conform: rfcUrlConform,
messages: {
conform:
'must be the URL for the original pull request on emberjs/rfcs, for example: https://github.com/emberjs/rfcs/pull/123',
},
},
'ready-for-release': {
required: false,
allowEmpty: true,
conform: rfcUrlConform,
messages: {
conform:
'must be the URL for the advancement pull request on emberjs/rfcs, for example: https://github.com/emberjs/rfcs/pull/123',
},
},
released: {
required: false,
allowEmpty: true,
conform: rfcUrlConform,
messages: {
conform:
'must be the URL for the advancement pull request on emberjs/rfcs, for example: https://github.com/emberjs/rfcs/pull/123',
},
},
recommended: {
required: false,
allowEmpty: true,
conform: rfcUrlConform,
messages: {
conform:
'must be the URL for the advancement pull request on emberjs/rfcs, for example: https://github.com/emberjs/rfcs/pull/123',
},
},
},
},
'release-date': {
Expand Down Expand Up @@ -132,3 +162,9 @@ function formatErrors(errors) {
return `${e.property} ${e.message}`;
});
}

function rfcUrlConform(url) {
let regex = /https:\/\/github.com\/emberjs\/rfcs\/pull\/\d+(\/|$)$/;
let cli = /https:\/\/github.com\/ember-cli\/rfcs\/pull\/\d+(\/|$)$/;
return regex.test(url) || cli.test(url);
}
48 changes: 48 additions & 0 deletions test/frontmatter-linter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ prs:
accepted: https://github.com/emberjs/rfcs/pull/123/files
---`;

const multiplePrsKeysMetadata = `---
stage: recommended
start-date: 2020-01-01
release-date: 2020-04-02
release-versions:
ember-source: v1.1.1
ember-data: v0.0.3
teams:
- framework
prs:
accepted: https://github.com/emberjs/rfcs/pull/123/
ready-for-release: https://example.com/emberjs/rfcs/pull/456/
released: https://github.com/emberjs/ember.js/pull/789/
recommended: https://raw.github.com/emberjs/rfcs/987
---`;

const extraPrsKeysMetadata = `---
stage: recommended
start-date: 2020-01-01
release-date: 2020-04-02
release-versions:
ember-source: v1.1.1
ember-data: v0.0.3
teams:
- framework
prs:
accepted: https://github.com/emberjs/rfcs/pull/123/
edition: https://github.com/emberjs/rfcs/pull/456/
---`;

const cliUrlForRFCMetadataMarkdown = `---
stage: recommended
start-date: 2020-01-01
Expand Down Expand Up @@ -153,6 +183,24 @@ describe('FrontmatterLinter', function () {
]);
});

it('reports errors for each incorrect key under prs', function () {
let results = linter.lint(multiplePrsKeysMetadata);

expect(results.messages).to.deep.eql([
'prs.ready-for-release must be the URL for the advancement pull request on emberjs/rfcs, for example: https://github.com/emberjs/rfcs/pull/123',
'prs.released must be the URL for the advancement pull request on emberjs/rfcs, for example: https://github.com/emberjs/rfcs/pull/123',
'prs.recommended must be the URL for the advancement pull request on emberjs/rfcs, for example: https://github.com/emberjs/rfcs/pull/123',
]);
});

it('reports errors for extraneous keys under prs', function () {
let results = linter.lint(extraPrsKeysMetadata);

expect(results.messages).to.deep.eql([
'prs must only include keys for RFC Stages: proposed, exploring, accepted, ready-for-release, released, recommended',
]);
});

it('reports NO errors for completed metadata', function () {
let results = linter.lint(completedMetadataMarkdown);
expect(results.messages).to.be.empty;
Expand Down

0 comments on commit 0df230b

Please sign in to comment.