@ngrx/eslint-plugin 14.3.0 → 14.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrx/eslint-plugin",
3
- "version": "14.3.0",
3
+ "version": "14.3.1",
4
4
  "description": "NgRx ESLint Plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -66,15 +66,32 @@ exports["default"] = (0, rule_creator_1.createRule)({
66
66
  }
67
67
  return false;
68
68
  }
69
+ var pipeHasThisExpression = false;
70
+ var selectorQuery = ":matches(".concat(selectSelector, ", ").concat(pipeWithSelectAndMapSelector, ")");
69
71
  return _a = {},
70
- _a[":matches(".concat(selectSelector, ", ").concat(pipeWithSelectAndMapSelector, ") > CallExpression[callee.name='map']:not(:has(ThisExpression))")] = function (node) {
72
+ _a["".concat(selectorQuery, " > CallExpression:has(ThisExpression)")] = function (node) {
73
+ pipeHasThisExpression = true;
74
+ },
75
+ _a["".concat(selectorQuery, "[callee.property.name=pipe]:exit")] = function (node) {
76
+ if (pipeHasThisExpression) {
77
+ pipeHasThisExpression = false;
78
+ return;
79
+ }
71
80
  if (isInCreateEffect(node)) {
72
81
  return;
73
82
  }
74
- context.report({
75
- node: node,
76
- messageId: exports.messageId
83
+ var operators = node.arguments;
84
+ var mapOperator = operators.find(function (operator) {
85
+ return (0, eslint_etc_1.isCallExpression)(operator) &&
86
+ (0, eslint_etc_1.isIdentifier)(operator.callee) &&
87
+ operator.callee.name === 'map';
77
88
  });
89
+ if (mapOperator) {
90
+ context.report({
91
+ node: mapOperator,
92
+ messageId: exports.messageId
93
+ });
94
+ }
78
95
  },
79
96
  _a;
80
97
  }
@@ -1 +1 @@
1
- {"version":3,"file":"avoid-mapping-selectors.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-mapping-selectors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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AAC,MAAM,CAAC;aACxB;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED;YACE,GAAC,mBAAY,cAAc,eAAK,4BAA4B,oEAAiE,IAA7H,UACE,IAA6B;gBAE7B,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE;oBAC1B,OAAO;iBACR;gBACD,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,MAAA;oBACJ,SAAS,mBAAA;iBACV,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport { isCallExpression, isIdentifier } from 'eslint-etc';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getNgRxStores,\n namedCallableExpression,\n pipeExpression,\n} from '../../utils';\n\nexport const messageId = 'avoidMapppingSelectors';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description: 'Avoid mapping logic outside the selector level.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]: 'Map logic at the selector level instead.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n const pipeWithSelectAndMapSelector = `${pipeExpression(\n storeNames\n )}:has(CallExpression[callee.name='select'] ~ CallExpression[callee.name='map'])` as const;\n const selectSelector = `${namedCallableExpression(\n storeNames\n )}[callee.object.callee.property.name='select']` as const;\n\n function isInCreateEffect(node: TSESTree.CallExpression) {\n let parent = node.parent;\n while (parent) {\n if (\n isCallExpression(parent) &&\n isIdentifier(parent.callee) &&\n parent.callee.name === 'createEffect'\n ) {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n }\n\n return {\n [`:matches(${selectSelector}, ${pipeWithSelectAndMapSelector}) > CallExpression[callee.name='map']:not(:has(ThisExpression))`](\n node: TSESTree.CallExpression\n ) {\n if (isInCreateEffect(node)) {\n return;\n }\n context.report({\n node,\n messageId,\n });\n },\n };\n },\n});\n"]}
1
+ {"version":3,"file":"avoid-mapping-selectors.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-mapping-selectors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA4D;AAC5D,yCAA6B;AAC7B,mDAAgD;AAChD,qCAMqB;AAER,QAAA,SAAS,GAAG,wBAAwB,CAAC;AAKlD,qBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EAAE,iDAAiD;YAC9D,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IAAG,0CAA0C;eACxD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACN,IAAA,KAAqB,IAAA,qBAAa,EAAC,OAAO,CAAC,YAA3B,EAAhB,WAAW,mBAAG,EAAE,KAAA,CAA4B;QACpD,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,EAAE,CAAC;SACX;QAED,IAAM,4BAA4B,GAAG,UAAG,IAAA,sBAAc,EACpD,UAAU,CACX,mFAAyF,CAAC;QAC3F,IAAM,cAAc,GAAG,UAAG,IAAA,+BAAuB,EAC/C,UAAU,CACX,kDAAwD,CAAC;QAE1D,SAAS,gBAAgB,CAAC,IAA6B;YACrD,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\nimport { isCallExpression, isIdentifier } from 'eslint-etc';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getNgRxStores,\n isMemberExpression,\n namedCallableExpression,\n pipeExpression,\n} from '../../utils';\n\nexport const messageId = 'avoidMapppingSelectors';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description: 'Avoid mapping logic outside the selector level.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]: 'Map logic at the selector level instead.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n const pipeWithSelectAndMapSelector = `${pipeExpression(\n storeNames\n )}:has(CallExpression[callee.name='select'] ~ CallExpression[callee.name='map'])` as const;\n const selectSelector = `${namedCallableExpression(\n storeNames\n )}[callee.object.callee.property.name='select']` as const;\n\n function isInCreateEffect(node: TSESTree.CallExpression) {\n let parent = node.parent;\n while (parent) {\n if (\n isCallExpression(parent) &&\n isIdentifier(parent.callee) &&\n parent.callee.name === 'createEffect'\n ) {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n }\n\n let pipeHasThisExpression = false;\n\n const selectorQuery = `:matches(${selectSelector}, ${pipeWithSelectAndMapSelector})`;\n return {\n [`${selectorQuery} > CallExpression:has(ThisExpression)`](\n node: TSESTree.CallExpression\n ) {\n pipeHasThisExpression = true;\n },\n [`${selectorQuery}[callee.property.name=pipe]:exit`](\n node: TSESTree.CallExpression\n ) {\n if (pipeHasThisExpression) {\n pipeHasThisExpression = false;\n return;\n }\n\n if (isInCreateEffect(node)) {\n return;\n }\n\n const operators = node.arguments;\n const mapOperator = operators.find(\n (operator) =>\n isCallExpression(operator) &&\n isIdentifier(operator.callee) &&\n operator.callee.name === 'map'\n );\n if (mapOperator) {\n context.report({\n node: mapOperator,\n messageId,\n });\n }\n },\n };\n },\n});\n"]}