Skip to content

Commit

Permalink
馃拕 Added new check for {{@labs.members}} helper use (#373)
Browse files Browse the repository at this point in the history
refs https://github.com/TryGhost/Team/issues/492

- Ghost 4.0 sets @labs.members flag to always be "true" by default and will remove the property completely (resolving it to `null` coerced as `false` value) starting with next version - Ghost 5.0
  • Loading branch information
naz committed Mar 1, 2021
1 parent 5f419df commit 870a09b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/specs/canary.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ let rules = {
details: oneLineTrim`Please change <code>"ghost-api"</code> in your <code>package.json</code> to higher version. E.g. <code>{"engines": {"ghost-api": "v4"}}</code>.<br>
If <code>"ghost-api"</code> property is left at "v2", it will stop working with next major version upgrade and default to v5.<br>
Check the <a href="${docsBaseUrl}packagejson/" target=_blank><code>package.json</code> documentation</a> for further information.`
},
'GS001-DEPR-LABS-MEMBERS': {
level: 'warning',
rule: 'The <code>{{@labs.members}}</code> helper should not be used.',
details: oneLineTrim`Please remove <code>{{@labs.members}}</code> from the theme.<br>
The <code>{{@labs.members}}</code> helper will always return <code>true</code> in Ghost v4 and will be removed from Ghost v5, at which point it will return <code>null</code> and evaluate to <code>false</code>.
Find more information about the <code>@labs</code> property <a href="${docsBaseUrl}helpers/labs/" target=_blank>here</a>.`,
regex: /@labs\.members/g,
helper: '{{@labs.members}}'
}
};

Expand Down
13 changes: 9 additions & 4 deletions test/001-deprecations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,8 @@ describe('001 Deprecations', function () {
'GS001-DEPR-LANG',
'GS001-DEPR-PAID',
'GS001-DEPR-USER-GET',
'GS001-DEPR-EACH'
'GS001-DEPR-EACH',
'GS001-DEPR-LABS-MEMBERS'
);

// pageUrl
Expand Down Expand Up @@ -1895,6 +1896,10 @@ describe('001 Deprecations', function () {
output.results.fail['GS001-DEPR-EACH'].should.be.a.ValidFailObject();
output.results.fail['GS001-DEPR-EACH'].failures.length.should.eql(1);

// {{@labs.members}} helper usage warning
output.results.fail['GS001-DEPR-LABS-MEMBERS'].should.be.a.ValidFailObject();
output.results.fail['GS001-DEPR-LABS-MEMBERS'].failures.length.should.eql(1);

// there are some single author rules which are not invalid for this theme.
output.results.pass.length.should.eql(17);

Expand Down Expand Up @@ -2140,7 +2145,7 @@ describe('001 Deprecations', function () {
output.results.fail['GS001-DEPR-EACH'].should.be.a.ValidFailObject();
output.results.fail['GS001-DEPR-EACH'].failures.length.should.eql(1);

output.results.pass.should.be.an.Array().with.lengthOf(46);
output.results.pass.should.be.an.Array().with.lengthOf(47);

done();
}).catch(done);
Expand All @@ -2151,7 +2156,7 @@ describe('001 Deprecations', function () {
output.should.be.a.ValidThemeObject();

output.results.fail.should.be.an.Object().which.is.empty();
output.results.pass.should.be.an.Array().with.lengthOf(92);
output.results.pass.should.be.an.Array().with.lengthOf(93);

done();
}).catch(done);
Expand Down Expand Up @@ -2205,7 +2210,7 @@ describe('001 Deprecations', function () {
output.results.fail['GS001-DEPR-AUTH'].should.be.a.ValidFailObject();
output.results.fail['GS001-DEPR-AUTH'].failures.length.should.eql(1);

output.results.pass.should.be.an.Array().with.lengthOf(58);
output.results.pass.should.be.an.Array().with.lengthOf(59);

done();
}).catch(done);
Expand Down
4 changes: 2 additions & 2 deletions test/checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('Checker', function () {
{file: 'README.md', ext: '.md'}
]);

theme.results.pass.should.be.an.Array().with.lengthOf(99);
theme.results.pass.should.be.an.Array().with.lengthOf(100);
theme.results.pass.should.containEql('GS005-TPL-ERR', 'GS030-ASSET-REQ', 'GS030-ASSET-SYM');

theme.results.fail.should.be.an.Object().with.keys(
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('Checker', function () {
{file: 'README.md', ext: '.md'}
]);

theme.results.pass.should.be.an.Array().with.lengthOf(99);
theme.results.pass.should.be.an.Array().with.lengthOf(100);
theme.results.pass.should.containEql('GS005-TPL-ERR', 'GS030-ASSET-REQ', 'GS030-ASSET-SYM');

theme.results.fail.should.be.an.Object().with.keys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

{{cover}}

{{#if @labs.members}}
<h1>Hi Member!</h1>
{{/if}}

{{#get "posts" include="tags, author" fields="author" filter="author:{{author.slug}}+id:-{{id}}"}}
{{#foreach posts}}
{{author}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

{{cover}}

{{#if @labs.members}}
<h1>Hi Member!</h1>
{{/if}}

{{#get "posts" include="tags, author" fields="author" filter="author:{{author.slug}}+id:-{{id}}"}}
{{#foreach posts}}
{{author}}
Expand Down
2 changes: 1 addition & 1 deletion test/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ describe('Format', function () {
theme.results.recommendation.byFiles['package.json'].length.should.eql(1);

theme.results.error.all.length.should.eql(99);
theme.results.warning.all.length.should.eql(7);
theme.results.warning.all.length.should.eql(8);

theme.results.error.byFiles['assets/my.css'].length.should.eql(3);
theme.results.error.byFiles['default.hbs'].length.should.eql(17);
Expand Down

0 comments on commit 870a09b

Please sign in to comment.