Skip to content

Commit

Permalink
馃拕 Added new check for {{@site.lang}} helper use
Browse files Browse the repository at this point in the history
refs https://github.com/TryGhost/Team/issues/509

- The 'lang' property is deprecated with the release of Ghost 4.0 and will be removed completely in Ghost 5.0
- The warning message inspiration taken from a similar deprecation used in GS001-DEPR-SGH (https://github.com/TryGhost/gscan/blob/6a67cfa820a1299a4e0213a7b1fac8d18fd2c937/lib/specs/v2.js#L410-L418)
  • Loading branch information
naz committed Mar 4, 2021
1 parent 6a67cfa commit b0f80be
Show file tree
Hide file tree
Showing 6 changed files with 31 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 @@ -79,6 +79,15 @@ let rules = {
Find more information about the updated <code>{{price}}</code> helper <a href="${docsBaseUrl}members/#the-price-helper" target=_blank>here</a>.`,
helper: '{{[#].currency_symbol}}',
regex: /currency_symbol/g
},
'GS001-DEPR-SITE-LANG': {
level: 'warning',
rule: 'The <code>{{@site.lang}}</code> helper should be replaced with <code>{{@site.locale}}</code>',

This comment has been minimized.

Copy link
@naz

naz Mar 4, 2021

Author Contributor

@matthanley would appreciate a copy check here. The copy used was very much a copy paste from this existing rule -

gscan/lib/specs/v2.js

Lines 410 to 418 in 6a67cfa

'GS001-DEPR-SGH': {
level: 'error',
rule: 'Replace <code>{{@site.ghost_head}}</code> with <code>{{ghost_head}}</code>',
details: oneLineTrim`The usage of <code>{{@site.ghost_head}}</code> is deprecated and should be replaced with <code>{{ghost_head}}</code>.<br>
The <code>{{@site.ghost_head}}</code> property will therefore no longer be used and should be removed from the theme.
Find more information about the <code>{{ghost_head}}</code> property <a href="${docsBaseUrl}helpers/ghost_head_foot/" target=_blank>here</a>.`,
regex: /{{\s*?@site\.ghost_head\s*?}}/g,
helper: '{{@site.ghost_head}}'
},

Thanks!

This comment has been minimized.

Copy link
@matthanley

matthanley Mar 4, 2021

Contributor

LGTM!

details: oneLineTrim`Please replace <code>{{@site.lang}}</code> helper with <code>{{@site.locale}}</code>.<br>
The <code>{{@site.lang}}</code> helper will be removed in next version of Ghost and should not be used.
Find more information about the <code>@site</code> property <a href="${docsBaseUrl}helpers/site/" target=_blank>here</a>.`,
regex: /@site\.lang/g,
helper: '{{@site.lang}}'
}
};

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

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

// {{@site.lang}} helper usage warning
output.results.fail['GS001-DEPR-SITE-LANG'].should.be.a.ValidFailObject();
output.results.fail['GS001-DEPR-SITE-LANG'].failures.length.should.eql(1);

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

Expand Down Expand Up @@ -1958,7 +1963,8 @@ describe('001 Deprecations', function () {
'GS001-DEPR-SPL',
'GS001-DEPR-LANG',
'GS001-DEPR-EACH',
'GS001-DEPR-CURR-SYM'
'GS001-DEPR-CURR-SYM',
'GS001-DEPR-SITE-LANG'
);

// css class .kg-card-markdown
Expand Down Expand Up @@ -2150,6 +2156,10 @@ describe('001 Deprecations', function () {
output.results.fail['GS001-DEPR-CURR-SYM'].should.be.a.ValidFailObject();
output.results.fail['GS001-DEPR-CURR-SYM'].failures.length.should.eql(2);

// {{@site.lang}}
output.results.fail['GS001-DEPR-SITE-LANG'].should.be.a.ValidFailObject();
output.results.fail['GS001-DEPR-SITE-LANG'].failures.length.should.eql(1);

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

done();
Expand All @@ -2161,7 +2171,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(94);
output.results.pass.should.be.an.Array().with.lengthOf(95);

done();
}).catch(done);
Expand Down Expand Up @@ -2215,7 +2225,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(60);
output.results.pass.should.be.an.Array().with.lengthOf(61);

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(104);
theme.results.pass.should.be.an.Array().with.lengthOf(105);
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(104);
theme.results.pass.should.be.an.Array().with.lengthOf(105);
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
@@ -1,3 +1,5 @@
{{@site.lang}}

{{#author}}
{{location}}
{{/author}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ @site.lang }}
{{post.image}}
{{#if @blog.cover}}
{{@blog.cover}}
Expand Down
4 changes: 3 additions & 1 deletion test/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ 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(8);
theme.results.warning.all.length.should.eql(9);

theme.results.error.byFiles['assets/my.css'].length.should.eql(3);
theme.results.error.byFiles['default.hbs'].length.should.eql(17);
theme.results.error.byFiles['post.hbs'].length.should.eql(54);
theme.results.error.byFiles['partials/mypartial.hbs'].length.should.eql(5);
theme.results.error.byFiles['index.hbs'].length.should.eql(9);

theme.results.warning.byFiles['index.hbs'].length.should.eql(1);

done();
}).catch(done);
});
Expand Down

0 comments on commit b0f80be

Please sign in to comment.