Updated eslint-plugin-ghost & fixed resulting failures

- I recently added a bunch of strict rules to our eslint plugin around returns: ca9af37866
- These mostly are issues that occur whilst writing code, that you spot and fix as you're developing, but they're annoying to notice/find and eslint can be used to flag them quickly
- There are of course, edge cases where you don't need to return from array fns, but this rule also suggests better patterns might be available
- For our excert helper and new assertEvent helper, I've updated the code to use simpler patterns that are easier to read, so as to avoid the warnings
- For our old API I've simply disabled the rule as we're about to delete this code
This commit is contained in:
Hannah Wolfe 2022-02-21 12:18:02 +00:00
parent 2f7456790e
commit 5bf12939e4
No known key found for this signature in database
GPG Key ID: AB586C3B5AE5C037
5 changed files with 44 additions and 27 deletions

View File

@ -12,6 +12,7 @@ const getMetaDataExcerpt = metaData.getMetaDataExcerpt;
module.exports = function excerpt(options) {
let truncateOptions = (options || {}).hash || {};
let excerptText;
if (this.custom_excerpt) {
@ -24,10 +25,12 @@ module.exports = function excerpt(options) {
excerptText = '';
}
truncateOptions = _.pick(truncateOptions, ['words', 'characters']);
_.keys(truncateOptions).map(function (key) {
truncateOptions[key] = parseInt(truncateOptions[key], 10);
});
truncateOptions = _.reduce(truncateOptions, (_truncateOptions, value, key) => {
if (['words', 'characters'].includes(key)) {
_truncateOptions[key] = parseInt(value, 10);
}
return _truncateOptions;
}, {});
if (!_.isEmpty(this.custom_excerpt)) {
truncateOptions.characters = this.custom_excerpt.length;

View File

@ -106,7 +106,8 @@ module.exports = {
before(frame) {
const errors = [];
frame.data.settings.map((setting) => {
// Using eslint disable line here as we are about to drop v2 - no point in fixing
frame.data.settings.map((setting) => { /* eslint-disable-line array-callback-return */
if (setting.group === 'core' && !(frame.options.context && frame.options.context.internal)) {
errors.push(new NoPermissionError({
message: tpl(messages.accessCoreSettingFromExtReq)

View File

@ -191,7 +191,7 @@
"coffeescript": "2.6.1",
"cssnano": "5.0.17",
"eslint": "8.9.0",
"eslint-plugin-ghost": "2.12.0",
"eslint-plugin-ghost": "2.13.0",
"grunt": "1.4.1",
"grunt-bg-shell": "2.3.3",
"grunt-contrib-clean": "2.0.0",

View File

@ -14,11 +14,11 @@ async function assertEvents({eventType, eventName, quantity, asserts}) {
const events = await models[eventType].findAll();
assert.equal(events.models.length, quantity, `Only one ${eventType} should have been added after ${eventName}.`);
const event = events.models[events.models.length - 1].toJSON();
Object.keys(asserts).map((key) => {
const attribute = key;
const value = asserts[key];
for (const attribute of Object.keys(assert)) {
const value = asserts[attribute];
assert.equal(event[attribute], value, `The ${attribute} attribute of ${eventType} should have been ${value}`);
});
}
}
const memberMatcherNoIncludes = {

View File

@ -4281,7 +4281,7 @@ css-select@~1.2.0:
domutils "1.5.1"
nth-check "~1.0.1"
css-tree@^1.0.0-alpha.39, css-tree@^1.1.2, css-tree@^1.1.3:
css-tree@^1.1.2, css-tree@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/css-tree/-/css-tree-1.1.3.tgz#eb4870fb6fd7707327ec95c2ff2ab09b5e8db91d"
integrity sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==
@ -4289,6 +4289,14 @@ css-tree@^1.0.0-alpha.39, css-tree@^1.1.2, css-tree@^1.1.3:
mdn-data "2.0.14"
source-map "^0.6.1"
css-tree@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/css-tree/-/css-tree-2.0.4.tgz#be44314f17e9ac85fe894a5888941782e1123c29"
integrity sha512-b4IS9ZUMtGBiNjzYbcj9JhYbyei99R3ai2CSxlu8GQDnoPA/P+NU85hAm0eKDc/Zp660rpK6tFJQ2OSdacMHVg==
dependencies:
mdn-data "2.0.23"
source-map-js "^1.0.1"
css-what@2.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/css-what/-/css-what-2.1.3.tgz#a6d7604573365fe74686c3f311c56513d88285f2"
@ -5042,13 +5050,13 @@ escodegen@^2.0.0:
optionalDependencies:
source-map "~0.6.1"
eslint-plugin-ember@10.5.8:
version "10.5.8"
resolved "https://registry.yarnpkg.com/eslint-plugin-ember/-/eslint-plugin-ember-10.5.8.tgz#87e004a5ebed88f94008364554daf57df2c9c718"
integrity sha512-d21mJ+F+htgi6HhrjwbOfllJojF4ZWGruW13HkBoGS2SaHqKUyvIH/8j3EjSxlsGFiNfhTEUWkNaUSLJxgbtWg==
eslint-plugin-ember@10.5.9:
version "10.5.9"
resolved "https://registry.yarnpkg.com/eslint-plugin-ember/-/eslint-plugin-ember-10.5.9.tgz#4071ac135c7207c7d4942e9fa75b710214885469"
integrity sha512-kJsdAaKNcfRvZBZ+YZ67pxxUgl+aPLFAnoFJNwTo+BsaptiOCsHUEc4xUKXiInH2BJOC6mg0FQcZKn1a6gwKrA==
dependencies:
"@ember-data/rfc395-data" "^0.0.4"
css-tree "^1.0.0-alpha.39"
css-tree "^2.0.4"
ember-rfc176-data "^0.3.15"
eslint-utils "^3.0.0"
estraverse "^5.2.0"
@ -5074,18 +5082,18 @@ eslint-plugin-filenames@1.3.2:
lodash.snakecase "4.1.1"
lodash.upperfirst "4.3.1"
eslint-plugin-ghost@2.12.0:
version "2.12.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-ghost/-/eslint-plugin-ghost-2.12.0.tgz#108c86be40eae12f8839131e30fa2cb57195a279"
integrity sha512-YyAmG2RVlYkf66/R9IG/UoCl0nvo3HKVleqzs4Ba/YcKK6gnmYgfRrpOt1k9a3klXEQkxSY1BKesEKTCS60KQw==
eslint-plugin-ghost@2.13.0:
version "2.13.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-ghost/-/eslint-plugin-ghost-2.13.0.tgz#1ab0ec7d508b38e33c39e8d4d22ef21632b488cb"
integrity sha512-l0r9NGeGOrjXQtgLdDZjdXuJjyNMOTES4DqzEob5FrQM80bnLjbbRBrBXDt637ZZW9+nPcsCv8x6bDHAf1Ds5w==
dependencies:
"@kapouer/eslint-plugin-no-return-in-loop" "1.0.0"
eslint-plugin-ember "10.5.8"
eslint-plugin-ember "10.5.9"
eslint-plugin-filenames "1.3.2"
eslint-plugin-mocha "7.0.1"
eslint-plugin-node "11.1.0"
eslint-plugin-sort-imports-es6-autofix "0.6.0"
eslint-plugin-unicorn "40.1.0"
eslint-plugin-unicorn "41.0.0"
eslint-plugin-mocha@7.0.1:
version "7.0.1"
@ -5112,10 +5120,10 @@ eslint-plugin-sort-imports-es6-autofix@0.6.0:
resolved "https://registry.yarnpkg.com/eslint-plugin-sort-imports-es6-autofix/-/eslint-plugin-sort-imports-es6-autofix-0.6.0.tgz#b8cd8639d7a54cefce6b17898b102fd5ec31e52b"
integrity sha512-2NVaBGF9NN+727Fyq+jJYihdIeegjXeUUrZED9Q8FVB8MsV3YQEyXG96GVnXqWt0pmn7xfCZOZf3uKnIhBrfeQ==
eslint-plugin-unicorn@40.1.0:
version "40.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-40.1.0.tgz#48975360e39d23df726e4b33e8dd5d650e184832"
integrity sha512-y5doK2DF9Sr5AqKEHbHxjFllJ167nKDRU01HDcWyv4Tnmaoe9iNxMrBnaybZvWZUaE3OC5Unu0lNIevYamloig==
eslint-plugin-unicorn@41.0.0:
version "41.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-41.0.0.tgz#bf0974f8551ab4dd4aaae7d9cf53894040defbbd"
integrity sha512-xoJCaRc1uy5REg9DkVga1BkZV57jJxoqOcrU28QHZB89Lk5LdSqdVyTIt9JQVfHNKaiyJ7X+3iLlIn+VEHWEzA==
dependencies:
"@babel/helper-validator-identifier" "^7.15.7"
ci-info "^3.3.0"
@ -8630,6 +8638,11 @@ mdn-data@2.0.14:
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.14.tgz#7113fc4281917d63ce29b43446f701e68c25ba50"
integrity sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==
mdn-data@2.0.23:
version "2.0.23"
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.23.tgz#dfb6c41e50a0edb808cf340973ab29321b70808e"
integrity sha512-IonVb7pfla2U4zW8rc7XGrtgq11BvYeCxWN8HS+KFBnLDE7XDK9AAMVhRuG6fj9BBsjc69Fqsp6WEActEdNTDQ==
mdurl@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
@ -11371,7 +11384,7 @@ socks@~2.3.2:
ip "1.1.5"
smart-buffer "^4.1.0"
source-map-js@^1.0.2:
source-map-js@^1.0.1, source-map-js@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==