UNPKG

eslint-plugin-strict-pattern-matching

Version:

prevent using non-exhaustive pattern matching in typescript

2 lines (1 loc) 1.93 kB
import{ESLintUtils as p}from"@typescript-eslint/utils";import{AST_NODE_TYPES as e}from"@typescript-eslint/utils";import{match as s}from"ts-pattern";var c=p.RuleCreator(n=>`https://https://github.com/JUSTIVE/strict-pattern-matching#${n}`),a=()=>{},h=c({create(n){return{CallExpression:function(t){s(t).with({callee:{type:e.MemberExpression,property:{type:e.Identifier,name:"run"}}},()=>{function r(i){return i.type===e.MemberExpression?r(i.object):i.type===e.CallExpression?i.callee.type===e.Identifier?i.callee.name==="match":r(i.callee):!1}r(t)&&n.report({node:t,messageId:"noRunEndingPatternMatching"})}).with({arguments:[{type:e.CallExpression,callee:{type:e.MemberExpression,property:{type:e.Identifier,name:"with"}}}]},()=>{n.report({node:t,messageId:"noUnFinishedPatternMatching"})}).otherwise(a)},ExpressionStatement:function(t){s(t).with({expression:{type:e.CallExpression,callee:{type:e.MemberExpression,property:{type:e.Identifier,name:"with"}}}},()=>{n.report({node:t,messageId:"noUnFinishedPatternMatching"})}).otherwise(a)},VariableDeclarator:function(t){s(t).with({init:{type:e.CallExpression,callee:{type:e.MemberExpression,property:{type:e.Identifier,name:"with"}}}},()=>{n.report({node:t,messageId:"noUnFinishedPatternMatching"})}).otherwise(a)}}},name:"strict-pattern-matching",meta:{type:"suggestion",messages:{noRunEndingPatternMatching:"\uD328\uD134 \uB9E4\uCE6D\uC740 run\uC73C\uB85C \uB05D\uB098\uC9C0 \uC54A\uC544\uC57C \uD569\uB2C8\uB2E4. exhastive(), otherwise()\uB97C \uC0AC\uC6A9\uD574\uC8FC\uC138\uC694",noUnFinishedPatternMatching:"\uD328\uD134 \uB9E4\uCE6D\uC740 \uB05D\uB098\uC9C0 \uC54A\uC740 \uC0C1\uD0DC\uB85C \uB450\uBA74 \uC548\uB429\uB2C8\uB2E4. exhastive(), otherwise()\uB97C \uC0AC\uC6A9\uD574\uC8FC\uC138\uC694"},fixable:"code",schema:[],docs:{description:"no unexhaustive pattern matching",recommended:"error"}},defaultOptions:[]}),o=h;var y={strictPatternMatching:o};export{y as rules};