@bigbinary/eslint-plugin-neeto 1.1.22 → 1.1.24

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 (3) hide show
  1. package/README.md +2 -0
  2. package/dist/index.js +106 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -46,6 +46,8 @@ module.exports = {
46
46
 
47
47
  ## Exported rules
48
48
 
49
+
50
+ - [use-classnames-for-dynamic-classes](./docs/src/rules/use-classnames-for-dynamic-classes.md)
49
51
  - [use-use-mutation-with-invalidation-hook](./docs/src/rules/use-use-mutation-with-invalidation-hook.md)
50
52
  - [no-withT-for-smart-components](./docs/src/rules/no-withT-for-smart-components.md)
51
53
  - [no-large-functions-inside-jsx](./docs/src/rules/no-large-functions-inside-jsx.md)
package/dist/index.js CHANGED
@@ -42,6 +42,7 @@
42
42
  var commonResolve$2 = loadJS$2("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
43
43
  var resolve$2 = ramda.mergeDeepLeft(projectResolve$2, commonResolve$2);
44
44
  var rules = {
45
+ "@bigbinary/neeto/use-classnames-for-dynamic-classes": "error",
45
46
  "@bigbinary/neeto/use-use-mutation-with-invalidation-hook": "error",
46
47
  "@bigbinary/neeto/no-withT-for-smart-components": "error",
47
48
  "@bigbinary/neeto/no-large-functions-inside-jsx": "error",
@@ -551,6 +552,7 @@
551
552
  var USE_STANDARD_DATE_TIME_FORMATS = 'Use "dateFormat/timeFormat" from "@bigbinary/neeto-commons-frontend/utils" instead. Refer: https://github.com/bigbinary/neeto-commons-frontend/blob/main/docs/utils/README.md#dateformattimeformat';
552
553
  var MOVE_SPREAD_ATTRIBUTES_TO_TOP = "Move spread attribute to top";
553
554
  var USE_USE_MUTATION_WITH_INVALIDATION = "Use useMutationWithInvalidation from 'neetocommons/react-utils'";
555
+ var USE_CLASSNAMES_PACKAGE = "Use classnames package for dynamic classes";
554
556
 
555
557
  var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
556
558
 
@@ -8414,6 +8416,99 @@
8414
8416
  }
8415
8417
  };
8416
8418
 
8419
+ // className={isPending ? "opacity-30" : "opacity-0"}
8420
+ // className={isPending && "opacity-30"}
8421
+ var CONDITIONAL_CLASSNAMES_PATTERN = {
8422
+ name: {
8423
+ type: TYPES.JSX_IDENTIFIER,
8424
+ name: "className"
8425
+ },
8426
+ value: {
8427
+ type: TYPES.JSX_EXPRESSION_CONTAINER,
8428
+ expression: {
8429
+ type: ramda.includes(ramda.__, [TYPES.LOGICAL_EXPRESSION, TYPES.CONDITIONAL_EXPRESSION, TYPES.TEMPLATE_LITERAL])
8430
+ }
8431
+ }
8432
+ };
8433
+
8434
+ // import classnames from "classnames";
8435
+ var CLASSNAMES_IMPORT_PATTERN = {
8436
+ type: TYPES.IMPORT_DECLARATION,
8437
+ source: {
8438
+ type: TYPES.LITERAL,
8439
+ value: "classnames"
8440
+ },
8441
+ specifiers: pure.existsBy({
8442
+ type: TYPES.IMPORT_DEFAULT_SPECIFIER,
8443
+ local: {
8444
+ type: TYPES.IDENTIFIER,
8445
+ name: "classnames"
8446
+ }
8447
+ })
8448
+ };
8449
+
8450
+ // ${isPending && "opacity-30"}
8451
+ // ${isPending ? "opacity-30" : "opacity-0"}
8452
+ var CONDITIONAL_EXPRESSION_PATTERN = {
8453
+ expressions: [{
8454
+ type: ramda.includes(ramda.__, [TYPES.LOGICAL_EXPRESSION, TYPES.CONDITIONAL_EXPRESSION])
8455
+ }]
8456
+ };
8457
+
8458
+ var getFixString = function getFixString(context, expressionNode) {
8459
+ if (expressionNode.type === TYPES.LOGICAL_EXPRESSION) {
8460
+ var left = context.getSourceCode().getText(expressionNode.left);
8461
+ var right = context.getSourceCode().getText(expressionNode.right);
8462
+ return "classnames({ ".concat(right, ": ").concat(left, " })");
8463
+ }
8464
+ var test = context.getSourceCode().getText(expressionNode.test);
8465
+ var consequent = context.getSourceCode().getText(expressionNode.consequent);
8466
+ var alternate = context.getSourceCode().getText(expressionNode.alternate);
8467
+ return "classnames({".concat(consequent, ": ").concat(test, ", ").concat(alternate, ": !(").concat(test, ")})");
8468
+ };
8469
+
8470
+ var useClassnamesForDynamicClasses = {
8471
+ meta: {
8472
+ type: "error",
8473
+ docs: {
8474
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-classnames-for-dynamic-classes.md",
8475
+ description: "Enforce use of classnames for dynamic classes"
8476
+ },
8477
+ fixable: "code"
8478
+ },
8479
+ create: function create(context) {
8480
+ return {
8481
+ JSXAttribute: function JSXAttribute(node) {
8482
+ if (!pure.matches(CONDITIONAL_CLASSNAMES_PATTERN, node)) return;
8483
+ var expressionNode = node.value.expression;
8484
+ if (expressionNode.type === TYPES.TEMPLATE_LITERAL) {
8485
+ if (pure.matches(CONDITIONAL_EXPRESSION_PATTERN, expressionNode)) {
8486
+ context.report({
8487
+ node: node,
8488
+ message: USE_CLASSNAMES_PACKAGE
8489
+ });
8490
+ }
8491
+ return;
8492
+ }
8493
+ context.report({
8494
+ node: node,
8495
+ message: USE_CLASSNAMES_PACKAGE,
8496
+ fix: function fix(fixer) {
8497
+ var fixString = getFixString(context, expressionNode);
8498
+ var fixerArray = [fixer.replaceText(expressionNode, fixString)];
8499
+ var importExists = pure.existsBy(CLASSNAMES_IMPORT_PATTERN, getAllImports(node));
8500
+ if (!importExists) {
8501
+ var addImport = fixer.insertTextBefore(context.getAncestors()[0], 'import classnames from "classnames";\n');
8502
+ fixerArray.push(addImport);
8503
+ }
8504
+ return fixerArray;
8505
+ }
8506
+ });
8507
+ }
8508
+ };
8509
+ }
8510
+ };
8511
+
8417
8512
  var IMPORT_SOURCES = {
8418
8513
  "neeto-commons-frontend/constants": ["neetocommons/constants", "@bigbinary/neeto-commons-frontend/constants"],
8419
8514
  "neeto-team-members-frontend": ["neetoteam", "@bigbinary/neeto-team-members-frontend"]
@@ -26478,8 +26573,11 @@
26478
26573
  if (!onSuccess.value.body) return;
26479
26574
  var importExists = pure.existsBy(USE_MUTATION_WITH_INVALIDATION_IMPORT_PATTERN, getAllImports(node));
26480
26575
  if (onSuccess.value.body.type === TYPES.CALL_EXPRESSION) {
26576
+ var _params$arguments;
26481
26577
  var params = onSuccess.value.body;
26482
- if (!pure.matches(SINGLE_INVALIDATION_PATTERN, params)) return;
26578
+ if (!pure.matches(SINGLE_INVALIDATION_PATTERN, params) || ((_params$arguments = params.arguments) === null || _params$arguments === void 0 ? void 0 : _params$arguments.length) > 1) {
26579
+ return;
26580
+ }
26483
26581
  var variables = getVariables(context, params);
26484
26582
  if (pure.isPresent(variables)) {
26485
26583
  reportError(context, node);
@@ -26508,7 +26606,12 @@
26508
26606
  } else if (onSuccess.value.body.type === TYPES.BLOCK_STATEMENT) {
26509
26607
  var _params = onSuccess.value.body.body;
26510
26608
  var invalidations = pure._filterBy(INVALIDATION_PATTERN, _params);
26511
- if (pure.isNotPresent(invalidations)) return;
26609
+ if (pure.isNotPresent(invalidations) || invalidations.find(function (item) {
26610
+ var _item$expression$argu;
26611
+ return ((_item$expression$argu = item.expression.arguments) === null || _item$expression$argu === void 0 ? void 0 : _item$expression$argu.length) > 1;
26612
+ })) {
26613
+ return;
26614
+ }
26512
26615
  var otherOptions = pure._removeBy(INVALIDATION_PATTERN, _params);
26513
26616
  var queryClientInOtherOptions = otherOptions === null || otherOptions === void 0 ? void 0 : otherOptions.find(function (item) {
26514
26617
  return context.getSourceCode().getText(item).includes("queryClient");
@@ -27145,6 +27248,7 @@
27145
27248
 
27146
27249
  var index = {
27147
27250
  rules: {
27251
+ "use-classnames-for-dynamic-classes": useClassnamesForDynamicClasses,
27148
27252
  "use-use-mutation-with-invalidation-hook": useUseMutationWithInvalidationHook,
27149
27253
  "no-withT-for-smart-components": noWithTForSmartComponents,
27150
27254
  "no-large-functions-inside-jsx": noLargeFunctionsInsideJsx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {