eslint-plugin-strict-pattern-matching
Version:
prevent using non-exhaustive pattern matching in typescript
2 lines (1 loc) • 3.56 kB
JavaScript
"use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var r in e)o(t,r,{get:e[r],enumerable:!0})},f=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of E(e))!x.call(t,s)&&s!==r&&o(t,s,{get:()=>e[s],enumerable:!(i=u(e,s))||i.enumerable});return t};var M=t=>f(o({},"__esModule",{value:!0}),t);var S={};y(S,{rules:()=>b});module.exports=M(S);var c=require("@typescript-eslint/utils"),p=require("@typescript-eslint/utils"),m=require("ts-pattern"),I=c.ESLintUtils.RuleCreator(t=>`https://https://github.com/JUSTIVE/strict-pattern-matching#${t}`),U=()=>{},w=I({create(t){return{CallExpression:e=>{(0,m.match)(e).with({callee:{type:p.AST_NODE_TYPES.MemberExpression,property:{type:p.AST_NODE_TYPES.Identifier,name:"exhaustive"}},arguments:[]},()=>{t.report({node:e,messageId:"noUnhandledExhaustiveException"})}).otherwise(U)}}},name:"no-unhandled-exhaustive-exception",meta:{type:"suggestion",messages:{noUnhandledExhaustiveException:"exhaustive()\uB97C \uC0AC\uC6A9\uD560 \uB54C\uC5D0\uB294 \uB7F0\uD0C0\uC784\uC5D0 \uBC1C\uC0DD\uD560 \uC218 \uC788\uB294 \uC608\uC678\uB97C \uBA85\uC2DC\uC801\uC73C\uB85C \uB2E4\uB8E8\uC5B4\uC57C \uD569\uB2C8\uB2E4."},schema:[],docs:{description:"no unhandled exhaustive's exception in pattern matching",recommended:"error"}},defaultOptions:[]}),l=w;var d=require("@typescript-eslint/utils"),n=require("@typescript-eslint/utils"),a=require("ts-pattern"),P=d.ESLintUtils.RuleCreator(t=>`https://https://github.com/JUSTIVE/strict-pattern-matching#${t}`),h=()=>{},v=P({create(t){return{CallExpression:e=>{(0,a.match)(e).with({callee:{type:n.AST_NODE_TYPES.MemberExpression,property:{type:n.AST_NODE_TYPES.Identifier,name:"run"}}},()=>{function r(i){return i.type===n.AST_NODE_TYPES.MemberExpression?r(i.object):i.type===n.AST_NODE_TYPES.CallExpression?i.callee.type===n.AST_NODE_TYPES.Identifier?i.callee.name==="match":r(i.callee):!1}r(e)&&t.report({node:e,messageId:"noRunEndingPatternMatching"})}).with({arguments:[{type:n.AST_NODE_TYPES.CallExpression,callee:{type:n.AST_NODE_TYPES.MemberExpression,property:{type:n.AST_NODE_TYPES.Identifier,name:"with"}}}]},()=>{t.report({node:e,messageId:"noUnFinishedPatternMatching"})}).otherwise(h)},ExpressionStatement:e=>{(0,a.match)(e).with({expression:{type:n.AST_NODE_TYPES.CallExpression,callee:{type:n.AST_NODE_TYPES.MemberExpression,property:{type:n.AST_NODE_TYPES.Identifier,name:"with"}}}},()=>{t.report({node:e,messageId:"noUnFinishedPatternMatching"})}).otherwise(h)},VariableDeclarator:e=>{(0,a.match)(e).with({init:{type:n.AST_NODE_TYPES.CallExpression,callee:{type:n.AST_NODE_TYPES.MemberExpression,property:{type:n.AST_NODE_TYPES.Identifier,name:"with"}}}},()=>{t.report({node:e,messageId:"noUnFinishedPatternMatching"})}).otherwise(h)}}},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:[]}),g=v;var b={strictPatternMatching:g,noUnhandledExhaustiveException:l};0&&(module.exports={rules});