@bigbinary/eslint-plugin-neeto 1.7.5 → 1.7.6

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.
Files changed (2) hide show
  1. package/dist/index.js +112 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -330,7 +330,7 @@
330
330
  }
331
331
 
332
332
  var name = "@bigbinary/eslint-plugin-neeto";
333
- var version = "1.7.4";
333
+ var version = "1.7.5";
334
334
  var main = "dist/index.js";
335
335
  var license = "UNLICENSED";
336
336
  var scripts = {
@@ -726,8 +726,23 @@
726
726
  var helpUrlConstantNamingConvention = function helpUrlConstantNamingConvention(filename) {
727
727
  return "All exported constants in ".concat(filename, " must follow the HELP_..._URL naming convention.");
728
728
  };
729
+ var baseUrlShouldBeInStandardFormat = function baseUrlShouldBeInStandardFormat(filename) {
730
+ return "All exported base URLS in ".concat(filename, " must be in the standard format help.neeto<product>.com.");
731
+ };
729
732
  var helpUrlInvalidType = function helpUrlInvalidType(filename) {
730
- return "Help URL constant must be a template literal string or assigned from another help URL constant. Objects and other types are not allowed in ".concat(filename, ".");
733
+ return "Help URL constant must be a template literal string, assigned from another help URL constant or a help base URL. Objects and other types are not allowed in ".concat(filename, ".");
734
+ };
735
+ var helpUrlOtherNeetoProductConstantNamingConvention = function helpUrlOtherNeetoProductConstantNamingConvention(_ref2) {
736
+ var filename = _ref2.filename,
737
+ constantName = _ref2.constantName,
738
+ suggestedConstantName = _ref2.suggestedConstantName;
739
+ return "All constants that export help URLs for other neeto products in ".concat(filename, " must follow the HELP_NEETO..._BASE_URL naming convention. Replace '").concat(constantName, "' with '").concat(suggestedConstantName, "'.");
740
+ };
741
+ var helpUrlOtherNeetoProductConstantShouldMatchHelpUrl = function helpUrlOtherNeetoProductConstantShouldMatchHelpUrl(_ref3) {
742
+ var filename = _ref3.filename,
743
+ constantName = _ref3.constantName,
744
+ suggestedConstantName = _ref3.suggestedConstantName;
745
+ return "All constants that export help URLs for other neeto products in ".concat(filename, " must match the help URL. Replace '").concat(constantName, "' with '").concat(suggestedConstantName, "'.");
731
746
  };
732
747
  var danglingHelpUrlConstant = function danglingHelpUrlConstant(constName, filename) {
733
748
  return "Help URL constant '".concat(constName, "' should be defined in '").concat(filename, "'.");
@@ -10592,26 +10607,37 @@
10592
10607
  return HELP_URL_CONSTANT_PATTERN.test(_name2);
10593
10608
  }
10594
10609
  };
10610
+ var VALID_HELP_URL_BASE_PATTERN = {
10611
+ type: TYPES.LITERAL,
10612
+ value: function value(_value) {
10613
+ return typeof _value === "string" && HELP_URL_BASE_REGEX.test(_value);
10614
+ }
10615
+ };
10595
10616
  var HELP_URLS_FILENAME = "helpUrls.js";
10596
10617
  var HELP_URL_CONSTANT_PATTERN = /^HELP_.*_URL$/;
10597
10618
  var HELP_DOCS_BASE_URL_CONSTANT_NAME = "HELP_DOCS_BASE_URL";
10598
10619
  var ARTICLE_LINK_REGEX = /\/articles\//;
10599
10620
  // Regex matches help.neeto<subdomain>.com
10600
- var HELP_URL_BASE_REGEX = /help\.neeto[a-z]+\.com/;
10621
+ var HELP_URL_BASE_REGEX = /help\.(neeto[a-z]+)\.com/;
10601
10622
  // Regex for the old/incorrect format: neeto<product>help.neetokb.com
10602
10623
  var OLD_HELP_URL_BASE_REGEX = /neeto[a-z]+help\.neetokb\.com/;
10624
+ // Regex matches HELP_NEETO..._BASE_URL
10625
+ var HELP_URL_OTHER_NEETO_PRODUCT_CONSTANT_REGEX = /^HELP_NEETO.*_BASE_URL$/;
10626
+ var HELP_URL_OTHER_NEETO_PRODUCT_CONSTANT_NAME_TEMPLATE = function HELP_URL_OTHER_NEETO_PRODUCT_CONSTANT_NAME_TEMPLATE(neetoProductName) {
10627
+ return "HELP_".concat(neetoProductName, "_BASE_URL");
10628
+ };
10603
10629
  var BASE_URL_DECLARATOR_PATTERN = {
10604
10630
  id: {
10605
10631
  name: HELP_DOCS_BASE_URL_CONSTANT_NAME
10606
10632
  },
10607
10633
  init: {
10608
10634
  type: TYPES.LITERAL,
10609
- value: function value(_value) {
10610
- return typeof _value === "string";
10635
+ value: function value(_value2) {
10636
+ return typeof _value2 === "string";
10611
10637
  }
10612
10638
  }
10613
10639
  };
10614
- var VALID_HELP_URL_INIT_PATTERN = matchesAny([VALID_TEMPLATE_LITERAL_INIT_PATTERN, VALID_IDENTIFIER_INIT_PATTERN]);
10640
+ var VALID_HELP_URL_INIT_PATTERN = matchesAny([VALID_TEMPLATE_LITERAL_INIT_PATTERN, VALID_IDENTIFIER_INIT_PATTERN, VALID_HELP_URL_BASE_PATTERN]);
10615
10641
  var DANGLING_HELP_URL_DECLARATOR_PATTERN = {
10616
10642
  type: TYPES.VARIABLE_DECLARATOR,
10617
10643
  id: {
@@ -10625,6 +10651,19 @@
10625
10651
  }
10626
10652
  };
10627
10653
 
10654
+ var getNeetoProductNameFromHelpUrl = function getNeetoProductNameFromHelpUrl(helpUrl) {
10655
+ var match = helpUrl.match(HELP_URL_BASE_REGEX);
10656
+ return match ? match[1].toUpperCase() : null;
10657
+ };
10658
+ var getSuggestedHelpUrlOtherNeetoProductConstantName = function getSuggestedHelpUrlOtherNeetoProductConstantName(helpUrl) {
10659
+ var neetoProductName = getNeetoProductNameFromHelpUrl(helpUrl);
10660
+ return HELP_URL_OTHER_NEETO_PRODUCT_CONSTANT_NAME_TEMPLATE(neetoProductName);
10661
+ };
10662
+ var checkIfConstantNameMatchesHelpUrl = function checkIfConstantNameMatchesHelpUrl(constantName, helpUrl) {
10663
+ var neetoProductName = getNeetoProductNameFromHelpUrl(helpUrl);
10664
+ return constantName === HELP_URL_OTHER_NEETO_PRODUCT_CONSTANT_NAME_TEMPLATE(neetoProductName);
10665
+ };
10666
+
10628
10667
  function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike) { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
10629
10668
  function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
10630
10669
  function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
@@ -10661,9 +10700,68 @@
10661
10700
  });
10662
10701
  return false;
10663
10702
  }
10703
+ if (!neetoCist.matches(VALID_HELP_URL_BASE_PATTERN, declarator.init)) {
10704
+ context.report({
10705
+ node: declarator,
10706
+ message: baseUrlShouldBeInStandardFormat(HELP_URLS_FILENAME)
10707
+ });
10708
+ return false;
10709
+ }
10664
10710
  return true;
10665
10711
  };
10666
10712
 
10713
+ /**
10714
+ * Validates a base help URL constant declaration for other neeto products inside helpUrls.js.
10715
+ * e.g., `export const HELP_NEETOCHAT_BASE_URL = "https://help.neetochat.com";`
10716
+ */
10717
+ var validateOtherNeetoProductConstant = function validateOtherNeetoProductConstant(context, declarator) {
10718
+ var constantName = declarator.id.name;
10719
+ var init = declarator.init;
10720
+
10721
+ // Check 1: Checks that the constant name follows the naming convention (HELP_NEETO..._BASE_URL)
10722
+ if (!HELP_URL_OTHER_NEETO_PRODUCT_CONSTANT_REGEX.test(constantName)) {
10723
+ var suggestedConstantName = getSuggestedHelpUrlOtherNeetoProductConstantName(init.value);
10724
+ context.report({
10725
+ node: declarator,
10726
+ message: helpUrlOtherNeetoProductConstantNamingConvention({
10727
+ filename: HELP_URLS_FILENAME,
10728
+ constantName: constantName,
10729
+ suggestedConstantName: suggestedConstantName
10730
+ }),
10731
+ fix: function fix(fixer) {
10732
+ return fixer.replaceText(declarator.id, suggestedConstantName);
10733
+ }
10734
+ });
10735
+ return;
10736
+ }
10737
+
10738
+ //Check 2: If the constant name matches the help URL, check that the help URL is in the correct format.
10739
+ if (OLD_HELP_URL_BASE_REGEX.test(init.value)) {
10740
+ context.report({
10741
+ node: declarator,
10742
+ message: HELP_URL_INCORRECT_FORMAT
10743
+ });
10744
+ return;
10745
+ }
10746
+
10747
+ // Check 3: Checks that the constant name matches the help URL
10748
+ if (!checkIfConstantNameMatchesHelpUrl(constantName, init.value)) {
10749
+ var _suggestedConstantName = getSuggestedHelpUrlOtherNeetoProductConstantName(init.value);
10750
+ context.report({
10751
+ node: declarator,
10752
+ message: helpUrlOtherNeetoProductConstantShouldMatchHelpUrl({
10753
+ filename: HELP_URLS_FILENAME,
10754
+ constantName: constantName,
10755
+ suggestedConstantName: _suggestedConstantName
10756
+ }),
10757
+ fix: function fix(fixer) {
10758
+ return fixer.replaceText(declarator.id, _suggestedConstantName);
10759
+ }
10760
+ });
10761
+ return;
10762
+ }
10763
+ };
10764
+
10667
10765
  /**
10668
10766
  * Validates a single help URL constant declaration inside helpUrls.js.
10669
10767
  * e.g., `export const HELP_API_KEYS_URL = \`\${HELP_DOCS_BASE_URL}/p/a-d7e4285a\`;`
@@ -10681,7 +10779,7 @@
10681
10779
  }
10682
10780
  var init = declarator.init;
10683
10781
 
10684
- // Check 2: Must be a valid template literal or identifier assignment.
10782
+ // Check 2: Must be a valid template literal, identifier assignment or help URL base.
10685
10783
  if (!neetoCist.matches(VALID_HELP_URL_INIT_PATTERN, init)) {
10686
10784
  context.report({
10687
10785
  node: declarator,
@@ -10698,8 +10796,14 @@
10698
10796
  node: declarator,
10699
10797
  message: HELP_URL_SHOULD_USE_PERMALINK
10700
10798
  });
10799
+ return;
10701
10800
  }
10702
10801
  }
10802
+
10803
+ //Check 4: If it's a help URL base for other neeto products, validate the constant name.
10804
+ if (init.type === TYPES.LITERAL) {
10805
+ validateOtherNeetoProductConstant(context, declarator);
10806
+ }
10703
10807
  };
10704
10808
 
10705
10809
  /**
@@ -10807,7 +10911,7 @@
10807
10911
  url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/standardize-help-urls.md",
10808
10912
  description: "Ensure help URLs are standardized and defined in helpUrls.js"
10809
10913
  },
10810
- fixable: null
10914
+ fixable: "code"
10811
10915
  },
10812
10916
  create: function create(context) {
10813
10917
  var filename = context.getFilename();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {