gscan 4.11.1 → 4.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,7 +73,7 @@ function classifyNode(sexpr, options = {knownHelpers: [], knownHelpersOnly: fals
73
73
  // An eligible helper is one that does not have a complex path, i.e. `this.foo`, `../foo` etc.
74
74
  if (isEligible && !isHelper) {
75
75
  let name = sexpr.path.parts[0];
76
- if (options.knownHelpers[name]) {
76
+ if (options.knownHelpers.includes(name)) {
77
77
  isHelper = true;
78
78
  } else if (options.knownHelpersOnly) {
79
79
  isEligible = false;
@@ -1,12 +1,12 @@
1
1
  const Rule = require('./base');
2
- const {getNodeName} = require('../helpers');
2
+ const {getPartialName} = require('../helpers');
3
3
 
4
4
  module.exports = class NoUnknownPartials extends Rule {
5
5
  _checkForUnknownPartials(node) {
6
6
  if (node.name) {
7
7
  if (!this.isValidPartialReference(node)) {
8
8
  this.log({
9
- message: `The partial ${getNodeName(node)} could not be found`,
9
+ message: `The partial ${getPartialName(node)} could not be found`,
10
10
  line: node.loc && node.loc.start.line,
11
11
  column: node.loc && node.loc.start.column,
12
12
  source: this.sourceForNode(node)
@@ -13,10 +13,28 @@ const checkKoenigCssClasses = function checkKoenigCssClasses(theme, options) {
13
13
  // Following the introduction of card assets, we disable certain rules
14
14
  // when it's enabled by the theme.
15
15
  const packageJson = getPackageJSON(theme);
16
- const cardAssetsEnabled = packageJson && packageJson.config && packageJson.config.card_assets === true;
16
+ const cardAssetsEnabled = packageJson
17
+ && packageJson.config
18
+ && packageJson.config.card_assets === true;
19
+ const enabledCards = packageJson
20
+ && packageJson.config
21
+ && packageJson.config.card_assets
22
+ && Array.isArray(packageJson.config.card_assets.include)
23
+ && packageJson.config.card_assets.include;
24
+ const disabledCards = !enabledCards // include takes priority over exclude
25
+ && packageJson
26
+ && packageJson.config
27
+ && packageJson.config.card_assets
28
+ && Array.isArray(packageJson.config.card_assets.exclude)
29
+ && packageJson.config.card_assets.exclude;
17
30
 
18
31
  ruleSet = _.pickBy(ruleSet.rules, function (rule, ruleCode) {
19
- if (ruleCode.match(ruleRegex) && (!cardAssetsEnabled || !rule.cardAsset)) {
32
+ if (rule.cardAsset && (cardAssetsEnabled
33
+ || (enabledCards && enabledCards.includes(rule.cardAsset))
34
+ || (disabledCards && !disabledCards.includes(rule.cardAsset)))) {
35
+ return; // skip rule
36
+ }
37
+ if (ruleCode.match(ruleRegex)) {
20
38
  return rule;
21
39
  }
22
40
  });
@@ -10,6 +10,19 @@ const previousKnownHelpers = previousSpec.knownHelpers;
10
10
  const previousTemplates = previousSpec.templates;
11
11
  const previousRules = previousSpec.rules;
12
12
 
13
+ function cssCardRule(cardName, className) {
14
+ return {
15
+ level: 'warning',
16
+ rule: `The <code>.${className}</code> CSS class is required to appear styled in your theme`,
17
+ details: oneLineTrim`The <code>.${className}</code> CSS class is required otherwise wide images will appear unstyled.
18
+ Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/" target=_blank>here</a>.`,
19
+ regex: new RegExp(`\\.${className}`, 'g'),
20
+ className: `.${className}`,
21
+ css: true,
22
+ cardAsset: cardName
23
+ };
24
+ }
25
+
13
26
  // assign new or overwrite existing knownHelpers, templates, or rules here:
14
27
  let knownHelpers = ['match'];
15
28
  let templates = [];
@@ -171,7 +184,19 @@ let rules = {
171
184
  level: 'error',
172
185
  rule: 'A custom theme setting defined in <code>package.json</code> hasn\'t been used in any theme file.',
173
186
  details: oneLineTrim`Custom theme settings defined in <code>package.json</code> must be used at least once in the theme templates.`
174
- }
187
+ },
188
+ 'GS050-CSS-KGCO': cssCardRule('callout', 'kg-card-callout'),
189
+ 'GS050-CSS-KGCOE': cssCardRule('callout', 'kg-card-callout-emoji'),
190
+ 'GS050-CSS-KGCOT': cssCardRule('callout', 'kg-card-callout-text'),
191
+ 'GS050-CSS-KGCOBGGY': cssCardRule('callout', 'kg-card-callout-background-grey'),
192
+ 'GS050-CSS-KGCOBGW': cssCardRule('callout', 'kg-card-callout-background-white'),
193
+ 'GS050-CSS-KGCOBGB': cssCardRule('callout', 'kg-card-callout-background-blue'),
194
+ 'GS050-CSS-KGCOBGGN': cssCardRule('callout', 'kg-card-callout-background-green'),
195
+ 'GS050-CSS-KGCOBGY': cssCardRule('callout', 'kg-card-callout-background-yellow'),
196
+ 'GS050-CSS-KGCOBGR': cssCardRule('callout', 'kg-card-callout-background-red'),
197
+ 'GS050-CSS-KGCOBGPK': cssCardRule('callout', 'kg-card-callout-background-pink'),
198
+ 'GS050-CSS-KGCOBGPE': cssCardRule('callout', 'kg-card-callout-background-purple'),
199
+ 'GS050-CSS-KGCOBGA': cssCardRule('callout', 'kg-card-callout-background-accent')
175
200
  };
176
201
 
177
202
  knownHelpers = _.union(previousKnownHelpers, knownHelpers);
package/lib/specs/v2.js CHANGED
@@ -10,6 +10,15 @@ const previousKnownHelpers = previousSpec.knownHelpers;
10
10
  const previousTemplates = previousSpec.templates;
11
11
  const previousRules = previousSpec.rules;
12
12
 
13
+ function requiredClassRule(strings) {
14
+ return `The <code>.${strings[0]}</code> CSS class is required to appear styled in your theme`;
15
+ }
16
+
17
+ function requiredClassDetails(strings) {
18
+ return oneLineTrim`The <code>.${strings[0]}</code> CSS class is required otherwise wide images will appear unstyled.
19
+ Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/" target=_blank>here</a>.`;
20
+ }
21
+
13
22
  // assign new or overwrite existing knownHelpers, templates, or rules here:
14
23
  let knownHelpers = ['link', 'link_class', 'concat'];
15
24
  let templates = [];
@@ -446,153 +455,136 @@ let rules = {
446
455
  },
447
456
  'GS050-CSS-KGWW': {
448
457
  level: 'error',
449
- rule: 'The <code>.kg-width-wide</code> CSS class is required to appear styled in your theme',
450
- details: oneLineTrim`The <code>.kg-width-wide</code> CSS class is required otherwise wide images will appear unstyled.
451
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#image-size-implementations" target=_blank>here</a>.`,
458
+ rule: requiredClassRule`kg-width-wide`,
459
+ details: requiredClassDetails`kg-width-wide`,
452
460
  regex: /\.kg-width-wide/g,
453
461
  className: '.kg-width-wide',
454
- css: true,
455
- cardAsset: true
462
+ css: true
456
463
  },
457
464
  'GS050-CSS-KGWF': {
458
465
  level: 'error',
459
- rule: 'The <code>.kg-width-full</code> CSS class is required to appear styled in your theme',
460
- details: oneLineTrim`The <code>.kg-width-full</code> CSS class is required otherwise full width images will appear unstyled.
461
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#image-size-implementations" target=_blank>here</a>.`,
466
+ rule: requiredClassRule`kg-width-full`,
467
+ details: requiredClassDetails`kg-width-full`,
462
468
  regex: /\.kg-width-full/g,
463
469
  className: '.kg-width-full',
464
- css: true,
465
- cardAsset: true
470
+ css: true
466
471
  },
467
472
  'GS050-CSS-KGGC': {
468
473
  level: 'error',
469
- rule: 'The <code>.kg-gallery-container</code> CSS class is required to appear styled in your theme',
470
- details: oneLineTrim`The <code>.kg-gallery-container</code> CSS class is required otherwise galleries will appear unstyled.
471
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#gallery-card" target=_blank>here</a>.`,
474
+ rule: requiredClassRule`kg-gallery-container`,
475
+ details: requiredClassDetails``,
472
476
  regex: /\.kg-gallery-container/g,
473
477
  className: '.kg-gallery-container',
474
478
  css: true,
475
- cardAsset: true
479
+ cardAsset: 'gallery'
476
480
  },
477
481
  'GS050-CSS-KGGR': {
478
482
  level: 'error',
479
- rule: 'The <code>.kg-gallery-row</code> CSS class is required to appear styled in your theme',
480
- details: oneLineTrim`The <code>.kg-gallery-row</code> CSS class is required otherwise gallery rows will appear unstyled.
481
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#gallery-card" target=_blank>here</a>.`,
483
+ rule: requiredClassRule`kg-gallery-row`,
484
+ details: requiredClassDetails`kg-gallery-row`,
482
485
  regex: /\.kg-gallery-row/g,
483
486
  className: '.kg-gallery-row',
484
487
  css: true,
485
- cardAsset: true
488
+ cardAsset: 'gallery'
486
489
  },
487
490
  'GS050-CSS-KGGI': {
488
491
  level: 'error',
489
- rule: 'The <code>.kg-gallery-image</code> CSS class is required to appear styled in your theme',
490
- details: oneLineTrim`The <code>.kg-gallery-image</code> CSS class is required otherwise gallery images will appear unstyled.
491
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#gallery-card" target=_blank>here</a>.`,
492
+ rule: requiredClassRule`kg-gallery-image`,
493
+ details: requiredClassDetails`kg-gallery-image`,
492
494
  regex: /\.kg-gallery-image/g,
493
495
  className: '.kg-gallery-image',
494
496
  css: true,
495
- cardAsset: true
497
+ cardAsset: 'gallery'
496
498
  },
497
499
  'GS050-CSS-KGBM': {
498
500
  level: 'error',
499
- rule: 'The <code>.kg-bookmark-card</code> CSS class is required to appear styled in your theme',
500
- details: oneLineTrim`The <code>.kg-bookmark-card</code> CSS class is required otherwise the bookmark card will appear unstyled.
501
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
501
+ rule: requiredClassRule`kg-bookmark-card`,
502
+ details: requiredClassDetails`kg-bookmark-card`,
502
503
  regex: /\.kg-bookmark-card/g,
503
504
  className: '.kg-bookmark-card',
504
505
  css: true,
505
- cardAsset: true
506
+ cardAsset: 'bookmark'
506
507
  },
507
508
  'GS050-CSS-KGBMCO': {
508
509
  level: 'error',
509
- rule: 'The <code>.kg-bookmark-container</code> CSS class is required to appear styled in your theme',
510
- details: oneLineTrim`The <code>.kg-bookmark-card</code> CSS class is required otherwise the bookmark card will appear unstyled.
511
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
510
+ rule: requiredClassRule`kg-bookmark-container`,
511
+ details: requiredClassDetails`kg-bookmark-container`,
512
512
  regex: /\.kg-bookmark-container/g,
513
513
  className: '.kg-bookmark-container',
514
514
  css: true,
515
- cardAsset: true
515
+ cardAsset: 'bookmark'
516
516
  },
517
517
  'GS050-CSS-KGBMCON': {
518
518
  level: 'error',
519
- rule: 'The <code>.kg-bookmark-content</code> CSS class is required to appear styled in your theme',
520
- details: oneLineTrim`The <code>.kg-bookmark-content</code> CSS class is required otherwise the bookmark card main content will appear unstyled.
521
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
519
+ rule: requiredClassRule`kg-bookmark-content`,
520
+ details: requiredClassDetails`kg-bookmark-content`,
522
521
  regex: /\.kg-bookmark-content/g,
523
522
  className: '.kg-bookmark-content',
524
523
  css: true,
525
- cardAsset: true
524
+ cardAsset: 'bookmark'
526
525
  },
527
526
  'GS050-CSS-KGBMTI': {
528
527
  level: 'error',
529
- rule: 'The <code>.kg-bookmark-title</code> CSS class is required to appear styled in your theme',
530
- details: oneLineTrim`The <code>.kg-bookmark-title</code> CSS class is required otherwise the bookmark card title will appear unstyled.
531
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
528
+ rule: requiredClassRule`kg-bookmark-title`,
529
+ details: requiredClassDetails`kg-bookmark-title`,
532
530
  regex: /\.kg-bookmark-title/g,
533
531
  className: '.kg-bookmark-title',
534
532
  css: true,
535
- cardAsset: true
533
+ cardAsset: 'bookmark'
536
534
  },
537
535
  'GS050-CSS-KGBMDE': {
538
536
  level: 'error',
539
- rule: 'The <code>.kg-bookmark-description</code> CSS class is required to appear styled in your theme',
540
- details: oneLineTrim`The <code>.kg-bookmark-description</code> CSS class is required otherwise the bookmark card description will appear unstyled.
541
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
537
+ rule: requiredClassRule`kg-bookmark-description`,
538
+ details: requiredClassDetails`kg-bookmark-description`,
542
539
  regex: /\.kg-bookmark-description/g,
543
540
  className: '.kg-bookmark-description',
544
541
  css: true,
545
- cardAsset: true
542
+ cardAsset: 'bookmark'
546
543
  },
547
544
  'GS050-CSS-KGBMME': {
548
545
  level: 'error',
549
- rule: 'The <code>.kg-bookmark-metadata</code> CSS class is required to appear styled in your theme',
550
- details: oneLineTrim`The <code>.kg-bookmark-metadata</code> CSS class is required otherwise the bookmark card meta details will appear unstyled.
551
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
546
+ rule: requiredClassRule`kg-bookmark-metadata`,
547
+ details: requiredClassDetails`kg-bookmark-metadata`,
552
548
  regex: /\.kg-bookmark-metadata/g,
553
549
  className: '.kg-bookmark-metadata',
554
550
  css: true,
555
- cardAsset: true
551
+ cardAsset: 'bookmark'
556
552
  },
557
553
  'GS050-CSS-KGBMIC': {
558
554
  level: 'error',
559
- rule: 'The <code>.kg-bookmark-icon</code> CSS class is required to appear styled in your theme',
560
- details: oneLineTrim`The <code>.kg-bookmark-icon</code> CSS class is required otherwise the bookmark card author icon will appear unstyled.
561
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
555
+ rule: requiredClassRule`kg-bookmark-icon`,
556
+ details: requiredClassDetails`kg-bookmark-icon`,
562
557
  regex: /\.kg-bookmark-icon/g,
563
558
  className: '.kg-bookmark-icon',
564
559
  css: true,
565
- cardAsset: true
560
+ cardAsset: 'bookmark'
566
561
  },
567
562
  'GS050-CSS-KGBMAU': {
568
563
  level: 'error',
569
- rule: 'The <code>.kg-bookmark-author</code> CSS class is required to appear styled in your theme',
570
- details: oneLineTrim`The <code>.kg-bookmark-author</code> CSS class is required otherwise the bookmark card author name will appear unstyled.
571
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
564
+ rule: requiredClassRule`kg-bookmark-author`,
565
+ details: requiredClassDetails`kg-bookmark-author`,
572
566
  regex: /\.kg-bookmark-author/g,
573
567
  className: '.kg-bookmark-author',
574
568
  css: true,
575
- cardAsset: true
569
+ cardAsset: 'bookmark'
576
570
  },
577
571
  'GS050-CSS-KGBMPU': {
578
572
  level: 'error',
579
- rule: 'The <code>.kg-bookmark-publisher</code> CSS class is required to appear styled in your theme',
580
- details: oneLineTrim`The <code>.kg-bookmark-publisher</code> CSS class is required otherwise the bookmark card publisher name will appear unstyled.
581
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
573
+ rule: requiredClassRule`kg-bookmark-publisher`,
574
+ details: requiredClassDetails``,
582
575
  regex: /\.kg-bookmark-publisher/g,
583
576
  className: '.kg-bookmark-publisher',
584
577
  css: true,
585
- cardAsset: true
578
+ cardAsset: 'bookmark'
586
579
  },
587
580
  'GS050-CSS-KGBMTH': {
588
581
  level: 'error',
589
- rule: 'The <code>.kg-bookmark-thumbnail</code> CSS class is required to appear styled in your theme',
590
- details: oneLineTrim`The <code>.kg-bookmark-thumbnail</code> CSS class is required otherwise the bookmark card thumbnail image will appear unstyled.
591
- Find out more about required theme changes for the Koenig editor <a href="${docsBaseUrl}editor/#bookmark-card" target=_blank>here</a>.`,
582
+ rule: requiredClassRule`kg-bookmark-thumbnail`,
583
+ details: requiredClassDetails``,
592
584
  regex: /\.kg-bookmark-thumbnail/g,
593
585
  className: '.kg-bookmark-thumbnail',
594
586
  css: true,
595
- cardAsset: true
587
+ cardAsset: 'bookmark'
596
588
  },
597
589
  // Updated v1 rules
598
590
  'GS001-DEPR-AC': {
@@ -1,6 +1,17 @@
1
+ /**
2
+ * Copy of Ghost defaults for https://github.com/TryGhost/Ghost/blob/e25f1df0ae551c447da0d319bae06eadf9665444/core/frontend/services/theme-engine/config/defaults.json
3
+ */
4
+ const defaultConfig = {
5
+ posts_per_page: 5,
6
+ card_assets: {
7
+ exclude: ['bookmark', 'gallery']
8
+ }
9
+ };
10
+
1
11
  /**
2
12
  * Extracts the package.json JSON content. Note that this function never throws,
3
13
  * even when there is a JSON parsing error.
14
+ * This function uses the default `config` property to match Ghost implementation.
4
15
  * @param {Object} theme The theme to extract package.json from.
5
16
  * @returns {Object} The content of the package.json file, or `null` if
6
17
  * something happened (no file, JSON parsing error...).
@@ -9,12 +20,21 @@ function getJSON(theme) {
9
20
  let packageJSON = theme.files.find(item => item.file === 'package.json');
10
21
  if (packageJSON && packageJSON.content) {
11
22
  try {
12
- return JSON.parse(packageJSON.content);
23
+ const json = JSON.parse(packageJSON.content);
24
+
25
+ // Use the default .config and allow it to be overwritten
26
+ const content = Object.assign({}, json, {
27
+ config: Object.assign({}, defaultConfig, json.config)
28
+ });
29
+
30
+ return content;
13
31
  } catch (e) {
14
32
  // Do nothing here
15
33
  }
16
34
  }
17
- return null;
35
+ return {
36
+ config: defaultConfig
37
+ };
18
38
  }
19
39
 
20
40
  module.exports = getJSON;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gscan",
3
- "version": "4.11.1",
3
+ "version": "4.13.2",
4
4
  "description": "Scans Ghost themes looking for errors, deprecations, features and compatibility",
5
5
  "keywords": [
6
6
  "ghost",