PageSourceSearch

https://typescript-eslint.io/assets/js/36720592.57ba63c1.js

js typescript-eslint.io collected 2026-10-02 02:16:03 UTC 16,344 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["2464"],{29298(e,t,s){s.r(t),s.d(t,{metadata:()=>n,default:()=>E,frontMatter:()=>w,contentTitle:()=>S,toc:()=>N,assets:()=>k});var n=JSON.parse('{"id":"README","title":"Overview","description":"@typescript-eslint/eslint-plugin includes over 100 rules that detect best practice violations, bugs, and/or stylistic issues specifically for TypeScript code. All of our rules are listed below.","source":"@site/../eslint-plugin/docs/rules/README.md","sourceDirName":".","slug":"/","permalink":"/rules/","draft":false,"unlisted":false,"editUrl":"https://github.com/typescript-eslint/typescript-eslint/edit/main/packages/website/../eslint-plugin/docs/rules/README.md","tags":[],"version":"current","frontMatter":{"title":"Overview","sidebar_label":"Overview","pagination_next":null,"pagination_prev":null,"slug":"/"},"sidebar":"rulesSidebar"}'),i=s(65723),r=s(7143),l=s(14652),o=s(62934),a=s(44188),c=s(70851),d=s(22155),u=s(88622);let h={checkboxListArea:"checkboxListArea_DthA",checkboxList:"checkboxList_u9au",checkboxListItem:"checkboxListItem_k261",checkboxLabel:"checkboxLabel_SpKH",activated:"activated_u0Ma",deactivated:"deactivated_XM7z",visual:"visual_iKWA","visual-exclude":"visual-exclude_gW1W","visual-include":"visual-include_cwPc",rulesTable:"rulesTable_X3vb",ruleCol:"ruleCol_VzLB",attrCol:"attrCol_xNoP",ruleNameWrapper:"ruleNameWrapper_ypS3"};function x({docs:e}){let t=e.recommended;return t?(0,u.a)(t):["",""]}function p({rule:e}){var t;let s;if(!e.docs.url)return null;let{deprecated:n,fixable:r,hasSuggestions:o}=e,{extendsBaseRule:a,requiresTypeChecking:c}=e.docs,[d,u]=x(e);return(0,i.jsxs)("tr",{children:[(0,i.jsxs)("td",{children:[(0,i.jsxs)("div",{className:h.ruleNameWrapper,children:[(0,i.jsx)(l.A,{to:new URL(e.docs.url).pathname,children:(0,i.jsxs)("code",{children:["@typescript-eslint/",e.name]})}),e.docs.frozen&&(0,i.jsx)("span",{children:"\u2744\uFE0F"})]}),(0,i.jsx)("br",{}),1===(s=(t=e.docs.description).split(/`(.*?)`/)).length?t:s.map((e,t)=>t%2==0?e:(0,i.jsx)("code",{children:e},t))]}),(0,i.jsx)("td",{className:h.attrCol,title:u,children:d}),(0,i.jsxs)("td",{className:h.attrCol,title:r&&o?"fixable and has suggestions":r?"fixable":o?"has suggestions":void 0,children:[r?"\u{1F527}":"",r&&o?(0,i.jsx)("br",{}):"",o?"\u{1F4A1}":""]}),(0,i.jsx)("td",{className:h.attrCol,title:c?"requires type information":void 0,children:c?"\u{1F4AD}":""}),(0,i.jsx)("td",{className:h.attrCol,title:a?"extends base rule":void 0,children:a?"\u{1F9F1}":""}),(0,i.jsx)("td",{className:h.attrCol,title:n?"deprecated":void 0,children:n?"\u{1F480}":""})]})}let m=["neutral","include","exclude"];function f({label:e,mode:t,setMode:s}){let n=()=>s(m[(m.indexOf(t)+1)%m.length]);return(0,i.jsx)("li",{className:h.checkboxListItem,children:(0,i.jsxs)("button",{"aria-label":`Toggle the filter mode. Current: ${t}`,className:(0,c.A)(h.checkboxLabel,"include"===t&&h.activated,"exclude"===t&&h.deactivated),onClick:n,onKeyDown:e=>{"Enter"===e.key&&n()},type:"button",children:[(0,i.jsx)("div",{"aria-hidden":!0,className:(0,c.A)(h.visual,h[`visual-${t}`])}),e]})})}function g(e,t){return"exclude"===e?!t:"include"===e?t:void 0}function j(){let[e,t]=function(e=""){let t,s=(0,o.W6)(),n=new URLSearchParams((t=(0,o.W6)(),(0,d.useSyncExternalStore)(t.listen,()=>y(t),v))).get(e)??"",i=(0,d.useMemo)(()=>(function(e){let t={...b};for(let s of e.split("-")){let e=s.startsWith("x"),n=e?s.slice(1):s;Object.hasOwn(b,n)&&(t[n]=e?"exclude":"include")}return t})(n),[n]);return[i,(t,n)=>{let r={...i,[t]:n};"strict"===t&&"include"===n&&"include"===i.recommended?r.recommended="exclude":"recommended"===t&&"include"===n&&"include"===i.strict&&(r.strict="exclude");let l=new URLSearchParams(s.location.search),o=Object.entries(r).map(([e,t])=>"include"===t?e:"exclude"===t?`x${e}
1`:"").filter(Boolean).join("-");o?l.set(e,o):l.delete(e),s.replace({search:l.toString()})}]}(),s=(0,a.M)(),n=(0,d.useMemo)(()=>s.filter(t=>{let s=x(t)[1];return[g(e.recommended,"recommended"===s),g(e.strict,"recommended"===s||"strict"===s),g(e.stylistic,"stylistic"===s),g(e.fixable,!!t.fixable),g(e.suggestions,!!t.hasSuggestions),g(e.typeInformation,!!t.docs.requiresTypeChecking),g(e.extension,!!t.docs.extendsBaseRule),g(e.deprecated,!!t.deprecated)].filter(e=>void 0!==e).every(e=>e)}),[s,e]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:h.checkboxListArea,children:[(0,i.jsxs)("em",{children:["Config Group (","\u2699\uFE0F",")"]}),(0,i.jsxs)("ul",{className:(0,c.A)("clean-list",h.checkboxList),children:[(0,i.jsx)(f,{label:"\u2705 recommended",mode:e.recommended,setMode:e=>t("recommended",e)}),(0,i.jsx)(f,{label:`\u{1F512} strict`,mode:e.strict,setMode:e=>t("strict",e)}),(0,i.jsx)(f,{label:`\u{1F3A8} stylistic`,mode:e.stylistic,setMode:e=>t("stylistic",e)})]})]}),(0,i.jsxs)("div",{className:h.checkboxListArea,children:[(0,i.jsx)("em",{children:"Metadata"}),(0,i.jsxs)("ul",{className:(0,c.A)("clean-list",h.checkboxList),children:[(0,i.jsx)(f,{label:`\u{1F527} fixable`,mode:e.fixable,setMode:e=>t("fixable",e)}),(0,i.jsx)(f,{label:`\u{1F4A1} has suggestions`,mode:e.suggestions,setMode:e=>t("suggestions",e)}),(0,i.jsx)(f,{label:`\u{1F4AD} type checked`,mode:e.typeInformation,setMode:e=>t("typeInformation",e)}),(0,i.jsx)(f,{label:`\u{1F9F1} extension`,mode:e.extension,setMode:e=>t("extension",e)}),(0,i.jsx)(f,{label:`\u{1F480} deprecated`,mode:e.deprecated,setMode:e=>t("deprecated",e)})]})]}),(0,i.jsxs)("p",{children:["(These categories are explained in"," ",(0,i.jsx)("a",{href:"#filtering",children:"more detail below"}),".)"]}),(0,i.jsxs)("table",{className:h.rulesTable,children:[(0,i.jsx)("thead",{children:(0,i.jsxs)("tr",{children:[(0,i.jsx)("th",{className:h.ruleCol,children:"Rule"}),(0,i.jsx)("th",{className:h.attrCol,children:(0,i.jsx)("div",{title:"The config group that the rule belongs to, if any.",children:"\u2699\uFE0F"})}),(0,i.jsx)("th",{className:h.attrCol,children:(0,i.jsx)("div",{title:"Whether the rule has an auto-fixer and/or has suggestions.",children:"\u{1F527}"})}),(0,i.jsx)("th",{className:h.attrCol,children:(0,i.jsx)("div",{title:"Whether the rule requires type information from the TypeScript compiler.",children:"\u{1F4AD}"})}),(0,i.jsx)("th",{className:h.attrCol,children:(0,i.jsx)("div",{title:"Whether the rule is an extension rule (i.e. based on a core ESLint rule).",children:"\u{1F9F1}"})}),(0,i.jsx)("th",{className:h.attrCol,children:(0,i.jsx)("div",{title:"Whether the rule is deprecated.",children:"\u{1F480}"})})]})}),(0,i.jsx)("tbody",{children:n.map(e=>(0,i.jsx)(p,{rule:e},e.name))})]})]})}let b={deprecated:"neutral",extension:"neutral",fixable:"neutral",recommended:"neutral",strict:"neutral",stylistic:"neutral",suggestions:"neutral",typeInformation:"neutral"},y=e=>e.location.search,v=()=>"",w={title:"Overview",sidebar_label:"Overview",pagination_next:null,pagination_prev:null,slug:"/"},S,k={},N=[{value:"Rules",id:"rules",level:2},{value:"Filtering",id:"filtering",level:2},{value:"Config Group (\u2699\uFE0F)",id:"config-group-\uFE0F",level:3},{value:"Metadata",id:"metadata",level:3},{value:"Extension Rules",id:"extension-rules",level:2},{value:"Frozen Rules",id:"frozen-rules",level:2}];function C(e){let t={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"@typescript-eslint/eslint-plugin"})," includes over 100 rules that detect best practice violations, bugs, and/or stylistic issues specifically for TypeScript code. All of our rules are listed below."]}),"\n",(0,i.jsx)(t.admonition,{type:"tip",children:(0,i.jsxs)(t.p,{children:["Instead of enabling rules one by one, we recommend using one of ",(0,i.jsx)(t.a,{href:"/users/configs",children:"our pre-defined configs"})," to enable a large set of recommended rules."]})}),"\n",(0,i.jsx)(t.h2,{id:"rules",children:"Rules"}),"\n",(0,i.jsx)(t.p,{children:"The rules are listed in alphabetical order. You can optionally filter them based on these categories:"}),"\n","\n",(0,i.jsx)(j,{}),"\n",(0,i.jsx)(t.h2,{id:"filtering",children:"Filtering"}),"\n",(0,i.jsx)(t.h3,{id:"config-group-\uFE0F",children:"Config Group (\u2699\uFE0F)"}),"\n",(0,i.jsxs)(t.p,{children:['"Config Group" refers to the ',(0,i.jsx)(t.a,{href:"/users/configs",children:"pre-defined config"})," that includes the rule. Extending from a configuration preset allow for enabling a large set of recommended rules all at once."]}),"\n",(0,i.jsx)(t.h3,{id:"metadata",children:"Metadata"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:"\u{1F527} fixable"})," refers to whether the rule contains an ",(0,i.jsxs)(t.a,{href:"https://eslint.org/docs/latest/use/command-line-interface#--fix",children:["ESLint ",(0,i.jsx)(t.code,{children:"--fix"})," auto-fixer"]}),"."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:"\u{1F4A1} has suggestions"})," refers to whether the rule contains an ESLint suggestion fixer.","\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:"Sometimes, it is not safe to automatically fix the code with an auto-fixer. But in these cases, we often have a good guess of what the correct fix should be, and we can provide it as a suggestion to the developer."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:"\u{1F4AD} requires type information"})," refers to whether the rule requires ",(0,i.jsx)(t.a,{href:"/getting-started/typed-linting",children:"typed linting"}),"."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:"\u{1F9F1} extension rule"})," means that the rule is an extension of an ",(0,i.jsx)(t.a,{href:"https://eslint.org/docs/latest/rules",children:"core ESLint rule"})," (see ",(0,i.jsx)(t.a,{href:"#extension-rules",children:"Extension Rules"}),")."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:"\u{1F480} deprecated rule"})," means that the rule should no longer be used and will be removed from the plugin in a future version."]}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"extension-rules",children:"Extension Rules"}),"\n",(0,i.jsx)(t.p,{children:'Some core ESLint rules do not support TypeScript syntax: either they crash, ignore the syntax, or falsely report against it.\nIn these cases, we create what we call an "extension rule": a rule within our plugin that has the same functionality, but also supports TypeScript.'}),"\n",(0,i.jsx)(t.p,{children:"Extension rules generally completely replace the base rule from ESLint core.\nIf the base rule is enabled in a config you extend from, you'll need to disable the base rule:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"module.exports = {\n  extends: ['eslint:recommended'],\n  rules: {\n    // Note: you must disable the base rule as it can report incorrect errors\n    'no-unused-vars': 'off',\n    '@typescript-eslint/no-unused-vars': 'error',\n  },\n};\n"})}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsxs)(t.a,{href:"?=extension#rules",children:["Search for ",(0,i.jsx)(t.code,{children:"\u{1F9F1} extension rule"}),"s"]})," in this page to see all extension rules."]}),"\n",(0,i.jsx)(t.h2,{id:"frozen-rules",children:"Frozen Rules"}),"\n",(0,i.jsxs)(t.p,{children:["When rules are feature complete, they are marked as frozen (indicated with \u2744\uFE0F in the documentation). This applies to standalone rules that are complete, as well as ",(0,i.jsx)(t.a,{href:"#extension-rules",children:"extension rules"})," whose underlying core ESLint rules are frozen. After that point, we expect users to use ",(0,i.jsx)(t.a,{href:"https://eslint.org/docs/latest/use/configure/rules#use-configuration-comments",children:"disable comments"}
1)," when they find an edge case that isn\u2019t covered."]}),"\n",(0,i.jsx)(t.p,{children:"When a rule is frozen, it means:"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.strong,{children:"Bug fixes"}),": We will still fix confirmed bugs."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.strong,{children:"New ECMAScript features"}),": We will ensure compatibility with new ECMAScript features, meaning the rule will not break on new syntax."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.strong,{children:"TypeScript support"}),": We will ensure compatibility with TypeScript syntax, meaning the rule will not break on TypeScript syntax and violations are appropriate for TypeScript."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.strong,{children:"New options"}),": We will not add any new options unless an option is the only way to fix a bug or support a newly-added ECMAScript feature."]}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"If you find that a frozen rule would work better for you with a change, we recommend copying the rule source code and modifying it to fit your needs."})]})}function E(e={}){let{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(C,{...e})}):C(e)}},44188(e,t,s){s.d(t,{M:()=>i});var n=s(13524);function i(){let{siteConfig:{customFields:e}}=(0,n.A)();if(!e)throw Error("Custom fields not found in config");return e.rules}},88622(e,t,s){s.d(t,{E:()=>u,a:()=>d});var n=s(65723),i=s(22155),r=s(14652),l=s(44188);function o({children:e,emoji:t}){return(0,n.jsxs)("div",{className:"feature_kXUu",children:[(0,n.jsx)("div",{className:"emoji_aMkV",children:t}),(0,n.jsx)("p",{className:"children_zlBF",children:e})]})}let a={features:"features_Kr5p"},c={recommended:["\u2705","recommended"],strict:["\u{1F512}","strict"],stylistic:["\u{1F3A8}","stylistic"]};function d(e){return c["object"==typeof e?!0===e.recommended?"recommended":"strict":e]}function u({name:e}){let t=(0,l.M)().find(t=>t.name===e);if(!t?.docs)return null;let s=[];if(t.docs.recommended){var c;let e,[i,l]=(e=d((c=t.docs).recommended),c.requiresTypeChecking?[e[0],`${e[1]}-type-checked`]:e);s.push({children:(0,n.jsxs)(n.Fragment,{children:["Extending"," ",(0,n.jsx)(r.A,{to:`/users/configs#${l}`,target:"_blank",children:(0,n.jsxs)("code",{className:a.code,children:['"plugin:@typescript-eslint/',l,'"']})})," ","in an"," ",(0,n.jsx)(r.A,{href:"https://eslint.org/docs/latest/user-guide/configuring/configuration-files#extending-configuration-files",children:"ESLint configuration"})," ","enables this rule."]}),emoji:i})}return t.fixable&&s.push({children:(0,n.jsxs)(n.Fragment,{children:["Some problems reported by this rule are automatically fixable by the"," ",(0,n.jsxs)(r.A,{href:"https://eslint.org/docs/latest/user-guide/command-line-interface#--fix",children:[(0,n.jsx)("code",{children:"--fix"})," ESLint command line option"]}),"."]}),emoji:"\u{1F527}"}),t.hasSuggestions&&s.push({children:(0,n.jsxs)(n.Fragment,{children:["Some problems reported by this rule are manually fixable by editor"," ",(0,n.jsx)(r.A,{href:"https://eslint.org/docs/latest/developer-guide/working-with-rules#providing-suggestions",children:"suggestions"}),"."]}),emoji:"\u{1F4A1}"}),t.docs.requiresTypeChecking&&s.push({children:(0,n.jsxs)(n.Fragment,{children:["This rule requires"," ",(0,n.jsx)(r.A,{href:"/getting-started/typed-linting",target:"_blank",children:"type information"})," ","to run, which comes with performance tradeoffs."]}),emoji:"\u{1F4AD}"}),t.docs.extendsBaseRule&&s.push({children:(0,n.jsxs)(n.Fragment,{children:[" ",'This is an "extension" rule that replaces a core ESLint rule to work with TypeScript. See'," ",(0,n.jsx)(r.A,{href:"/rules#extension-rules",children:"Rules > Extension Rules"}),"."]}),emoji:"\u{1F9F1}"}),t.docs.frozen&&s.push({children:(0,n.jsxs)(n.Fragment,{children:["This rule is currently ",(0,n.jsx)(r.A,{href:"/rules#frozen-rules",children:"frozen"})," ","and is not accepting feature requests."]}),emoji:"\u2744\uFE0F"}),(0,n.jsx)("div",{className:a.features,children:s.map(e=>(0,i.createElement)(o,{...e,key:e.emoji}))})}}
1,7143(e,t,s){s.d(t,{R:()=>l,x:()=>o});var n=s(22155);let i={},r=n.createContext(i);function l(e){let t=n.useContext(r);return n.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.