eslint-plugin-strict-pattern-matching
Version:
prevent using non-exhaustive pattern matching in typescript
2 lines (1 loc) • 2.62 kB
JavaScript
"use strict";var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var u=(n,e)=>{for(var r in e)o(n,r,{get:e[r],enumerable:!0})},d=(n,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of m(e))!g.call(n,s)&&s!==r&&o(n,s,{get:()=>e[s],enumerable:!(i=l(e,s))||i.enumerable});return n};var y=n=>d(o({},"__esModule",{value:!0}),n);var P={};u(P,{rules:()=>M});module.exports=y(P);var c=require("@typescript-eslint/utils"),t=require("@typescript-eslint/utils"),a=require("ts-pattern"),f=c.ESLintUtils.RuleCreator(n=>`https://https://github.com/JUSTIVE/strict-pattern-matching#${n}`),p=()=>{},E=f({create(n){return{CallExpression:function(e){(0,a.match)(e).with({callee:{type:t.AST_NODE_TYPES.MemberExpression,property:{type:t.AST_NODE_TYPES.Identifier,name:"run"}}},()=>{function r(i){return i.type===t.AST_NODE_TYPES.MemberExpression?r(i.object):i.type===t.AST_NODE_TYPES.CallExpression?i.callee.type===t.AST_NODE_TYPES.Identifier?i.callee.name==="match":r(i.callee):!1}r(e)&&n.report({node:e,messageId:"noRunEndingPatternMatching"})}).with({arguments:[{type:t.AST_NODE_TYPES.CallExpression,callee:{type:t.AST_NODE_TYPES.MemberExpression,property:{type:t.AST_NODE_TYPES.Identifier,name:"with"}}}]},()=>{n.report({node:e,messageId:"noUnFinishedPatternMatching"})}).otherwise(p)},ExpressionStatement:function(e){(0,a.match)(e).with({expression:{type:t.AST_NODE_TYPES.CallExpression,callee:{type:t.AST_NODE_TYPES.MemberExpression,property:{type:t.AST_NODE_TYPES.Identifier,name:"with"}}}},()=>{n.report({node:e,messageId:"noUnFinishedPatternMatching"})}).otherwise(p)},VariableDeclarator:function(e){(0,a.match)(e).with({init:{type:t.AST_NODE_TYPES.CallExpression,callee:{type:t.AST_NODE_TYPES.MemberExpression,property:{type:t.AST_NODE_TYPES.Identifier,name:"with"}}}},()=>{n.report({node:e,messageId:"noUnFinishedPatternMatching"})}).otherwise(p)}}},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:[]}),h=E;var M={strictPatternMatching:h};0&&(module.exports={rules});