@bigbinary/eslint-plugin-neeto 1.1.7 → 1.1.9

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 +30 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -82,7 +82,8 @@
82
82
  "@bigbinary/neeto/no-globalProps-reassignment": "error",
83
83
  "@bigbinary/neeto/no-missing-localization": ["error", {
84
84
  translationsDir: absolutePath("app/javascript/src/translations"),
85
- languages: ["en"]
85
+ languages: ["en"],
86
+ nanosTranslationDir: [absolutePath("node_modules/@bigbinary/neeto-team-members-frontend/src/translations")]
86
87
  }],
87
88
  "@bigbinary/neeto/no-multiple-components-in-a-file": "error",
88
89
  "@bigbinary/neeto/no-multiple-translation-functions-under-same-parent": "error",
@@ -3934,7 +3935,7 @@
3934
3935
  };
3935
3936
  var NATURAL_LANGUAGE_REGEX = /^(?:(?:[a-z]+\s)+|\s(?:[a-z]+\s)+|[a-z]*(?:\s[a-z]+)+)$/i;
3936
3937
  var EXCLUDED_KEYWORDS_REGEX = /^(.*classnames?|.*class|.*styles?|.*format|viewBox|d|keybinding|rel|sequence)$/i;
3937
- var INCLUDED_KEYWORDS_REGEX = /^(.*label|.*title|placeholder|helpText)$/i;
3938
+ var INCLUDED_KEYWORDS_REGEX = /^(.*label|.*title|placeholder|helpText|message|description)$/i;
3938
3939
  var ONLY_NON_WORD_CHAR_REGEX = /^[\s\n\r\t\W0-9_ ]*(&.*;)*[\s\n\r\t\W0-9_ ]*$/;
3939
3940
 
3940
3941
  var getNodeName = function getNodeName(node) {
@@ -3952,17 +3953,26 @@
3952
3953
  }
3953
3954
  };
3954
3955
  var shouldReport = function shouldReport(node, nodeValue, context) {
3955
- if (typeof nodeValue !== "string") return false;
3956
- var containOnlyNonWordChars = ONLY_NON_WORD_CHAR_REGEX.test(nodeValue);
3957
- if (containOnlyNonWordChars) return false;
3956
+ if (node.type !== TYPES.TEMPLATE_LITERAL) {
3957
+ if (typeof nodeValue !== "string") return false;
3958
+ var containOnlyNonWordChars = ONLY_NON_WORD_CHAR_REGEX.test(nodeValue);
3959
+ if (containOnlyNonWordChars) return false;
3960
+ }
3958
3961
  var isJSXTextType = node.type === TYPES.JSX_TEXT;
3959
3962
  if (isJSXTextType) return true;
3960
3963
  var ancestors = context.getAncestors(node);
3964
+ var isMatchesNaturalLangRegex = NATURAL_LANGUAGE_REGEX.test(nodeValue);
3961
3965
  for (var i = ancestors.length - 1; i > 0; i--) {
3962
3966
  var _parent$init;
3963
3967
  var parent = ancestors[i];
3968
+ var excludedTypes = [TYPES.MEMBER_EXPRESSION, TYPES.BINARY_EXPRESSION];
3969
+ if (excludedTypes.includes(parent.type)) {
3970
+ return false;
3971
+ }
3964
3972
  if (((_parent$init = parent.init) === null || _parent$init === void 0 ? void 0 : _parent$init.type) === TYPES.ARROW_FUNCTION_EXPRESSION) return false;
3965
3973
  if (parent.type === TYPES.CALL_EXPRESSION) {
3974
+ var _parent$callee;
3975
+ if (((_parent$callee = parent.callee) === null || _parent$callee === void 0 ? void 0 : _parent$callee.name) === "t" && isMatchesNaturalLangRegex) return true;
3966
3976
  var isToastrFunc = pure.matches(TOASTR_CALL_EXPRESSION_PATTERN, parent);
3967
3977
  return isToastrFunc;
3968
3978
  }
@@ -3970,11 +3980,10 @@
3970
3980
  if (nodeName) {
3971
3981
  var isInIncludedList = INCLUDED_KEYWORDS_REGEX.test(nodeName);
3972
3982
  if (isInIncludedList) return true;
3973
- var isMatchesNaturalLangRegex = NATURAL_LANGUAGE_REGEX.test(nodeValue);
3974
- if (!isMatchesNaturalLangRegex) return false;
3983
+ var _isMatchesNaturalLangRegex = NATURAL_LANGUAGE_REGEX.test(nodeValue);
3984
+ if (!_isMatchesNaturalLangRegex) return false;
3975
3985
  var isInExcludedList = EXCLUDED_KEYWORDS_REGEX.test(nodeName);
3976
3986
  if (isInExcludedList) return false;
3977
- return true;
3978
3987
  }
3979
3988
  }
3980
3989
  return false;
@@ -4000,7 +4009,7 @@
4000
4009
  Literal: function Literal(node) {
4001
4010
  checkAndReport$3(node, context);
4002
4011
  },
4003
- TemplateElement: function TemplateElement(node) {
4012
+ TemplateLiteral: function TemplateLiteral(node) {
4004
4013
  checkAndReport$3(node, context);
4005
4014
  },
4006
4015
  JSXText: function JSXText(node) {
@@ -4109,6 +4118,7 @@
4109
4118
  function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4110
4119
  function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4111
4120
  var translationFiles = [];
4121
+ var nanosContent = {};
4112
4122
  var previousOptions = null;
4113
4123
  var watcher$1 = null;
4114
4124
  var watchTranslationsDir = function watchTranslationsDir(translationsDirPath) {
@@ -4118,7 +4128,7 @@
4118
4128
  var lng = changedFileName.split(".")[0];
4119
4129
  translationFiles = pure.modifyBy({
4120
4130
  lng: lng
4121
- }, ramda.assoc("content", parseJsonData(path$2.join(translationsDirPath, changedFileName))), translationFiles);
4131
+ }, ramda.assoc("content", _objectSpread$3(_objectSpread$3({}, parseJsonData(path$2.join(translationsDirPath, changedFileName))), nanosContent[lng])), translationFiles);
4122
4132
  });
4123
4133
  };
4124
4134
  var checkAndReport$2 = function checkAndReport(_ref) {
@@ -4173,10 +4183,19 @@
4173
4183
  },
4174
4184
  create: function create(context) {
4175
4185
  if (pure.isNot(previousOptions, context.options[0])) {
4186
+ var nanosTranslationOption = context.options[0].nanosTranslationDir;
4176
4187
  translationFiles = context.options[0].languages.map(function (lng) {
4188
+ nanosContent[lng] = nanosTranslationOption ? nanosTranslationOption.map(function (filePath) {
4189
+ return path$2.join(filePath, "".concat(lng, ".json"));
4190
+ }).reduce(function (mergedObj, filePath) {
4191
+ return _objectSpread$3(_objectSpread$3({}, mergedObj), parseJsonData(filePath));
4192
+ }, {}) : {};
4193
+ var translationsFilePath = path$2.join(context.options[0].translationsDir, "".concat(lng, ".json"));
4194
+ var translationsContent = parseJsonData(translationsFilePath);
4195
+ var combinedContent = _objectSpread$3(_objectSpread$3({}, translationsContent), nanosContent[lng]);
4177
4196
  return {
4178
4197
  lng: lng,
4179
- content: parseJsonData(path$2.join(context.options[0].translationsDir, "".concat(lng, ".json")))
4198
+ content: combinedContent
4180
4199
  };
4181
4200
  });
4182
4201
  previousOptions = context.options[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {