@bigbinary/eslint-plugin-neeto 1.1.42 → 1.3.0

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 +148 -20
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -46,6 +46,7 @@ module.exports = {
46
46
 
47
47
  ## Exported rules
48
48
 
49
+ - [no-unnecessary-classnames](./docs/src/rules/no-unnecessary-classnames.md)
49
50
  - [no-snake-case-destructuring-for-use-query-params-and-get-query-params](./docs/src/rules/no-snake-case-destructuring-for-use-query-params-and-get-query-params.md)
50
51
  - [no-local-storage](./docs/src/rules/no-local-storage.md)
51
52
  - [no-lowercase-on-translation](./docs/src/rules/no-lowercase-on-translation.md)
@@ -123,6 +124,7 @@ module.exports = {
123
124
  - [move-spread-attributes-to-top-position](./docs/src/rules/move-spread-attributes-to-top-position.md)
124
125
  - [prefer-function-reference.md](./docs/src/rules/prefer-function-reference.md)
125
126
  - [jsx-prefer-guard-clause.md](./docs/src/rules/jsx-prefer-guard-clause.md)
127
+ - [use-show-thumbs-up-toastr.md](./docs/src/rules/use-show-thumbs-up-toastr)
126
128
 
127
129
  ## Other references
128
130
 
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/no-unnecessary-classnames": "error",
45
46
  "@bigbinary/neeto/no-snake-case-destructuring-for-use-query-params-and-get-query-params": "warn",
46
47
  "@bigbinary/neeto/no-local-storage": "error",
47
48
  "@bigbinary/neeto/no-lowercase-on-translation": "warn",
@@ -163,7 +164,8 @@
163
164
  "@bigbinary/neeto/use-common-constants": "warn",
164
165
  "@bigbinary/neeto/move-spread-attributes-to-top-position": "error",
165
166
  "@bigbinary/neeto/prefer-function-reference": "warn",
166
- "@bigbinary/neeto/jsx-prefer-guard-clause": "warn"
167
+ "@bigbinary/neeto/jsx-prefer-guard-clause": "warn",
168
+ "@bigbinary/neeto/use-show-thumbs-up-toastr": "error"
167
169
  };
168
170
 
169
171
  var recommended = {
@@ -438,6 +440,18 @@
438
440
  var NO_OF_LINES_ALLOWED_FOR_MULTIPLE_COMPONENTS_IN_A_FILE = 20;
439
441
  var MAX_LINES_FOR_FUNCTIONS_INSIDE_JSX = 4;
440
442
 
443
+ // import { functionName } from neetocommons/utils;
444
+ var NEETO_COMMONS_UTILS_IMPORT_PATTERN = {
445
+ type: TYPES.IMPORT_DECLARATION,
446
+ source: {
447
+ type: TYPES.LITERAL,
448
+ value: "neetocommons/utils"
449
+ },
450
+ specifiers: [{
451
+ type: TYPES.IMPORT_SPECIFIER
452
+ }]
453
+ };
454
+
441
455
  var ARGUMENT_LIMIT = 3;
442
456
  var API_ACTIONS_ARGUMENT_LIMIT = 2;
443
457
  var FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
@@ -453,10 +467,10 @@
453
467
  return "Do not use the package ".concat(packageName);
454
468
  };
455
469
  var exportedObjectShouldBe = function exportedObjectShouldBe(caseStyle) {
456
- return "Exported object should be in ".concat(caseStyle, ". Refer https://www.youtube.com/watch?v=As9BzWsGJfY");
470
+ return "Exported object should be in ".concat(caseStyle, ". Refer https://youtu.be/uZtRIvo8-ww");
457
471
  };
458
472
  var filenameShouldBe = function filenameShouldBe(caseStyle) {
459
- return "Filename should be in ".concat(caseStyle, ". Refer https://www.youtube.com/watch?v=As9BzWsGJfY");
473
+ return "Filename should be in ".concat(caseStyle, ". Refer https://youtu.be/uZtRIvo8-ww");
460
474
  };
461
475
  var moveToConstantsJs = function moveToConstantsJs(constantName) {
462
476
  return "Move the constant ".concat(constantName, " to a constants.js file.");
@@ -570,6 +584,8 @@
570
584
  var AVOID_SNAKE_CASE_DESTRUCTURING_USEQUERYPARAMS_OR_GETQUERYPARAMS = "Avoid destructuring snake-cased values from getQueryParams or useQueryParams";
571
585
  var PREFER_FUNCTION_REFERENCE = "Prefer passing function reference instead of creating a new function as the parameters and arguments are the same.";
572
586
  var JSX_PREFER_GUARD_CLAUSE = "Prefer adding a guard clause for conditional statements left of JSX statments in the last return statement of the function.";
587
+ var USE_SHOW_THUMBS_UP_TOASTR_FUNCTION = "Use 'showThumbsUpToastr' function from '@bigbinary/neeto-commons-frontend/utils' for displaying thumbs up toast message.";
588
+ var NO_UNNECESSARY_CLASSNAMES = "classnames usage is unnecessary";
573
589
 
574
590
  var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
575
591
 
@@ -2068,7 +2084,7 @@
2068
2084
  }
2069
2085
  };
2070
2086
 
2071
- var OBJECT_EXPRESSION_PATTERN = {
2087
+ var OBJECT_EXPRESSION_PATTERN$1 = {
2072
2088
  type: TYPES.OBJECT_EXPRESSION,
2073
2089
  properties: neetoCist.isNotEmpty
2074
2090
  };
@@ -2090,7 +2106,7 @@
2090
2106
  ObjectExpression: function ObjectExpression(node) {
2091
2107
  var _resolveConfig$sync;
2092
2108
  if (isExcludedFile(EXCLUDED_FILES, context.getFilename())) return;
2093
- if (!neetoCist.matches(OBJECT_EXPRESSION_PATTERN, node)) return;
2109
+ if (!neetoCist.matches(OBJECT_EXPRESSION_PATTERN$1, node)) return;
2094
2110
  var sourceCode = context.getSourceCode();
2095
2111
  var hasComments = neetoCist.isNotEmpty(sourceCode.getCommentsInside(node));
2096
2112
  if (hasComments) return;
@@ -6607,7 +6623,7 @@
6607
6623
  };
6608
6624
 
6609
6625
  var SNAKE_CASE_WITHOUT_SINGLE_WORDS = /^[a-z]+_[a-z0-9_]+$/;
6610
- var PATTERN = {
6626
+ var PATTERN$1 = {
6611
6627
  id: {
6612
6628
  type: "ObjectPattern",
6613
6629
  properties: ramda.any(neetoCist.matches({
@@ -6647,7 +6663,7 @@
6647
6663
  create: function create(context) {
6648
6664
  return {
6649
6665
  VariableDeclarator: function VariableDeclarator(node) {
6650
- if (neetoCist.matches(PATTERN, node)) {
6666
+ if (neetoCist.matches(PATTERN$1, node)) {
6651
6667
  context.report({
6652
6668
  node: node,
6653
6669
  message: AVOID_SNAKE_CASE_DESTRUCTURING_USEQUERYPARAMS_OR_GETQUERYPARAMS
@@ -6658,6 +6674,57 @@
6658
6674
  }
6659
6675
  };
6660
6676
 
6677
+ var CLASS_NAME = "className";
6678
+ var CLASS_NAMES = ["classnames", "classNames"];
6679
+ var PATTERN = neetoCist.matches({
6680
+ name: {
6681
+ name: CLASS_NAME
6682
+ },
6683
+ value: {
6684
+ expression: {
6685
+ type: TYPES.CALL_EXPRESSION,
6686
+ callee: {
6687
+ name: matchesAny(CLASS_NAMES)
6688
+ },
6689
+ arguments: _defineProperty({
6690
+ length: 1
6691
+ }, 0, {
6692
+ type: matchesAny([TYPES.LITERAL, TYPES.TEMPLATE_LITERAL])
6693
+ })
6694
+ }
6695
+ }
6696
+ });
6697
+
6698
+ var noUnnecessaryClassnames = {
6699
+ meta: {
6700
+ type: "suggestion",
6701
+ docs: {
6702
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-unnecessary-classnames.md",
6703
+ description: "classnames usage is unnecessary"
6704
+ },
6705
+ fixable: "code"
6706
+ },
6707
+ create: function create(context) {
6708
+ return {
6709
+ JSXAttribute: function JSXAttribute(node) {
6710
+ if (!neetoCist.matches(PATTERN, node)) return;
6711
+ context.report({
6712
+ node: node,
6713
+ message: NO_UNNECESSARY_CLASSNAMES,
6714
+ fix: function fix(fixer) {
6715
+ var singleClass = node.value.expression.arguments[0];
6716
+ var classText = context.getSourceCode().getText(singleClass);
6717
+ if (singleClass.type === TYPES.TEMPLATE_LITERAL) {
6718
+ classText = "{".concat(classText, "}");
6719
+ }
6720
+ return fixer.replaceTextRange([node.range[0], node.range[1]], "className=".concat(classText));
6721
+ }
6722
+ });
6723
+ }
6724
+ };
6725
+ }
6726
+ };
6727
+
6661
6728
  // if (condition) statement;
6662
6729
  var SINGLE_LINE_IF_CONDITION_PATTERN = {
6663
6730
  parent: {
@@ -8979,18 +9046,6 @@
8979
9046
  })
8980
9047
  };
8981
9048
 
8982
- // import { functionName } from neetocommons/utils;
8983
- var NEETO_COMMONS_UTILS_IMPORT_PATTERN = {
8984
- type: TYPES.IMPORT_DECLARATION,
8985
- source: {
8986
- type: TYPES.LITERAL,
8987
- value: "neetocommons/utils"
8988
- },
8989
- specifiers: [{
8990
- type: TYPES.IMPORT_SPECIFIER
8991
- }]
8992
- };
8993
-
8994
9049
  var createSubscriptionImportPattern = function createSubscriptionImportPattern(functionName) {
8995
9050
  return {
8996
9051
  type: TYPES.IMPORT_DECLARATION,
@@ -9442,6 +9497,77 @@
9442
9497
  }
9443
9498
  };
9444
9499
 
9500
+ var OBJECT_EXPRESSION_PATTERN = {
9501
+ type: TYPES.OBJECT_EXPRESSION,
9502
+ properties: neetoCist.existsBy({
9503
+ key: {
9504
+ name: "icon"
9505
+ },
9506
+ value: {
9507
+ value: "👍"
9508
+ }
9509
+ })
9510
+ };
9511
+
9512
+ // Toastr.success("", { icon: "👍", className: "w-20" });
9513
+ var TOASTR_SUCCESS_THUMBS_UP_PATTERN = {
9514
+ callee: {
9515
+ object: {
9516
+ name: "Toastr"
9517
+ },
9518
+ property: {
9519
+ name: "success"
9520
+ }
9521
+ },
9522
+ arguments: neetoCist.existsBy(OBJECT_EXPRESSION_PATTERN)
9523
+ };
9524
+
9525
+ // const THUMBS_UP = { icon: "👍", className: "w-20" }
9526
+ var THUMBS_UP_OBJECT_DECLARATION = {
9527
+ id: {
9528
+ type: TYPES.IDENTIFIER,
9529
+ name: "THUMBS_UP"
9530
+ },
9531
+ init: OBJECT_EXPRESSION_PATTERN
9532
+ };
9533
+
9534
+ var useShowThumbsUpToastr = {
9535
+ meta: {
9536
+ type: "problem",
9537
+ docs: {
9538
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-show-thumbs-up-toastr.md",
9539
+ description: "Enforces the use of 'showThumbsUpToastr' function for displaying thumbs up toast messages."
9540
+ },
9541
+ fixable: "code"
9542
+ },
9543
+ create: function create(context) {
9544
+ return {
9545
+ CallExpression: function CallExpression(node) {
9546
+ if (!neetoCist.matches(TOASTR_SUCCESS_THUMBS_UP_PATTERN, node)) return;
9547
+ context.report({
9548
+ node: node,
9549
+ message: USE_SHOW_THUMBS_UP_TOASTR_FUNCTION,
9550
+ fix: function fix(fixer) {
9551
+ var fixerArr = [fixer.replaceText(node, "showThumbsUpToastr()")];
9552
+ var addImport = addFunctionImport({
9553
+ context: context,
9554
+ fixer: fixer,
9555
+ functions: ["showThumbsUpToastr"],
9556
+ importPattern: NEETO_COMMONS_UTILS_IMPORT_PATTERN
9557
+ });
9558
+ if (addImport) fixerArr.push(addImport);
9559
+ return fixerArr;
9560
+ }
9561
+ });
9562
+ },
9563
+ VariableDeclarator: function VariableDeclarator(node) {
9564
+ if (!neetoCist.matches(THUMBS_UP_OBJECT_DECLARATION, node)) return;
9565
+ context.report(node, USE_SHOW_THUMBS_UP_TOASTR_FUNCTION);
9566
+ }
9567
+ };
9568
+ }
9569
+ };
9570
+
9445
9571
  var isSnakeCase = function isSnakeCase(text) {
9446
9572
  return SNAKE_CASE_REGEX.test(text);
9447
9573
  };
@@ -10456,6 +10582,7 @@
10456
10582
 
10457
10583
  var index = {
10458
10584
  rules: {
10585
+ "no-unnecessary-classnames": noUnnecessaryClassnames,
10459
10586
  "no-snake-case-destructuring-for-use-query-params-and-get-query-params": noSnakeCaseDestructuringForUseQueryParamsAndGetQueryParams,
10460
10587
  "no-local-storage": noLocalStorage,
10461
10588
  "no-lowercase-on-translation": noLowercaseOnTranslation,
@@ -10534,7 +10661,8 @@
10534
10661
  "use-common-constants": useCommonConstants,
10535
10662
  "move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition,
10536
10663
  "prefer-function-reference": preferFunctionReference,
10537
- "jsx-prefer-guard-clause": jsxPreferGuardClause
10664
+ "jsx-prefer-guard-clause": jsxPreferGuardClause,
10665
+ "use-show-thumbs-up-toastr": useShowThumbsUpToastr
10538
10666
  },
10539
10667
  configs: {
10540
10668
  recommended: recommended,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.42",
3
+ "version": "1.3.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {