@eslint-react/core 2.0.0-next.177 → 2.0.0-next.179

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/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { unit } from "@eslint-react/eff";
4
4
  import { RuleContext } from "@eslint-react/kit";
5
5
  import * as birecord0 from "birecord";
6
6
  import { isFalseLiteralType, isTrueLiteralType } from "ts-api-utils";
7
+ import * as typescript0 from "typescript";
7
8
  import ts from "typescript";
8
9
  import { ESLintUtils, TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
9
10
  import { Scope } from "@typescript-eslint/scope-manager";
@@ -486,6 +487,39 @@ declare function resolveAttributeValue(context: RuleContext, attribute: AST.TSES
486
487
  readonly toStatic: (name?: string) => unknown;
487
488
  };
488
489
  //#endregion
490
+ //#region src/jsx/jsx-config.d.ts
491
+ declare const JsxEmit: {
492
+ readonly None: 0;
493
+ readonly Preserve: 1;
494
+ readonly React: 2;
495
+ readonly ReactNative: 3;
496
+ readonly ReactJSX: 4;
497
+ readonly ReactJSXDev: 5;
498
+ };
499
+ interface JsxConfig {
500
+ jsx?: number;
501
+ jsxFactory?: string;
502
+ jsxFragmentFactory?: string;
503
+ jsxImportSource?: string;
504
+ }
505
+ /**
506
+ * Get JsxConfig from the rule context by reading compiler options.
507
+ * @param context The RuleContext.
508
+ * @returns JsxConfig derived from compiler options.
509
+ */
510
+ declare function getJsxConfigFromContext(context: RuleContext): {
511
+ jsx: 4 | typescript0.JsxEmit;
512
+ jsxFactory: string;
513
+ jsxFragmentFactory: string;
514
+ jsxImportSource: string;
515
+ };
516
+ /**
517
+ * Get JsxConfig from pragma comments (annotations) in the source code.
518
+ * @param context The RuleContext.
519
+ * @returns JsxConfig derived from pragma comments.
520
+ */
521
+ declare function getJsxConfigFromAnnotation(context: RuleContext): JsxConfig;
522
+ //#endregion
489
523
  //#region src/jsx/jsx-detection.d.ts
490
524
  /**
491
525
  * BitFlags for configuring JSX detection behavior
@@ -799,4 +833,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
799
833
  declare const isMemoCall: isReactAPICall.ReturnType;
800
834
  declare const isLazyCall: isReactAPICall.ReturnType;
801
835
  //#endregion
802
- export { AttributeValue, ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, EffectKind, FunctionComponent, Hook, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, TypeVariant, findParentAttribute, getAttribute, getAttributeName, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getTypeVariants, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isStringType, isThisSetState, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
836
+ export { AttributeValue, ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, EffectKind, FunctionComponent, Hook, JSXDetectionHint, JsxConfig, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, TypeVariant, findParentAttribute, getAttribute, getAttributeName, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getJsxConfigFromAnnotation, getJsxConfigFromContext, getTypeVariants, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isStringType, isThisSetState, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
2
2
  import * as AST from "@eslint-react/ast";
3
- import { constFalse, constTrue, dual, flip, identity, unit } from "@eslint-react/eff";
4
- import { RegExp, Selector } from "@eslint-react/kit";
3
+ import { constFalse, constTrue, dual, flip, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
4
+ import { RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION } from "@eslint-react/kit";
5
5
  import { getId } from "@eslint-react/shared";
6
6
  import * as VAR from "@eslint-react/var";
7
7
  import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
@@ -377,6 +377,56 @@ function resolveAttributeValue(context, attribute) {
377
377
  }
378
378
  }
379
379
 
380
+ //#endregion
381
+ //#region src/jsx/jsx-config.ts
382
+ const JsxEmit = {
383
+ None: 0,
384
+ Preserve: 1,
385
+ React: 2,
386
+ ReactNative: 3,
387
+ ReactJSX: 4,
388
+ ReactJSXDev: 5
389
+ };
390
+ /**
391
+ * Get JsxConfig from the rule context by reading compiler options.
392
+ * @param context The RuleContext.
393
+ * @returns JsxConfig derived from compiler options.
394
+ */
395
+ function getJsxConfigFromContext(context) {
396
+ const options = context.sourceCode.parserServices?.program?.getCompilerOptions() ?? {};
397
+ return {
398
+ jsx: options.jsx ?? JsxEmit.ReactJSX,
399
+ jsxFactory: options.jsxFactory ?? "React.createElement",
400
+ jsxFragmentFactory: options.jsxFragmentFactory ?? "React.Fragment",
401
+ jsxImportSource: options.jsxImportSource ?? "react"
402
+ };
403
+ }
404
+ const cache = /* @__PURE__ */ new WeakMap();
405
+ /**
406
+ * Get JsxConfig from pragma comments (annotations) in the source code.
407
+ * @param context The RuleContext.
408
+ * @returns JsxConfig derived from pragma comments.
409
+ */
410
+ function getJsxConfigFromAnnotation(context) {
411
+ return getOrElseUpdate(cache, context.sourceCode, () => {
412
+ const options = {};
413
+ if (!context.sourceCode.text.includes("@jsx")) return options;
414
+ let jsx, jsxFrag, jsxRuntime, jsxImportSource;
415
+ for (const comment of context.sourceCode.getAllComments().reverse()) {
416
+ const value = comment.value;
417
+ jsx ??= value.match(RE_ANNOTATION_JSX)?.[1];
418
+ jsxFrag ??= value.match(RE_ANNOTATION_JSX_FRAG)?.[1];
419
+ jsxRuntime ??= value.match(RE_ANNOTATION_JSX_RUNTIME)?.[1];
420
+ jsxImportSource ??= value.match(RE_ANNOTATION_JSX_IMPORT_SOURCE)?.[1];
421
+ }
422
+ if (jsx != null) options.jsxFactory = jsx;
423
+ if (jsxFrag != null) options.jsxFragmentFactory = jsxFrag;
424
+ if (jsxRuntime != null) options.jsx = jsxRuntime === "classic" ? JsxEmit.React : JsxEmit.ReactJSX;
425
+ if (jsxImportSource != null) options.jsxImportSource = jsxImportSource;
426
+ return options;
427
+ });
428
+ }
429
+
380
430
  //#endregion
381
431
  //#region src/jsx/jsx-detection.ts
382
432
  /**
@@ -846,10 +896,10 @@ function getComponentFlagFromInitPath(initPath) {
846
896
  //#endregion
847
897
  //#region src/component/component-name.ts
848
898
  function isComponentName(name) {
849
- return RegExp.COMPONENT_NAME.test(name);
899
+ return RE_COMPONENT_NAME.test(name);
850
900
  }
851
901
  function isComponentNameLoose(name) {
852
- return RegExp.COMPONENT_NAME_LOOSE.test(name);
902
+ return RE_COMPONENT_NAME_LOOSE.test(name);
853
903
  }
854
904
  function getComponentNameFromId(id) {
855
905
  if (id == null) return unit;
@@ -933,7 +983,7 @@ function useComponentCollector(context, options = {}) {
933
983
  initPath
934
984
  });
935
985
  },
936
- ...collectDisplayName ? { [Selector.DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
986
+ ...collectDisplayName ? { [SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
937
987
  const { left, right } = node;
938
988
  if (left.type !== AST_NODE_TYPES.MemberExpression) return;
939
989
  const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : unit;
@@ -1211,4 +1261,4 @@ function getTypeVariants(types) {
1211
1261
  }
1212
1262
 
1213
1263
  //#endregion
1214
- export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, findParentAttribute, getAttribute, getAttributeName, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getTypeVariants, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isStringType, isThisSetState, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
1264
+ export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findParentAttribute, getAttribute, getAttributeName, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getJsxConfigFromAnnotation, getJsxConfigFromContext, getTypeVariants, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isStringType, isThisSetState, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.0.0-next.177",
3
+ "version": "2.0.0-next.179",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -34,11 +34,11 @@
34
34
  "birecord": "^0.1.1",
35
35
  "ts-api-utils": "^2.1.0",
36
36
  "ts-pattern": "^5.8.0",
37
- "@eslint-react/ast": "2.0.0-next.177",
38
- "@eslint-react/eff": "2.0.0-next.177",
39
- "@eslint-react/shared": "2.0.0-next.177",
40
- "@eslint-react/kit": "2.0.0-next.177",
41
- "@eslint-react/var": "2.0.0-next.177"
37
+ "@eslint-react/ast": "2.0.0-next.179",
38
+ "@eslint-react/eff": "2.0.0-next.179",
39
+ "@eslint-react/kit": "2.0.0-next.179",
40
+ "@eslint-react/var": "2.0.0-next.179",
41
+ "@eslint-react/shared": "2.0.0-next.179"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsdown": "^0.15.0",