eslint-plugin-justive-better-ts-belt
Version:
prevent using non-exhaustive pattern matching in typescript
2 lines (1 loc) • 3.76 kB
JavaScript
import{ESLintUtils as d}from"@typescript-eslint/utils";import{AST_NODE_TYPES as r}from"@typescript-eslint/utils";import{P as s,match as g}from"ts-pattern";var y=d.RuleCreator(t=>`https://https://github.com/JUSTIVE/justive-better-ts-belt#${t}`),F=()=>{},l={type:r.MemberExpression,object:{type:r.Identifier,name:s.union("A","B","F","G","N","O","R","S")},property:{type:r.Identifier,name:s.not(s.union("fromExecution","fromPromise","fromNullable"))}},S=y({create(t){return{CallExpression:function(n){g(n).with({callee:{type:r.Identifier,name:"pipe"},arguments:[s.union({type:s.union(r.Identifier,r.MemberExpression)}),s.union({type:r.CallExpression,callee:l},l)]},i=>{let a=i.arguments[0].loc.end.line-i.arguments[0].loc.start.line,f=i.arguments[0].range[1]-i.arguments[0].range[0];(a<=1||f>20)&&t.report({node:n,messageId:"noPipeForSingleFunction"})}).otherwise(F)}}},name:"noPipeForSingleFunction",meta:{type:"suggestion",messages:{noPipeForSingleFunction:"Pipe function with single ts-belt's function could be used as data-first function."},fixable:"code",schema:[],docs:{description:"no pipe function with single ts-belt's function.",recommended:"error"}},defaultOptions:[]}),p=S;import{ESLintUtils as b}from"@typescript-eslint/utils";import{AST_NODE_TYPES as e}from"@typescript-eslint/utils";import{P as o,match as h}from"ts-pattern";var I=b.RuleCreator(t=>`https://https://github.com/JUSTIVE/justive-better-ts-belt#${t}`),E=()=>{},c={type:e.MemberExpression,object:{type:e.Identifier,name:o.union("A","B","F","G","N","O","R","S")},property:{type:e.Identifier,name:o.not(o.union("fromExecution","fromPromise","fromNullable"))}},w=I({create(t){return{VariableDeclaration:function(n){h(n).with({declarations:[{type:e.VariableDeclarator,init:{type:e.ArrowFunctionExpression,params:[{type:e.Identifier,name:o.select("argumentSymbol")}],body:{type:e.CallExpression,callee:{type:e.Identifier,name:"pipe"},arguments:[{type:e.Identifier,name:o.select("firstFeedValue")},{type:e.CallExpression,callee:c}]}}}]},({argumentSymbol:i,firstFeedValue:a})=>{a===i&&t.report({node:n,messageId:"preferTacitStylePipe"})}).with({declarations:[{type:e.VariableDeclarator,init:{type:e.ArrowFunctionExpression,params:[{type:e.Identifier,name:o.select("argumentSymbol")}],body:{type:e.CallExpression,callee:c,arguments:[{type:e.Identifier,name:o.select("firstFeedValue")},o.union({type:e.Identifier},{type:e.Literal})]}}}]},({argumentSymbol:i,firstFeedValue:a})=>{a===i&&t.report({node:n,messageId:"preferTacitStyle"})}).otherwise(E)}}},name:"preferTacitStyle",meta:{type:"suggestion",messages:{preferTacitStyle:"This lambda is safe to be removed. Use the function directly instead.",preferTacitStylePipe:"This lambda and pipe function is safe to be removed. Use the function directly instead."},fixable:"code",schema:[],docs:{description:"prefer tacit style programming.",recommended:"error"}},defaultOptions:[]}),m=w;import{ESLintUtils as P}from"@typescript-eslint/utils";import{AST_NODE_TYPES as T}from"@typescript-eslint/utils";import{P as x,match as O}from"ts-pattern";var C=P.RuleCreator(t=>`https://https://github.com/JUSTIVE/justive-better-ts-belt#${t}`),M=()=>{},U=C({create(t){return{CallExpression:function(n){O(n).with({callee:{type:T.Identifier,name:"flow"},arguments:[x._]},()=>{t.report({node:n,messageId:"noFlowForSingleFunction"})}).otherwise(M)}}},name:"noFlowForSingleFunction",meta:{type:"suggestion",messages:{noFlowForSingleFunction:"Flow function with single ts-belt's function is abundant. Use the function directly."},fixable:"code",schema:[],docs:{description:"no flow function with single ts-belt's function.",recommended:"error"}},defaultOptions:[]}),u=U;var q={noPipeForSingleFunction:p,preferTacitStyle:m,noFlowForSingleFunction:u};export{q as rules};