@eslint-react/jsx 0.9.1-beta.1 → 0.9.1-beta.3

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.cjs CHANGED
@@ -40,7 +40,7 @@ function getFragmentFromContext(context) {
40
40
  // eslint-disable-next-line prefer-destructuring
41
41
  const settings = context.settings;
42
42
  const fragment = settings.react?.fragment;
43
- if (tools.Pred.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
43
+ if (tools.P.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
44
44
  return fragment;
45
45
  }
46
46
  return "Fragment";
@@ -53,8 +53,6 @@ const getPragmaFromContext = memo((context)=>{
53
53
  return tools.F.pipe(tools.O.orElse(tools.O.fromNullable(settings.react?.pragma), ()=>tools.F.pipe(tools.O.fromNullable(pragmaNode), tools.O.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), tools.O.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), tools.O.flatMap(tools.O.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), tools.O.getOrElse(tools.F.constant("React")));
54
54
  });
55
55
 
56
- const t=Symbol.for("@ts-pattern/matcher"),e=Symbol.for("@ts-pattern/isVariadic"),n="@ts-pattern/anonymous-select-key",r=t=>Boolean(t&&"object"==typeof t),i=e=>e&&!!e[t],s=(n,o,c)=>{if(i(n)){const e=n[t](),{matched:r,selections:i}=e.match(o);return r&&i&&Object.keys(i).forEach(t=>c(t,i[t])),r}if(r(n)){if(!r(o))return !1;if(Array.isArray(n)){if(!Array.isArray(o))return !1;let t=[],r=[],a=[];for(const s of n.keys()){const o=n[s];i(o)&&o[e]?a.push(o):a.length?r.push(o):t.push(o);}if(a.length){if(a.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(o.length<t.length+r.length)return !1;const e=o.slice(0,t.length),n=0===r.length?[]:o.slice(-r.length),i=o.slice(t.length,0===r.length?Infinity:-r.length);return t.every((t,n)=>s(t,e[n],c))&&r.every((t,e)=>s(t,n[e],c))&&(0===a.length||s(a[0],i,c))}return n.length===o.length&&n.every((t,e)=>s(t,o[e],c))}return Object.keys(n).every(e=>{const r=n[e];return (e in o||i(a=r)&&"optional"===a[t]().matcherType)&&s(r,o[e],c);var a;})}return Object.is(o,n)},o=e=>{var n,s,a;return r(e)?i(e)?null!=(n=null==(s=(a=e[t]()).getSelectionKeys)?void 0:s.call(a))?n:[]:Array.isArray(e)?c(e,o):c(Object.values(e),o):[]},c=(t,e)=>t.reduce((t,n)=>t.concat(e(n)),[]);function a(...t){if(1===t.length){const[e]=t;return t=>s(e,t,()=>{})}if(2===t.length){const[e,n]=t;return s(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function u(t){return Object.assign(t,{optional:()=>l(t),and:e=>m(t,e),or:e=>y(t,e),select:e=>void 0===e?p(t):p(e,t)})}function h(t){return Object.assign((t=>Object.assign(t,{*[Symbol.iterator](){yield Object.assign(t,{[e]:!0});}}))(t),{optional:()=>h(l(t)),select:e=>h(void 0===e?p(t):p(e,t))})}function l(e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return void 0===t?(o(e).forEach(t=>r(t,void 0)),{matched:!0,selections:n}):{matched:s(e,t,r),selections:n}},getSelectionKeys:()=>o(e),matcherType:"optional"})})}const f=(t,e)=>{for(const n of t)if(!e(n))return !1;return !0},g=(t,e)=>{for(const[n,r]of t.entries())if(!e(r,n))return !1;return !0};function m(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return {matched:e.every(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"and"})})}function y(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return c(e,o).forEach(t=>r(t,void 0)),{matched:e.some(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"or"})})}function d(e){return {[t]:()=>({match:t=>({matched:Boolean(e(t))})})}}function p(...e){const r="string"==typeof e[0]?e[0]:void 0,i=2===e.length?e[1]:"string"==typeof e[0]?void 0:e[0];return u({[t]:()=>({match:t=>{let e={[null!=r?r:n]:t};return {matched:void 0===i||s(i,t,(t,n)=>{e[t]=n;}),selections:e}},getSelectionKeys:()=>[null!=r?r:n].concat(void 0===i?[]:o(i))})})}function v(t){return "number"==typeof t}function b(t){return "string"==typeof t}function w(t){return "bigint"==typeof t}const S=u(d(function(t){return !0})),O=S,j=t=>Object.assign(u(t),{startsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.startsWith(n)))));var n;},endsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.endsWith(n)))));var n;},minLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length>=t))(e))),maxLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length<=t))(e))),includes:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.includes(n)))));var n;},regex:e=>{return j(m(t,(n=e,d(t=>b(t)&&Boolean(t.match(n))))));var n;}}),E=j(d(b)),K=t=>Object.assign(u(t),{between:(e,n)=>K(m(t,((t,e)=>d(n=>v(n)&&t<=n&&e>=n))(e,n))),lt:e=>K(m(t,(t=>d(e=>v(e)&&e<t))(e))),gt:e=>K(m(t,(t=>d(e=>v(e)&&e>t))(e))),lte:e=>K(m(t,(t=>d(e=>v(e)&&e<=t))(e))),gte:e=>K(m(t,(t=>d(e=>v(e)&&e>=t))(e))),int:()=>K(m(t,d(t=>v(t)&&Number.isInteger(t)))),finite:()=>K(m(t,d(t=>v(t)&&Number.isFinite(t)))),positive:()=>K(m(t,d(t=>v(t)&&t>0))),negative:()=>K(m(t,d(t=>v(t)&&t<0)))}),A=K(d(v)),x=t=>Object.assign(u(t),{between:(e,n)=>x(m(t,((t,e)=>d(n=>w(n)&&t<=n&&e>=n))(e,n))),lt:e=>x(m(t,(t=>d(e=>w(e)&&e<t))(e))),gt:e=>x(m(t,(t=>d(e=>w(e)&&e>t))(e))),lte:e=>x(m(t,(t=>d(e=>w(e)&&e<=t))(e))),gte:e=>x(m(t,(t=>d(e=>w(e)&&e>=t))(e))),positive:()=>x(m(t,d(t=>w(t)&&t>0))),negative:()=>x(m(t,d(t=>w(t)&&t<0)))}),P=x(d(w)),T=u(d(function(t){return "boolean"==typeof t})),k=u(d(function(t){return "symbol"==typeof t})),B=u(d(function(t){return null==t}));var _={__proto__:null,matcher:t,optional:l,array:function(...e){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return {matched:!1};if(0===e.length)return {matched:!0};const n=e[0];let r={};if(0===t.length)return o(n).forEach(t=>{r[t]=[];}),{matched:!0,selections:r};const i=(t,e)=>{r[t]=(r[t]||[]).concat([e]);};return {matched:t.every(t=>s(n,t,i)),selections:r}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},set:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Set))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};if(0===e.length)return {matched:!0};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);},i=e[0];return {matched:f(t,t=>s(i,t,r)),selections:n}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},map:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Map))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);};if(0===e.length)return {matched:!0};var i;if(1===e.length)throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null==(i=e[0])?void 0:i.toString()}`);const[o,c]=e;return {matched:g(t,(t,e)=>{const n=s(o,e,r),i=s(c,t,r);return n&&i}),selections:n}},getSelectionKeys:()=>0===e.length?[]:[...o(e[0]),...o(e[1])]})})},intersection:m,union:y,not:function(e){return u({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:d,select:p,any:S,_:O,string:E,number:A,bigint:P,boolean:T,symbol:k,nullish:B,instanceOf:function(t){return u(d(function(t){return e=>e instanceof t}(t)))},shape:function(t){return u(d(a(t)))}};const W={matched:!1,value:void 0};function N(t){return new $(t,W)}class ${constructor(t,e){this.input=void 0,this.state=void 0,this.input=t,this.state=e;}with(...t){if(this.state.matched)return this;const e=t[t.length-1],r=[t[0]];let i;3===t.length&&"function"==typeof t[1]?i=t[1]:t.length>2&&r.push(...t.slice(1,t.length-1));let o=!1,c={};const a=(t,e)=>{o=!0,c[t]=e;},u=!r.some(t=>s(t,this.input,a))||i&&!Boolean(i(this.input))?W:{matched:!0,value:e(o?n in c?c[n]:c:this.input,this.input)};return new $(this.input,u)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new $(this.input,n?{matched:!0,value:e(this.input,this.input)}:W)}otherwise(t){return this.state.matched?this.state.value:t(this.input)}exhaustive(){if(this.state.matched)return this.state.value;let t;try{t=JSON.stringify(this.input);}catch(e){t=this.input;}throw new Error(`Pattern matching error: no pattern matches value ${t}`)}run(){return this.exhaustive()}returnType(){return this}}
57
-
58
56
  function isInitializedFromPragma(variableName, context, pragma = getPragmaFromContext(context)) {
59
57
  const variables = ast.getVariablesUpToGlobal(context.getScope());
60
58
  const maybeVariable = ast.findVariableByName(variableName)(variables);
@@ -67,7 +65,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
67
65
  if (node.type === ast.NodeType.VariableDeclarator && node.init) {
68
66
  const { init } = node;
69
67
  // check for: `variable = pragma.variable`
70
- if (a({
68
+ if (tools.M.isMatching({
71
69
  type: "MemberExpression",
72
70
  object: {
73
71
  type: "Identifier",
@@ -77,14 +75,14 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
77
75
  return true;
78
76
  }
79
77
  // check for: `{ variable } = pragma`
80
- if (a({
78
+ if (tools.M.isMatching({
81
79
  type: "Identifier",
82
80
  name: pragma
83
81
  }, init)) {
84
82
  return true;
85
83
  }
86
84
  // check if from a require call: `require("react")`
87
- const maybeRequireExpression = N(init).with({
85
+ const maybeRequireExpression = tools.M.match(init).with({
88
86
  type: ast.NodeType.CallExpression,
89
87
  callee: {
90
88
  type: ast.NodeType.Identifier,
@@ -111,7 +109,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
111
109
  return firstArg.value === pragma.toLowerCase();
112
110
  }
113
111
  // latest definition is an import declaration: import { variable } from 'react'
114
- return a({
112
+ return tools.M.isMatching({
115
113
  type: "ImportDeclaration",
116
114
  source: {
117
115
  value: pragma.toLowerCase()
@@ -119,7 +117,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
119
117
  }, parent);
120
118
  }
121
119
  function isPropertyOfPragma(name, context, pragma = getPragmaFromContext(context)) {
122
- const isMatch = a({
120
+ const isMatch = tools.M.isMatching({
123
121
  type: ast.NodeType.MemberExpression,
124
122
  object: {
125
123
  type: ast.NodeType.Identifier,
@@ -388,7 +386,7 @@ const isFragment = (node, pragma, fragment)=>{
388
386
  if (!node) {
389
387
  return false;
390
388
  }
391
- return N(node).with({
389
+ return tools.M.match(node).with({
392
390
  type: ast.NodeType.JSXElement
393
391
  }, tools.F.constTrue).with({
394
392
  type: ast.NodeType.JSXFragment
@@ -399,7 +397,7 @@ const isFragment = (node, pragma, fragment)=>{
399
397
  }, tools.F.constTrue).with({
400
398
  type: ast.NodeType.Literal
401
399
  }, (node)=>{
402
- return N(node.value).with(null, ()=>!(hint & JSXValueCheckHint.SkipNullLiteral)).with(_.boolean, ()=>!(hint & JSXValueCheckHint.SkipBooleanLiteral)).with(_.string, ()=>!(hint & JSXValueCheckHint.SkipStringLiteral)).with(_.number, ()=>!(hint & JSXValueCheckHint.SkipNumberLiteral)).otherwise(tools.F.constFalse);
400
+ return tools.M.match(node.value).with(null, ()=>!(hint & JSXValueCheckHint.SkipNullLiteral)).with(tools.M.P.boolean, ()=>!(hint & JSXValueCheckHint.SkipBooleanLiteral)).with(tools.M.P.string, ()=>!(hint & JSXValueCheckHint.SkipStringLiteral)).with(tools.M.P.number, ()=>!(hint & JSXValueCheckHint.SkipNumberLiteral)).otherwise(tools.F.constFalse);
403
401
  }).with({
404
402
  type: ast.NodeType.TemplateLiteral
405
403
  }, ()=>{
@@ -480,7 +478,7 @@ const isFragment = (node, pragma, fragment)=>{
480
478
  * @param node The JSX attribute node
481
479
  * @returns string
482
480
  */ function getPropName(node) {
483
- return N(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n)=>n.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
481
+ return tools.M.match(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n)=>n.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
484
482
  }
485
483
  function getProp(props, propName, context) {
486
484
  return findPropInAttributes(props, context)(propName);
@@ -521,10 +519,10 @@ function getProp(props, propName, context) {
521
519
  * @returns The property if found
522
520
  */ return (propName)=>{
523
521
  return tools.O.fromNullable(properties.find((prop)=>{
524
- return N(prop).when(ast.is(ast.NodeType.Property), (prop)=>{
522
+ return tools.M.match(prop).when(ast.is(ast.NodeType.Property), (prop)=>{
525
523
  return "name" in prop.key && prop.key.name === propName;
526
524
  }).when(ast.is(ast.NodeType.SpreadElement), (prop)=>{
527
- return N(prop.argument).when(ast.is(ast.NodeType.Identifier), (argument)=>{
525
+ return tools.M.match(prop.argument).when(ast.is(ast.NodeType.Identifier), (argument)=>{
528
526
  const { name } = argument;
529
527
  const maybeInit = tools.O.flatMap(ast.findVariableByNameUpToGlobal(name, startScope), ast.getVariableInit(0));
530
528
  if (tools.O.isNone(maybeInit)) {
@@ -567,8 +565,8 @@ function getProp(props, propName, context) {
567
565
  * @returns The property if found
568
566
  */ return (propName)=>{
569
567
  return tools.O.fromNullable(attributes.find((attr)=>{
570
- return N(attr).when(ast.is(ast.NodeType.JSXAttribute), (attr)=>getPropName(attr) === propName).when(ast.is(ast.NodeType.JSXSpreadAttribute), (attr)=>{
571
- return N(attr.argument).with({
568
+ return tools.M.match(attr).when(ast.is(ast.NodeType.JSXAttribute), (attr)=>getPropName(attr) === propName).when(ast.is(ast.NodeType.JSXSpreadAttribute), (attr)=>{
569
+ return tools.M.match(attr.argument).with({
572
570
  type: ast.NodeType.Identifier
573
571
  }, (argument)=>{
574
572
  const { name } = argument;
@@ -659,7 +657,7 @@ function getProp(props, propName, context) {
659
657
  * @param node The AST node to check
660
658
  * @returns boolean `true` if the node is whitespace
661
659
  */ function isWhiteSpace(node) {
662
- return tools.Pred.isString(node.value) && node.value.trim() === "";
660
+ return tools.P.isString(node.value) && node.value.trim() === "";
663
661
  }
664
662
  /**
665
663
  * Check if a Literal or JSXText node is a line break
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ function getFragmentFromContext(context) {
40
40
  // eslint-disable-next-line prefer-destructuring
41
41
  const settings = context.settings;
42
42
  const fragment = settings.react?.fragment;
43
- if (tools.Pred.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
43
+ if (tools.P.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
44
44
  return fragment;
45
45
  }
46
46
  return "Fragment";
@@ -53,8 +53,6 @@ const getPragmaFromContext = memo((context)=>{
53
53
  return tools.F.pipe(tools.O.orElse(tools.O.fromNullable(settings.react?.pragma), ()=>tools.F.pipe(tools.O.fromNullable(pragmaNode), tools.O.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), tools.O.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), tools.O.flatMap(tools.O.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), tools.O.getOrElse(tools.F.constant("React")));
54
54
  });
55
55
 
56
- const t=Symbol.for("@ts-pattern/matcher"),e=Symbol.for("@ts-pattern/isVariadic"),n="@ts-pattern/anonymous-select-key",r=t=>Boolean(t&&"object"==typeof t),i=e=>e&&!!e[t],s=(n,o,c)=>{if(i(n)){const e=n[t](),{matched:r,selections:i}=e.match(o);return r&&i&&Object.keys(i).forEach(t=>c(t,i[t])),r}if(r(n)){if(!r(o))return !1;if(Array.isArray(n)){if(!Array.isArray(o))return !1;let t=[],r=[],a=[];for(const s of n.keys()){const o=n[s];i(o)&&o[e]?a.push(o):a.length?r.push(o):t.push(o);}if(a.length){if(a.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(o.length<t.length+r.length)return !1;const e=o.slice(0,t.length),n=0===r.length?[]:o.slice(-r.length),i=o.slice(t.length,0===r.length?Infinity:-r.length);return t.every((t,n)=>s(t,e[n],c))&&r.every((t,e)=>s(t,n[e],c))&&(0===a.length||s(a[0],i,c))}return n.length===o.length&&n.every((t,e)=>s(t,o[e],c))}return Object.keys(n).every(e=>{const r=n[e];return (e in o||i(a=r)&&"optional"===a[t]().matcherType)&&s(r,o[e],c);var a;})}return Object.is(o,n)},o=e=>{var n,s,a;return r(e)?i(e)?null!=(n=null==(s=(a=e[t]()).getSelectionKeys)?void 0:s.call(a))?n:[]:Array.isArray(e)?c(e,o):c(Object.values(e),o):[]},c=(t,e)=>t.reduce((t,n)=>t.concat(e(n)),[]);function a(...t){if(1===t.length){const[e]=t;return t=>s(e,t,()=>{})}if(2===t.length){const[e,n]=t;return s(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function u(t){return Object.assign(t,{optional:()=>l(t),and:e=>m(t,e),or:e=>y(t,e),select:e=>void 0===e?p(t):p(e,t)})}function h(t){return Object.assign((t=>Object.assign(t,{*[Symbol.iterator](){yield Object.assign(t,{[e]:!0});}}))(t),{optional:()=>h(l(t)),select:e=>h(void 0===e?p(t):p(e,t))})}function l(e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return void 0===t?(o(e).forEach(t=>r(t,void 0)),{matched:!0,selections:n}):{matched:s(e,t,r),selections:n}},getSelectionKeys:()=>o(e),matcherType:"optional"})})}const f=(t,e)=>{for(const n of t)if(!e(n))return !1;return !0},g=(t,e)=>{for(const[n,r]of t.entries())if(!e(r,n))return !1;return !0};function m(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return {matched:e.every(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"and"})})}function y(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return c(e,o).forEach(t=>r(t,void 0)),{matched:e.some(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"or"})})}function d(e){return {[t]:()=>({match:t=>({matched:Boolean(e(t))})})}}function p(...e){const r="string"==typeof e[0]?e[0]:void 0,i=2===e.length?e[1]:"string"==typeof e[0]?void 0:e[0];return u({[t]:()=>({match:t=>{let e={[null!=r?r:n]:t};return {matched:void 0===i||s(i,t,(t,n)=>{e[t]=n;}),selections:e}},getSelectionKeys:()=>[null!=r?r:n].concat(void 0===i?[]:o(i))})})}function v(t){return "number"==typeof t}function b(t){return "string"==typeof t}function w(t){return "bigint"==typeof t}const S=u(d(function(t){return !0})),O=S,j=t=>Object.assign(u(t),{startsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.startsWith(n)))));var n;},endsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.endsWith(n)))));var n;},minLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length>=t))(e))),maxLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length<=t))(e))),includes:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.includes(n)))));var n;},regex:e=>{return j(m(t,(n=e,d(t=>b(t)&&Boolean(t.match(n))))));var n;}}),E=j(d(b)),K=t=>Object.assign(u(t),{between:(e,n)=>K(m(t,((t,e)=>d(n=>v(n)&&t<=n&&e>=n))(e,n))),lt:e=>K(m(t,(t=>d(e=>v(e)&&e<t))(e))),gt:e=>K(m(t,(t=>d(e=>v(e)&&e>t))(e))),lte:e=>K(m(t,(t=>d(e=>v(e)&&e<=t))(e))),gte:e=>K(m(t,(t=>d(e=>v(e)&&e>=t))(e))),int:()=>K(m(t,d(t=>v(t)&&Number.isInteger(t)))),finite:()=>K(m(t,d(t=>v(t)&&Number.isFinite(t)))),positive:()=>K(m(t,d(t=>v(t)&&t>0))),negative:()=>K(m(t,d(t=>v(t)&&t<0)))}),A=K(d(v)),x=t=>Object.assign(u(t),{between:(e,n)=>x(m(t,((t,e)=>d(n=>w(n)&&t<=n&&e>=n))(e,n))),lt:e=>x(m(t,(t=>d(e=>w(e)&&e<t))(e))),gt:e=>x(m(t,(t=>d(e=>w(e)&&e>t))(e))),lte:e=>x(m(t,(t=>d(e=>w(e)&&e<=t))(e))),gte:e=>x(m(t,(t=>d(e=>w(e)&&e>=t))(e))),positive:()=>x(m(t,d(t=>w(t)&&t>0))),negative:()=>x(m(t,d(t=>w(t)&&t<0)))}),P=x(d(w)),T=u(d(function(t){return "boolean"==typeof t})),k=u(d(function(t){return "symbol"==typeof t})),B=u(d(function(t){return null==t}));var _={__proto__:null,matcher:t,optional:l,array:function(...e){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return {matched:!1};if(0===e.length)return {matched:!0};const n=e[0];let r={};if(0===t.length)return o(n).forEach(t=>{r[t]=[];}),{matched:!0,selections:r};const i=(t,e)=>{r[t]=(r[t]||[]).concat([e]);};return {matched:t.every(t=>s(n,t,i)),selections:r}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},set:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Set))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};if(0===e.length)return {matched:!0};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);},i=e[0];return {matched:f(t,t=>s(i,t,r)),selections:n}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},map:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Map))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);};if(0===e.length)return {matched:!0};var i;if(1===e.length)throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null==(i=e[0])?void 0:i.toString()}`);const[o,c]=e;return {matched:g(t,(t,e)=>{const n=s(o,e,r),i=s(c,t,r);return n&&i}),selections:n}},getSelectionKeys:()=>0===e.length?[]:[...o(e[0]),...o(e[1])]})})},intersection:m,union:y,not:function(e){return u({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:d,select:p,any:S,_:O,string:E,number:A,bigint:P,boolean:T,symbol:k,nullish:B,instanceOf:function(t){return u(d(function(t){return e=>e instanceof t}(t)))},shape:function(t){return u(d(a(t)))}};const W={matched:!1,value:void 0};function N(t){return new $(t,W)}class ${constructor(t,e){this.input=void 0,this.state=void 0,this.input=t,this.state=e;}with(...t){if(this.state.matched)return this;const e=t[t.length-1],r=[t[0]];let i;3===t.length&&"function"==typeof t[1]?i=t[1]:t.length>2&&r.push(...t.slice(1,t.length-1));let o=!1,c={};const a=(t,e)=>{o=!0,c[t]=e;},u=!r.some(t=>s(t,this.input,a))||i&&!Boolean(i(this.input))?W:{matched:!0,value:e(o?n in c?c[n]:c:this.input,this.input)};return new $(this.input,u)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new $(this.input,n?{matched:!0,value:e(this.input,this.input)}:W)}otherwise(t){return this.state.matched?this.state.value:t(this.input)}exhaustive(){if(this.state.matched)return this.state.value;let t;try{t=JSON.stringify(this.input);}catch(e){t=this.input;}throw new Error(`Pattern matching error: no pattern matches value ${t}`)}run(){return this.exhaustive()}returnType(){return this}}
57
-
58
56
  function isInitializedFromPragma(variableName, context, pragma = getPragmaFromContext(context)) {
59
57
  const variables = ast.getVariablesUpToGlobal(context.getScope());
60
58
  const maybeVariable = ast.findVariableByName(variableName)(variables);
@@ -67,7 +65,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
67
65
  if (node.type === ast.NodeType.VariableDeclarator && node.init) {
68
66
  const { init } = node;
69
67
  // check for: `variable = pragma.variable`
70
- if (a({
68
+ if (tools.M.isMatching({
71
69
  type: "MemberExpression",
72
70
  object: {
73
71
  type: "Identifier",
@@ -77,14 +75,14 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
77
75
  return true;
78
76
  }
79
77
  // check for: `{ variable } = pragma`
80
- if (a({
78
+ if (tools.M.isMatching({
81
79
  type: "Identifier",
82
80
  name: pragma
83
81
  }, init)) {
84
82
  return true;
85
83
  }
86
84
  // check if from a require call: `require("react")`
87
- const maybeRequireExpression = N(init).with({
85
+ const maybeRequireExpression = tools.M.match(init).with({
88
86
  type: ast.NodeType.CallExpression,
89
87
  callee: {
90
88
  type: ast.NodeType.Identifier,
@@ -111,7 +109,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
111
109
  return firstArg.value === pragma.toLowerCase();
112
110
  }
113
111
  // latest definition is an import declaration: import { variable } from 'react'
114
- return a({
112
+ return tools.M.isMatching({
115
113
  type: "ImportDeclaration",
116
114
  source: {
117
115
  value: pragma.toLowerCase()
@@ -119,7 +117,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
119
117
  }, parent);
120
118
  }
121
119
  function isPropertyOfPragma(name, context, pragma = getPragmaFromContext(context)) {
122
- const isMatch = a({
120
+ const isMatch = tools.M.isMatching({
123
121
  type: ast.NodeType.MemberExpression,
124
122
  object: {
125
123
  type: ast.NodeType.Identifier,
@@ -388,7 +386,7 @@ const isFragment = (node, pragma, fragment)=>{
388
386
  if (!node) {
389
387
  return false;
390
388
  }
391
- return N(node).with({
389
+ return tools.M.match(node).with({
392
390
  type: ast.NodeType.JSXElement
393
391
  }, tools.F.constTrue).with({
394
392
  type: ast.NodeType.JSXFragment
@@ -399,7 +397,7 @@ const isFragment = (node, pragma, fragment)=>{
399
397
  }, tools.F.constTrue).with({
400
398
  type: ast.NodeType.Literal
401
399
  }, (node)=>{
402
- return N(node.value).with(null, ()=>!(hint & JSXValueCheckHint.SkipNullLiteral)).with(_.boolean, ()=>!(hint & JSXValueCheckHint.SkipBooleanLiteral)).with(_.string, ()=>!(hint & JSXValueCheckHint.SkipStringLiteral)).with(_.number, ()=>!(hint & JSXValueCheckHint.SkipNumberLiteral)).otherwise(tools.F.constFalse);
400
+ return tools.M.match(node.value).with(null, ()=>!(hint & JSXValueCheckHint.SkipNullLiteral)).with(tools.M.P.boolean, ()=>!(hint & JSXValueCheckHint.SkipBooleanLiteral)).with(tools.M.P.string, ()=>!(hint & JSXValueCheckHint.SkipStringLiteral)).with(tools.M.P.number, ()=>!(hint & JSXValueCheckHint.SkipNumberLiteral)).otherwise(tools.F.constFalse);
403
401
  }).with({
404
402
  type: ast.NodeType.TemplateLiteral
405
403
  }, ()=>{
@@ -480,7 +478,7 @@ const isFragment = (node, pragma, fragment)=>{
480
478
  * @param node The JSX attribute node
481
479
  * @returns string
482
480
  */ function getPropName(node) {
483
- return N(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n)=>n.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
481
+ return tools.M.match(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n)=>n.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
484
482
  }
485
483
  function getProp(props, propName, context) {
486
484
  return findPropInAttributes(props, context)(propName);
@@ -521,10 +519,10 @@ function getProp(props, propName, context) {
521
519
  * @returns The property if found
522
520
  */ return (propName)=>{
523
521
  return tools.O.fromNullable(properties.find((prop)=>{
524
- return N(prop).when(ast.is(ast.NodeType.Property), (prop)=>{
522
+ return tools.M.match(prop).when(ast.is(ast.NodeType.Property), (prop)=>{
525
523
  return "name" in prop.key && prop.key.name === propName;
526
524
  }).when(ast.is(ast.NodeType.SpreadElement), (prop)=>{
527
- return N(prop.argument).when(ast.is(ast.NodeType.Identifier), (argument)=>{
525
+ return tools.M.match(prop.argument).when(ast.is(ast.NodeType.Identifier), (argument)=>{
528
526
  const { name } = argument;
529
527
  const maybeInit = tools.O.flatMap(ast.findVariableByNameUpToGlobal(name, startScope), ast.getVariableInit(0));
530
528
  if (tools.O.isNone(maybeInit)) {
@@ -567,8 +565,8 @@ function getProp(props, propName, context) {
567
565
  * @returns The property if found
568
566
  */ return (propName)=>{
569
567
  return tools.O.fromNullable(attributes.find((attr)=>{
570
- return N(attr).when(ast.is(ast.NodeType.JSXAttribute), (attr)=>getPropName(attr) === propName).when(ast.is(ast.NodeType.JSXSpreadAttribute), (attr)=>{
571
- return N(attr.argument).with({
568
+ return tools.M.match(attr).when(ast.is(ast.NodeType.JSXAttribute), (attr)=>getPropName(attr) === propName).when(ast.is(ast.NodeType.JSXSpreadAttribute), (attr)=>{
569
+ return tools.M.match(attr.argument).with({
572
570
  type: ast.NodeType.Identifier
573
571
  }, (argument)=>{
574
572
  const { name } = argument;
@@ -659,7 +657,7 @@ function getProp(props, propName, context) {
659
657
  * @param node The AST node to check
660
658
  * @returns boolean `true` if the node is whitespace
661
659
  */ function isWhiteSpace(node) {
662
- return tools.Pred.isString(node.value) && node.value.trim() === "";
660
+ return tools.P.isString(node.value) && node.value.trim() === "";
663
661
  }
664
662
  /**
665
663
  * Check if a Literal or JSXText node is a line break
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
2
2
  import { getVariablesUpToGlobal, findVariableByName, NodeType, traverseUp, is, isOneOf, isJSXTagNameExpression, findVariableByNameUpToGlobal, getVariableInit, getNestedReturnStatements, getStaticValue, traverseUpGuard, isStringLiteral, isMultiLine } from '@eslint-react/ast';
3
- import { F, O as O$1, Pred } from '@eslint-react/tools';
3
+ import { F, O, P, M } from '@eslint-react/tools';
4
4
  import memo from 'micro-memoize';
5
5
 
6
6
  function resolveMemberExpressions(object, property) {
@@ -38,7 +38,7 @@ function getFragmentFromContext(context) {
38
38
  // eslint-disable-next-line prefer-destructuring
39
39
  const settings = context.settings;
40
40
  const fragment = settings.react?.fragment;
41
- if (Pred.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
41
+ if (P.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
42
42
  return fragment;
43
43
  }
44
44
  return "Fragment";
@@ -48,16 +48,14 @@ const getPragmaFromContext = memo((context)=>{
48
48
  const settings = context.settings;
49
49
  const sourceCode = context.getSourceCode();
50
50
  const pragmaNode = sourceCode.getAllComments().find((node)=>RE_JSX_ANNOTATION_REGEX.test(node.value));
51
- return F.pipe(O$1.orElse(O$1.fromNullable(settings.react?.pragma), ()=>F.pipe(O$1.fromNullable(pragmaNode), O$1.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), O$1.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), O$1.flatMap(O$1.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), O$1.getOrElse(F.constant("React")));
51
+ return F.pipe(O.orElse(O.fromNullable(settings.react?.pragma), ()=>F.pipe(O.fromNullable(pragmaNode), O.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), O.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), O.flatMap(O.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), O.getOrElse(F.constant("React")));
52
52
  });
53
53
 
54
- const t=Symbol.for("@ts-pattern/matcher"),e=Symbol.for("@ts-pattern/isVariadic"),n="@ts-pattern/anonymous-select-key",r=t=>Boolean(t&&"object"==typeof t),i=e=>e&&!!e[t],s=(n,o,c)=>{if(i(n)){const e=n[t](),{matched:r,selections:i}=e.match(o);return r&&i&&Object.keys(i).forEach(t=>c(t,i[t])),r}if(r(n)){if(!r(o))return !1;if(Array.isArray(n)){if(!Array.isArray(o))return !1;let t=[],r=[],a=[];for(const s of n.keys()){const o=n[s];i(o)&&o[e]?a.push(o):a.length?r.push(o):t.push(o);}if(a.length){if(a.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(o.length<t.length+r.length)return !1;const e=o.slice(0,t.length),n=0===r.length?[]:o.slice(-r.length),i=o.slice(t.length,0===r.length?Infinity:-r.length);return t.every((t,n)=>s(t,e[n],c))&&r.every((t,e)=>s(t,n[e],c))&&(0===a.length||s(a[0],i,c))}return n.length===o.length&&n.every((t,e)=>s(t,o[e],c))}return Object.keys(n).every(e=>{const r=n[e];return (e in o||i(a=r)&&"optional"===a[t]().matcherType)&&s(r,o[e],c);var a;})}return Object.is(o,n)},o=e=>{var n,s,a;return r(e)?i(e)?null!=(n=null==(s=(a=e[t]()).getSelectionKeys)?void 0:s.call(a))?n:[]:Array.isArray(e)?c(e,o):c(Object.values(e),o):[]},c=(t,e)=>t.reduce((t,n)=>t.concat(e(n)),[]);function a(...t){if(1===t.length){const[e]=t;return t=>s(e,t,()=>{})}if(2===t.length){const[e,n]=t;return s(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function u(t){return Object.assign(t,{optional:()=>l(t),and:e=>m(t,e),or:e=>y(t,e),select:e=>void 0===e?p(t):p(e,t)})}function h(t){return Object.assign((t=>Object.assign(t,{*[Symbol.iterator](){yield Object.assign(t,{[e]:!0});}}))(t),{optional:()=>h(l(t)),select:e=>h(void 0===e?p(t):p(e,t))})}function l(e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return void 0===t?(o(e).forEach(t=>r(t,void 0)),{matched:!0,selections:n}):{matched:s(e,t,r),selections:n}},getSelectionKeys:()=>o(e),matcherType:"optional"})})}const f=(t,e)=>{for(const n of t)if(!e(n))return !1;return !0},g=(t,e)=>{for(const[n,r]of t.entries())if(!e(r,n))return !1;return !0};function m(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return {matched:e.every(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"and"})})}function y(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return c(e,o).forEach(t=>r(t,void 0)),{matched:e.some(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"or"})})}function d(e){return {[t]:()=>({match:t=>({matched:Boolean(e(t))})})}}function p(...e){const r="string"==typeof e[0]?e[0]:void 0,i=2===e.length?e[1]:"string"==typeof e[0]?void 0:e[0];return u({[t]:()=>({match:t=>{let e={[null!=r?r:n]:t};return {matched:void 0===i||s(i,t,(t,n)=>{e[t]=n;}),selections:e}},getSelectionKeys:()=>[null!=r?r:n].concat(void 0===i?[]:o(i))})})}function v(t){return "number"==typeof t}function b(t){return "string"==typeof t}function w(t){return "bigint"==typeof t}const S=u(d(function(t){return !0})),O=S,j=t=>Object.assign(u(t),{startsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.startsWith(n)))));var n;},endsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.endsWith(n)))));var n;},minLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length>=t))(e))),maxLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length<=t))(e))),includes:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.includes(n)))));var n;},regex:e=>{return j(m(t,(n=e,d(t=>b(t)&&Boolean(t.match(n))))));var n;}}),E=j(d(b)),K=t=>Object.assign(u(t),{between:(e,n)=>K(m(t,((t,e)=>d(n=>v(n)&&t<=n&&e>=n))(e,n))),lt:e=>K(m(t,(t=>d(e=>v(e)&&e<t))(e))),gt:e=>K(m(t,(t=>d(e=>v(e)&&e>t))(e))),lte:e=>K(m(t,(t=>d(e=>v(e)&&e<=t))(e))),gte:e=>K(m(t,(t=>d(e=>v(e)&&e>=t))(e))),int:()=>K(m(t,d(t=>v(t)&&Number.isInteger(t)))),finite:()=>K(m(t,d(t=>v(t)&&Number.isFinite(t)))),positive:()=>K(m(t,d(t=>v(t)&&t>0))),negative:()=>K(m(t,d(t=>v(t)&&t<0)))}),A=K(d(v)),x=t=>Object.assign(u(t),{between:(e,n)=>x(m(t,((t,e)=>d(n=>w(n)&&t<=n&&e>=n))(e,n))),lt:e=>x(m(t,(t=>d(e=>w(e)&&e<t))(e))),gt:e=>x(m(t,(t=>d(e=>w(e)&&e>t))(e))),lte:e=>x(m(t,(t=>d(e=>w(e)&&e<=t))(e))),gte:e=>x(m(t,(t=>d(e=>w(e)&&e>=t))(e))),positive:()=>x(m(t,d(t=>w(t)&&t>0))),negative:()=>x(m(t,d(t=>w(t)&&t<0)))}),P=x(d(w)),T=u(d(function(t){return "boolean"==typeof t})),k=u(d(function(t){return "symbol"==typeof t})),B=u(d(function(t){return null==t}));var _={__proto__:null,matcher:t,optional:l,array:function(...e){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return {matched:!1};if(0===e.length)return {matched:!0};const n=e[0];let r={};if(0===t.length)return o(n).forEach(t=>{r[t]=[];}),{matched:!0,selections:r};const i=(t,e)=>{r[t]=(r[t]||[]).concat([e]);};return {matched:t.every(t=>s(n,t,i)),selections:r}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},set:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Set))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};if(0===e.length)return {matched:!0};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);},i=e[0];return {matched:f(t,t=>s(i,t,r)),selections:n}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},map:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Map))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);};if(0===e.length)return {matched:!0};var i;if(1===e.length)throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null==(i=e[0])?void 0:i.toString()}`);const[o,c]=e;return {matched:g(t,(t,e)=>{const n=s(o,e,r),i=s(c,t,r);return n&&i}),selections:n}},getSelectionKeys:()=>0===e.length?[]:[...o(e[0]),...o(e[1])]})})},intersection:m,union:y,not:function(e){return u({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:d,select:p,any:S,_:O,string:E,number:A,bigint:P,boolean:T,symbol:k,nullish:B,instanceOf:function(t){return u(d(function(t){return e=>e instanceof t}(t)))},shape:function(t){return u(d(a(t)))}};const W={matched:!1,value:void 0};function N(t){return new $(t,W)}class ${constructor(t,e){this.input=void 0,this.state=void 0,this.input=t,this.state=e;}with(...t){if(this.state.matched)return this;const e=t[t.length-1],r=[t[0]];let i;3===t.length&&"function"==typeof t[1]?i=t[1]:t.length>2&&r.push(...t.slice(1,t.length-1));let o=!1,c={};const a=(t,e)=>{o=!0,c[t]=e;},u=!r.some(t=>s(t,this.input,a))||i&&!Boolean(i(this.input))?W:{matched:!0,value:e(o?n in c?c[n]:c:this.input,this.input)};return new $(this.input,u)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new $(this.input,n?{matched:!0,value:e(this.input,this.input)}:W)}otherwise(t){return this.state.matched?this.state.value:t(this.input)}exhaustive(){if(this.state.matched)return this.state.value;let t;try{t=JSON.stringify(this.input);}catch(e){t=this.input;}throw new Error(`Pattern matching error: no pattern matches value ${t}`)}run(){return this.exhaustive()}returnType(){return this}}
55
-
56
54
  function isInitializedFromPragma(variableName, context, pragma = getPragmaFromContext(context)) {
57
55
  const variables = getVariablesUpToGlobal(context.getScope());
58
56
  const maybeVariable = findVariableByName(variableName)(variables);
59
- const maybeLatestDef = O$1.flatMapNullable(maybeVariable, (variable)=>variable.defs.at(-1));
60
- if (O$1.isNone(maybeLatestDef)) {
57
+ const maybeLatestDef = O.flatMapNullable(maybeVariable, (variable)=>variable.defs.at(-1));
58
+ if (O.isNone(maybeLatestDef)) {
61
59
  return false;
62
60
  }
63
61
  const latestDef = maybeLatestDef.value;
@@ -65,7 +63,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
65
63
  if (node.type === NodeType.VariableDeclarator && node.init) {
66
64
  const { init } = node;
67
65
  // check for: `variable = pragma.variable`
68
- if (a({
66
+ if (M.isMatching({
69
67
  type: "MemberExpression",
70
68
  object: {
71
69
  type: "Identifier",
@@ -75,20 +73,20 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
75
73
  return true;
76
74
  }
77
75
  // check for: `{ variable } = pragma`
78
- if (a({
76
+ if (M.isMatching({
79
77
  type: "Identifier",
80
78
  name: pragma
81
79
  }, init)) {
82
80
  return true;
83
81
  }
84
82
  // check if from a require call: `require("react")`
85
- const maybeRequireExpression = N(init).with({
83
+ const maybeRequireExpression = M.match(init).with({
86
84
  type: NodeType.CallExpression,
87
85
  callee: {
88
86
  type: NodeType.Identifier,
89
87
  name: "require"
90
88
  }
91
- }, (exp)=>O$1.some(exp)).with({
89
+ }, (exp)=>O.some(exp)).with({
92
90
  type: NodeType.MemberExpression,
93
91
  object: {
94
92
  type: NodeType.CallExpression,
@@ -97,8 +95,8 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
97
95
  name: "require"
98
96
  }
99
97
  }
100
- }, ({ object })=>O$1.some(object)).otherwise(O$1.none);
101
- if (O$1.isNone(maybeRequireExpression)) {
98
+ }, ({ object })=>O.some(object)).otherwise(O.none);
99
+ if (O.isNone(maybeRequireExpression)) {
102
100
  return false;
103
101
  }
104
102
  const requireExpression = maybeRequireExpression.value;
@@ -109,7 +107,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
109
107
  return firstArg.value === pragma.toLowerCase();
110
108
  }
111
109
  // latest definition is an import declaration: import { variable } from 'react'
112
- return a({
110
+ return M.isMatching({
113
111
  type: "ImportDeclaration",
114
112
  source: {
115
113
  value: pragma.toLowerCase()
@@ -117,7 +115,7 @@ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromCo
117
115
  }, parent);
118
116
  }
119
117
  function isPropertyOfPragma(name, context, pragma = getPragmaFromContext(context)) {
120
- const isMatch = a({
118
+ const isMatch = M.isMatching({
121
119
  type: NodeType.MemberExpression,
122
120
  object: {
123
121
  type: NodeType.Identifier,
@@ -167,7 +165,7 @@ function isPropertyOfPragma(name, context, pragma = getPragmaFromContext(context
167
165
  * @param context The rule context
168
166
  * @returns `true` if the node is inside createElement's props
169
167
  */ function isInsideCreateElementProps(node, context) {
170
- return F.pipe(traverseUp(node, (n)=>isCreateElementCall(n, context)), O$1.filter(is(NodeType.CallExpression)), O$1.flatMapNullable((c)=>c.arguments.at(1)), O$1.filter(is(NodeType.ObjectExpression)), O$1.zipWith(traverseUp(node, is(NodeType.ObjectExpression)), (a, b)=>a === b), O$1.getOrElse(F.constFalse));
168
+ return F.pipe(traverseUp(node, (n)=>isCreateElementCall(n, context)), O.filter(is(NodeType.CallExpression)), O.flatMapNullable((c)=>c.arguments.at(1)), O.filter(is(NodeType.ObjectExpression)), O.zipWith(traverseUp(node, is(NodeType.ObjectExpression)), (a, b)=>a === b), O.getOrElse(F.constFalse));
171
169
  }
172
170
  function isChildrenOfCreateElement(node, context) {
173
171
  const maybeCallExpression = node.parent;
@@ -386,7 +384,7 @@ const isFragment = (node, pragma, fragment)=>{
386
384
  if (!node) {
387
385
  return false;
388
386
  }
389
- return N(node).with({
387
+ return M.match(node).with({
390
388
  type: NodeType.JSXElement
391
389
  }, F.constTrue).with({
392
390
  type: NodeType.JSXFragment
@@ -397,7 +395,7 @@ const isFragment = (node, pragma, fragment)=>{
397
395
  }, F.constTrue).with({
398
396
  type: NodeType.Literal
399
397
  }, (node)=>{
400
- return N(node.value).with(null, ()=>!(hint & JSXValueCheckHint.SkipNullLiteral)).with(_.boolean, ()=>!(hint & JSXValueCheckHint.SkipBooleanLiteral)).with(_.string, ()=>!(hint & JSXValueCheckHint.SkipStringLiteral)).with(_.number, ()=>!(hint & JSXValueCheckHint.SkipNumberLiteral)).otherwise(F.constFalse);
398
+ return M.match(node.value).with(null, ()=>!(hint & JSXValueCheckHint.SkipNullLiteral)).with(M.P.boolean, ()=>!(hint & JSXValueCheckHint.SkipBooleanLiteral)).with(M.P.string, ()=>!(hint & JSXValueCheckHint.SkipStringLiteral)).with(M.P.number, ()=>!(hint & JSXValueCheckHint.SkipNumberLiteral)).otherwise(F.constFalse);
401
399
  }).with({
402
400
  type: NodeType.TemplateLiteral
403
401
  }, ()=>{
@@ -455,7 +453,7 @@ const isFragment = (node, pragma, fragment)=>{
455
453
  return true;
456
454
  }
457
455
  const maybeVariable = findVariableByNameUpToGlobal(name, context.getScope());
458
- return F.pipe(maybeVariable, O$1.flatMap(getVariableInit(0)), O$1.exists((n)=>isJSXValue(n, context, hint)));
456
+ return F.pipe(maybeVariable, O.flatMap(getVariableInit(0)), O.exists((n)=>isJSXValue(n, context, hint)));
459
457
  }).otherwise(F.constFalse);
460
458
  }
461
459
 
@@ -478,7 +476,7 @@ const isFragment = (node, pragma, fragment)=>{
478
476
  * @param node The JSX attribute node
479
477
  * @returns string
480
478
  */ function getPropName(node) {
481
- return N(node.name).when(is(NodeType.JSXIdentifier), (n)=>n.name).when(is(NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
479
+ return M.match(node.name).when(is(NodeType.JSXIdentifier), (n)=>n.name).when(is(NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
482
480
  }
483
481
  function getProp(props, propName, context) {
484
482
  return findPropInAttributes(props, context)(propName);
@@ -493,18 +491,18 @@ function getProp(props, propName, context) {
493
491
  if (attribute.type === NodeType.JSXAttribute && "value" in attribute) {
494
492
  const { value } = attribute;
495
493
  if (value === null) {
496
- return O$1.none();
494
+ return O.none();
497
495
  }
498
496
  if (value.type === NodeType.Literal) {
499
- return O$1.some(getStaticValue(value, scope));
497
+ return O.some(getStaticValue(value, scope));
500
498
  }
501
499
  if (value.type === NodeType.JSXExpressionContainer) {
502
- return O$1.some(getStaticValue(value.expression, scope));
500
+ return O.some(getStaticValue(value.expression, scope));
503
501
  }
504
- return O$1.none();
502
+ return O.none();
505
503
  }
506
504
  const { argument } = attribute;
507
- return O$1.some(getStaticValue(argument, scope));
505
+ return O.some(getStaticValue(argument, scope));
508
506
  }
509
507
  /**
510
508
  * @param properties The properties to search in
@@ -518,14 +516,14 @@ function getProp(props, propName, context) {
518
516
  * @param propName The name of the property to search for
519
517
  * @returns The property if found
520
518
  */ return (propName)=>{
521
- return O$1.fromNullable(properties.find((prop)=>{
522
- return N(prop).when(is(NodeType.Property), (prop)=>{
519
+ return O.fromNullable(properties.find((prop)=>{
520
+ return M.match(prop).when(is(NodeType.Property), (prop)=>{
523
521
  return "name" in prop.key && prop.key.name === propName;
524
522
  }).when(is(NodeType.SpreadElement), (prop)=>{
525
- return N(prop.argument).when(is(NodeType.Identifier), (argument)=>{
523
+ return M.match(prop.argument).when(is(NodeType.Identifier), (argument)=>{
526
524
  const { name } = argument;
527
- const maybeInit = O$1.flatMap(findVariableByNameUpToGlobal(name, startScope), getVariableInit(0));
528
- if (O$1.isNone(maybeInit)) {
525
+ const maybeInit = O.flatMap(findVariableByNameUpToGlobal(name, startScope), getVariableInit(0));
526
+ if (O.isNone(maybeInit)) {
529
527
  return false;
530
528
  }
531
529
  const init = maybeInit.value;
@@ -535,12 +533,12 @@ function getProp(props, propName, context) {
535
533
  if (seenProps.includes(name)) {
536
534
  return false;
537
535
  }
538
- return O$1.isSome(findPropInProperties(init.properties, context, [
536
+ return O.isSome(findPropInProperties(init.properties, context, [
539
537
  ...seenProps,
540
538
  name
541
539
  ])(propName));
542
540
  }).when(is(NodeType.ObjectExpression), (argument)=>{
543
- return O$1.isSome(findPropInProperties(argument.properties, context, seenProps)(propName));
541
+ return O.isSome(findPropInProperties(argument.properties, context, seenProps)(propName));
544
542
  }).when(is(NodeType.MemberExpression), ()=>{
545
543
  // Not implemented
546
544
  }).when(is(NodeType.CallExpression), ()=>{
@@ -564,23 +562,23 @@ function getProp(props, propName, context) {
564
562
  * @param propName The name of the property to search for
565
563
  * @returns The property if found
566
564
  */ return (propName)=>{
567
- return O$1.fromNullable(attributes.find((attr)=>{
568
- return N(attr).when(is(NodeType.JSXAttribute), (attr)=>getPropName(attr) === propName).when(is(NodeType.JSXSpreadAttribute), (attr)=>{
569
- return N(attr.argument).with({
565
+ return O.fromNullable(attributes.find((attr)=>{
566
+ return M.match(attr).when(is(NodeType.JSXAttribute), (attr)=>getPropName(attr) === propName).when(is(NodeType.JSXSpreadAttribute), (attr)=>{
567
+ return M.match(attr.argument).with({
570
568
  type: NodeType.Identifier
571
569
  }, (argument)=>{
572
570
  const { name } = argument;
573
- const maybeInit = O$1.flatMap(findVariableByNameUpToGlobal(name, startScope), getVariableInit(0));
574
- if (O$1.isNone(maybeInit)) {
571
+ const maybeInit = O.flatMap(findVariableByNameUpToGlobal(name, startScope), getVariableInit(0));
572
+ if (O.isNone(maybeInit)) {
575
573
  return false;
576
574
  }
577
575
  const init = maybeInit.value;
578
576
  if (!("properties" in init)) {
579
577
  return false;
580
578
  }
581
- return O$1.isSome(findPropInProperties(init.properties, context)(propName));
579
+ return O.isSome(findPropInProperties(init.properties, context)(propName));
582
580
  }).when(is(NodeType.ObjectExpression), (argument)=>{
583
- return O$1.isSome(findPropInProperties(argument.properties, context)(propName));
581
+ return O.isSome(findPropInProperties(argument.properties, context)(propName));
584
582
  }).when(is(NodeType.MemberExpression), ()=>{
585
583
  // Not implemented
586
584
  return false;
@@ -600,7 +598,7 @@ function getProp(props, propName, context) {
600
598
  * @param context The rule context
601
599
  * @returns `true` if the given prop name is present in the given properties
602
600
  */ function hasProp(attributes, propName, context) {
603
- return O$1.isSome(findPropInAttributes(attributes, context)(propName));
601
+ return O.isSome(findPropInAttributes(attributes, context)(propName));
604
602
  }
605
603
  /**
606
604
  * Check if any of the given prop names are present in the given attributes
@@ -641,7 +639,7 @@ function getProp(props, propName, context) {
641
639
  if (isStringLiteral(node)) {
642
640
  return node.parent.type === NodeType.JSXAttribute;
643
641
  }
644
- return O$1.isSome(traverseUpProp(node, (n)=>n.value?.type === NodeType.JSXExpressionContainer));
642
+ return O.isSome(traverseUpProp(node, (n)=>n.value?.type === NodeType.JSXExpressionContainer));
645
643
  }
646
644
 
647
645
  /**
@@ -657,7 +655,7 @@ function getProp(props, propName, context) {
657
655
  * @param node The AST node to check
658
656
  * @returns boolean `true` if the node is whitespace
659
657
  */ function isWhiteSpace(node) {
660
- return Pred.isString(node.value) && node.value.trim() === "";
658
+ return P.isString(node.value) && node.value.trim() === "";
661
659
  }
662
660
  /**
663
661
  * Check if a Literal or JSXText node is a line break
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "0.9.1-beta.1",
3
+ "version": "0.9.1-beta.3",
4
4
  "description": "ESLint x React's TSESTree AST utility module for static analysis of JSX.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -34,14 +34,14 @@
34
34
  "./package.json"
35
35
  ],
36
36
  "dependencies": {
37
- "@typescript-eslint/scope-manager": "6.13.1",
38
- "@typescript-eslint/types": "6.13.1",
39
- "@typescript-eslint/utils": "6.13.1",
37
+ "@typescript-eslint/scope-manager": "6.13.2",
38
+ "@typescript-eslint/types": "6.13.2",
39
+ "@typescript-eslint/utils": "6.13.2",
40
40
  "micro-memoize": "4.1.2",
41
- "@eslint-react/ast": "0.9.1-beta.1",
42
- "@eslint-react/tools": "0.9.1-beta.1",
43
- "@eslint-react/shared": "0.9.1-beta.1",
44
- "@eslint-react/types": "0.9.1-beta.1"
41
+ "@eslint-react/ast": "0.9.1-beta.3",
42
+ "@eslint-react/types": "0.9.1-beta.3",
43
+ "@eslint-react/shared": "0.9.1-beta.3",
44
+ "@eslint-react/tools": "0.9.1-beta.3"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "rollup -c rollup.config.ts --configPlugin swc3 && cp dist/index.d.ts dist/index.d.mts",