UNPKG

eslint-plugin-justive-better-ts-belt

Version:

prevent using non-exhaustive pattern matching in typescript

2 lines (1 loc) 4.55 kB
"use strict";var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var w=(e,t)=>{for(var i in t)c(e,i,{get:t[i],enumerable:!0})},P=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of I(t))!E.call(e,l)&&l!==i&&c(e,l,{get:()=>t[l],enumerable:!(s=h(t,l))||s.enumerable});return e};var T=e=>P(c({},"__esModule",{value:!0}),e);var j={};w(j,{rules:()=>N});module.exports=T(j);var u=require("@typescript-eslint/utils"),a=require("@typescript-eslint/utils"),r=require("ts-pattern"),x=u.ESLintUtils.RuleCreator(e=>`https://https://github.com/JUSTIVE/justive-better-ts-belt#${e}`),O=()=>{},m={type:a.AST_NODE_TYPES.MemberExpression,object:{type:a.AST_NODE_TYPES.Identifier,name:r.P.union("A","B","F","G","N","O","R","S")},property:{type:a.AST_NODE_TYPES.Identifier,name:r.P.not(r.P.union("fromExecution","fromPromise","fromNullable"))}},C=x({create(e){return{CallExpression:function(t){(0,r.match)(t).with({callee:{type:a.AST_NODE_TYPES.Identifier,name:"pipe"},arguments:[r.P.union({type:r.P.union(a.AST_NODE_TYPES.Identifier,a.AST_NODE_TYPES.MemberExpression)}),r.P.union({type:a.AST_NODE_TYPES.CallExpression,callee:m},m)]},i=>{let s=i.arguments[0].loc.end.line-i.arguments[0].loc.start.line,l=i.arguments[0].range[1]-i.arguments[0].range[0];(s<=1||l>20)&&e.report({node:t,messageId:"noPipeForSingleFunction"})}).otherwise(O)}}},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:[]}),f=C;var g=require("@typescript-eslint/utils"),n=require("@typescript-eslint/utils"),o=require("ts-pattern"),M=g.ESLintUtils.RuleCreator(e=>`https://https://github.com/JUSTIVE/justive-better-ts-belt#${e}`),U=()=>{},d={type:n.AST_NODE_TYPES.MemberExpression,object:{type:n.AST_NODE_TYPES.Identifier,name:o.P.union("A","B","F","G","N","O","R","S")},property:{type:n.AST_NODE_TYPES.Identifier,name:o.P.not(o.P.union("fromExecution","fromPromise","fromNullable"))}},D=M({create(e){return{VariableDeclaration:function(t){(0,o.match)(t).with({declarations:[{type:n.AST_NODE_TYPES.VariableDeclarator,init:{type:n.AST_NODE_TYPES.ArrowFunctionExpression,params:[{type:n.AST_NODE_TYPES.Identifier,name:o.P.select("argumentSymbol")}],body:{type:n.AST_NODE_TYPES.CallExpression,callee:{type:n.AST_NODE_TYPES.Identifier,name:"pipe"},arguments:[{type:n.AST_NODE_TYPES.Identifier,name:o.P.select("firstFeedValue")},{type:n.AST_NODE_TYPES.CallExpression,callee:d}]}}}]},({argumentSymbol:i,firstFeedValue:s})=>{s===i&&e.report({node:t,messageId:"preferTacitStylePipe"})}).with({declarations:[{type:n.AST_NODE_TYPES.VariableDeclarator,init:{type:n.AST_NODE_TYPES.ArrowFunctionExpression,params:[{type:n.AST_NODE_TYPES.Identifier,name:o.P.select("argumentSymbol")}],body:{type:n.AST_NODE_TYPES.CallExpression,callee:d,arguments:[{type:n.AST_NODE_TYPES.Identifier,name:o.P.select("firstFeedValue")},o.P.union({type:n.AST_NODE_TYPES.Identifier},{type:n.AST_NODE_TYPES.Literal})]}}}]},({argumentSymbol:i,firstFeedValue:s})=>{s===i&&e.report({node:t,messageId:"preferTacitStyle"})}).otherwise(U)}}},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:[]}),y=D;var F=require("@typescript-eslint/utils"),S=require("@typescript-eslint/utils"),p=require("ts-pattern"),R=F.ESLintUtils.RuleCreator(e=>`https://https://github.com/JUSTIVE/justive-better-ts-belt#${e}`),V=()=>{},A=R({create(e){return{CallExpression:function(t){(0,p.match)(t).with({callee:{type:S.AST_NODE_TYPES.Identifier,name:"flow"},arguments:[p.P._]},()=>{e.report({node:t,messageId:"noFlowForSingleFunction"})}).otherwise(V)}}},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:[]}),b=A;var N={noPipeForSingleFunction:f,preferTacitStyle:y,noFlowForSingleFunction:b};0&&(module.exports={rules});