@bigbinary/eslint-plugin-neeto 1.7.4 → 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 +130 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -68,6 +68,9 @@
68
68
  exportnameCase: "camelCase"
69
69
  },
70
70
  configs: [{
71
+ filenameCase: "anycase",
72
+ includes: "/translations/**"
73
+ }, {
71
74
  filenameCase: "camelCase",
72
75
  exportnameCase: "CONSTANT_CASE",
73
76
  includes: ["/**/constants.{js,jsx}", "/**/constants/**"]
@@ -209,6 +212,9 @@
209
212
  exportnameCase: "camelCase"
210
213
  },
211
214
  configs: [{
215
+ filenameCase: "anycase",
216
+ includes: "/translations/**"
217
+ }, {
212
218
  filenameCase: "camelCase",
213
219
  exportnameCase: "CONSTANT_CASE",
214
220
  includes: ["/**/constants.{js,jsx}", "/**/constants/**"]
@@ -324,7 +330,7 @@
324
330
  }
325
331
 
326
332
  var name = "@bigbinary/eslint-plugin-neeto";
327
- var version = "1.7.3";
333
+ var version = "1.7.5";
328
334
  var main = "dist/index.js";
329
335
  var license = "UNLICENSED";
330
336
  var scripts = {
@@ -720,8 +726,23 @@
720
726
  var helpUrlConstantNamingConvention = function helpUrlConstantNamingConvention(filename) {
721
727
  return "All exported constants in ".concat(filename, " must follow the HELP_..._URL naming convention.");
722
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
+ };
723
732
  var helpUrlInvalidType = function helpUrlInvalidType(filename) {
724
- 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, "'.");
725
746
  };
726
747
  var danglingHelpUrlConstant = function danglingHelpUrlConstant(constName, filename) {
727
748
  return "Help URL constant '".concat(constName, "' should be defined in '").concat(filename, "'.");
@@ -5471,9 +5492,18 @@
5471
5492
 
5472
5493
  var minimatch$1 = minimatch_1;
5473
5494
 
5495
+ var _CASE_REGEXES;
5474
5496
  var EXPORT_PATTERN = {
5475
5497
  type: ramda.includes(ramda.__, [TYPES.EXPORT_DEFAULT_DECLARATION, TYPES.EXPORT_NAMED_DECLARATION])
5476
5498
  };
5499
+ var CASE_STYLES = {
5500
+ camel: "camelCase",
5501
+ constant: "CONSTANT_CASE",
5502
+ pascal: "PascalCase",
5503
+ snake: "snake_case",
5504
+ any: "anycase"
5505
+ };
5506
+ var CASE_REGEXES = (_CASE_REGEXES = {}, _defineProperty(_CASE_REGEXES, CASE_STYLES.camel, CAMEL_CASE_REGEX), _defineProperty(_CASE_REGEXES, CASE_STYLES.constant, CONSTANT_CASE_REGEX), _defineProperty(_CASE_REGEXES, CASE_STYLES.pascal, PASCAL_CASE_REGEX), _defineProperty(_CASE_REGEXES, CASE_STYLES.snake, SNAKE_CASE_REGEX), _CASE_REGEXES);
5477
5507
 
5478
5508
  var isInsideBaseDirectory = function isInsideBaseDirectory(context) {
5479
5509
  return context.getFilename().startsWith(context.options[0].basePath);
@@ -5483,15 +5513,9 @@
5483
5513
  return Array.isArray(item) ? item : new Array(item);
5484
5514
  };
5485
5515
  var isCaseMatching = function isCaseMatching(text, caseStyle) {
5486
- var _regexes$caseStyle$te, _regexes$caseStyle;
5487
- if (!text) return true;
5488
- var regexes = {
5489
- camelCase: CAMEL_CASE_REGEX,
5490
- CONSTANT_CASE: CONSTANT_CASE_REGEX,
5491
- PascalCase: PASCAL_CASE_REGEX,
5492
- snake_case: SNAKE_CASE_REGEX
5493
- };
5494
- return (_regexes$caseStyle$te = (_regexes$caseStyle = regexes[caseStyle]) === null || _regexes$caseStyle === void 0 ? void 0 : _regexes$caseStyle.test(text)) !== null && _regexes$caseStyle$te !== void 0 ? _regexes$caseStyle$te : true;
5516
+ var _CASE_REGEXES$caseSty, _CASE_REGEXES$caseSty2;
5517
+ if (!text || caseStyle === CASE_STYLES.any) return true;
5518
+ return (_CASE_REGEXES$caseSty = (_CASE_REGEXES$caseSty2 = CASE_REGEXES[caseStyle]) === null || _CASE_REGEXES$caseSty2 === void 0 ? void 0 : _CASE_REGEXES$caseSty2.test(text)) !== null && _CASE_REGEXES$caseSty !== void 0 ? _CASE_REGEXES$caseSty : true;
5495
5519
  };
5496
5520
  var findMatchedConfig = function findMatchedConfig(context, configs) {
5497
5521
  var fullFilePath = context.getFilename();
@@ -10583,26 +10607,37 @@
10583
10607
  return HELP_URL_CONSTANT_PATTERN.test(_name2);
10584
10608
  }
10585
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
+ };
10586
10616
  var HELP_URLS_FILENAME = "helpUrls.js";
10587
10617
  var HELP_URL_CONSTANT_PATTERN = /^HELP_.*_URL$/;
10588
10618
  var HELP_DOCS_BASE_URL_CONSTANT_NAME = "HELP_DOCS_BASE_URL";
10589
10619
  var ARTICLE_LINK_REGEX = /\/articles\//;
10590
10620
  // Regex matches help.neeto<subdomain>.com
10591
- var HELP_URL_BASE_REGEX = /help\.neeto[a-z]+\.com/;
10621
+ var HELP_URL_BASE_REGEX = /help\.(neeto[a-z]+)\.com/;
10592
10622
  // Regex for the old/incorrect format: neeto<product>help.neetokb.com
10593
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
+ };
10594
10629
  var BASE_URL_DECLARATOR_PATTERN = {
10595
10630
  id: {
10596
10631
  name: HELP_DOCS_BASE_URL_CONSTANT_NAME
10597
10632
  },
10598
10633
  init: {
10599
10634
  type: TYPES.LITERAL,
10600
- value: function value(_value) {
10601
- return typeof _value === "string";
10635
+ value: function value(_value2) {
10636
+ return typeof _value2 === "string";
10602
10637
  }
10603
10638
  }
10604
10639
  };
10605
- 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]);
10606
10641
  var DANGLING_HELP_URL_DECLARATOR_PATTERN = {
10607
10642
  type: TYPES.VARIABLE_DECLARATOR,
10608
10643
  id: {
@@ -10616,6 +10651,19 @@
10616
10651
  }
10617
10652
  };
10618
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
+
10619
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; } } }; }
10620
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); }
10621
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; }
@@ -10652,9 +10700,68 @@
10652
10700
  });
10653
10701
  return false;
10654
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
+ }
10655
10710
  return true;
10656
10711
  };
10657
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
+
10658
10765
  /**
10659
10766
  * Validates a single help URL constant declaration inside helpUrls.js.
10660
10767
  * e.g., `export const HELP_API_KEYS_URL = \`\${HELP_DOCS_BASE_URL}/p/a-d7e4285a\`;`
@@ -10672,7 +10779,7 @@
10672
10779
  }
10673
10780
  var init = declarator.init;
10674
10781
 
10675
- // 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.
10676
10783
  if (!neetoCist.matches(VALID_HELP_URL_INIT_PATTERN, init)) {
10677
10784
  context.report({
10678
10785
  node: declarator,
@@ -10689,8 +10796,14 @@
10689
10796
  node: declarator,
10690
10797
  message: HELP_URL_SHOULD_USE_PERMALINK
10691
10798
  });
10799
+ return;
10692
10800
  }
10693
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
+ }
10694
10807
  };
10695
10808
 
10696
10809
  /**
@@ -10798,7 +10911,7 @@
10798
10911
  url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/standardize-help-urls.md",
10799
10912
  description: "Ensure help URLs are standardized and defined in helpUrls.js"
10800
10913
  },
10801
- fixable: null
10914
+ fixable: "code"
10802
10915
  },
10803
10916
  create: function create(context) {
10804
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.4",
3
+ "version": "1.7.6",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {