@bigbinary/eslint-plugin-neeto 1.1.22 → 1.1.23

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.
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"]
@@ -27145,6 +27240,7 @@
27145
27240
 
27146
27241
  var index = {
27147
27242
  rules: {
27243
+ "use-classnames-for-dynamic-classes": useClassnamesForDynamicClasses,
27148
27244
  "use-use-mutation-with-invalidation-hook": useUseMutationWithInvalidationHook,
27149
27245
  "no-withT-for-smart-components": noWithTForSmartComponents,
27150
27246
  "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.23",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {