pyo3_stub_gen/
rule_name.rs

1use serde::{Deserialize, Serialize};
2use std::{convert::Infallible, fmt, str::FromStr};
3
4/// Type checker rule names for MyPy error codes and Pyright diagnostic rules
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub enum RuleName {
7    // MyPy error codes from https://mypy.readthedocs.io/en/stable/error_code_list.html
8    AttrDefined,
9    UnionAttr,
10    NameDefined,
11    UsedBeforeDef,
12    CallArg,
13    ArgType,
14    CallOverload,
15    ValidType,
16    VarAnnotated,
17    Override,
18    Return,
19    EmptyBody,
20    ReturnValue,
21    Assignment,
22    MethodAssign,
23    TypeVar,
24    Operator,
25    Index,
26    ListItem,
27    DictItem,
28    TypedDictItem,
29    TypedDictUnknownKey,
30    HasType,
31    Import,
32    ImportNotFound,
33    ImportUntyped,
34    NoRedef,
35    FuncReturnsValue,
36    Abstract,
37    TypeAbstract,
38    SafeSuper,
39    ValidNewtype,
40    ExitReturn,
41    NameMatch,
42    LiteralRequired,
43    NoOverloadImpl,
44    UnusedCoroutine,
45    TopLevelAwait,
46    AwaitNotAsync,
47    AssertType,
48    TruthyFunction,
49    StrFormat,
50    StrBytesSafe,
51    OverloadOverlap,
52    OverloadCannotMatch,
53    AnnotationUnchecked,
54    PropDecorator,
55    Syntax,
56    TypedDictReadonlyMutated,
57    NarrowedTypeNotSubtype,
58    Misc,
59
60    // MyPy optional error codes from https://mypy.readthedocs.io/en/stable/error_code_list2.html
61    TypeArg,
62    NoUntypedDef,
63    RedundantCast,
64    RedundantSelf,
65    ComparisonOverlap,
66    NoUntypedCall,
67    NoAnyReturn,
68    NoAnyUnimported,
69    Unreachable,
70    Deprecated,
71    RedundantExpr,
72    PossiblyUndefined,
73    TruthyBool,
74    TruthyIterable,
75    IgnoreWithoutCode,
76    UnusedAwaitable,
77    UnusedIgnore,
78    ExplicitOverride,
79    MutableOverride,
80    UnimportedReveal,
81    ExplicitAny,
82    ExhaustiveMatch,
83
84    // Pyright diagnostic rules from https://microsoft.github.io/pyright/#/configuration?id=type-check-rule-overrides
85    ReportGeneralTypeIssues,
86    ReportPropertyTypeMismatch,
87    ReportFunctionMemberAccess,
88    ReportMissingImports,
89    ReportMissingModuleSource,
90    ReportInvalidTypeForm,
91    ReportMissingTypeStubs,
92    ReportImportCycles,
93    ReportUnusedImport,
94    ReportUnusedClass,
95    ReportUnusedFunction,
96    ReportUnusedVariable,
97    ReportDuplicateImport,
98    ReportWildcardImportFromLibrary,
99    ReportAbstractUsage,
100    ReportArgumentType,
101    ReportAssertTypeFailure,
102    ReportAssignmentType,
103    ReportAttributeAccessIssue,
104    ReportCallIssue,
105    ReportInconsistentOverload,
106    ReportIndexIssue,
107    ReportInvalidTypeArguments,
108    ReportInvalidTypeVarUse,
109    ReportMissingParameterType,
110    ReportMissingTypeArgument,
111    ReportOperatorIssue,
112    ReportOptionalMemberAccess,
113    ReportOptionalSubscript,
114    ReportOptionalIterable,
115    ReportOptionalCall,
116    ReportOptionalOperand,
117    ReportOptionalContextManager,
118    ReportPrivateImportUsage,
119    ReportPrivateUsage,
120    ReportRedeclaration,
121    ReportReturnType,
122    ReportTypedDictNotRequiredAccess,
123    ReportUndefinedVariable,
124    ReportUnknownArgumentType,
125    ReportUnknownLambdaType,
126    ReportUnknownMemberType,
127    ReportUnknownParameterType,
128    ReportUnknownVariableType,
129    ReportUnnecessaryCast,
130    ReportUnnecessaryComparison,
131    ReportUnnecessaryContains,
132    ReportUnnecessaryIsInstance,
133    ReportUnnecessaryTypeIgnoreComment,
134    ReportUnsupportedDunderAll,
135    ReportUntypedBaseClass,
136    ReportUntypedClassDecorator,
137    ReportUntypedFunctionDecorator,
138    ReportUntypedNamedTuple,
139    ReportIncompatibleMethodOverride,
140    ReportIncompatibleVariableOverride,
141    ReportInvalidStringEscapeSequence,
142    ReportMissingCallArgument,
143    ReportUnboundVariable,
144    ReportPossiblyUnboundVariable,
145    ReportImplicitOverride,
146    ReportInvalidStubStatement,
147    ReportIncompleteStub,
148    ReportUnusedCoroutine,
149    ReportAwaitNotAsync,
150    ReportMatchNotExhaustive,
151    ReportShadowedImports,
152    ReportImplicitStringConcatenation,
153    ReportDeprecated,
154    ReportNoOverloadImplementation,
155    ReportTypeCommentUsage,
156    ReportConstantRedefinition,
157    ReportInconsistentConstructor,
158    ReportOverlappingOverload,
159    ReportMissingSuperCall,
160    ReportUninitializedInstanceVariable,
161    ReportCallInDefaultInitializer,
162    ReportAssertAlwaysTrue,
163    ReportSelfClsParameterName,
164    ReportUnhashable,
165    ReportUnusedCallResult,
166    ReportUnusedExcept,
167    ReportUnusedExpression,
168    ReportUnreachable,
169
170    /// Custom rule name escape hatch for rules not in the enum
171    Custom(String),
172}
173
174impl FromStr for RuleName {
175    type Err = Infallible;
176
177    fn from_str(s: &str) -> Result<Self, Self::Err> {
178        let result = match s {
179            // MyPy error codes
180            "attr-defined" => Self::AttrDefined,
181            "union-attr" => Self::UnionAttr,
182            "name-defined" => Self::NameDefined,
183            "used-before-def" => Self::UsedBeforeDef,
184            "call-arg" => Self::CallArg,
185            "arg-type" => Self::ArgType,
186            "call-overload" => Self::CallOverload,
187            "valid-type" => Self::ValidType,
188            "var-annotated" => Self::VarAnnotated,
189            "override" => Self::Override,
190            "return" => Self::Return,
191            "empty-body" => Self::EmptyBody,
192            "return-value" => Self::ReturnValue,
193            "assignment" => Self::Assignment,
194            "method-assign" => Self::MethodAssign,
195            "type-var" => Self::TypeVar,
196            "operator" => Self::Operator,
197            "index" => Self::Index,
198            "list-item" => Self::ListItem,
199            "dict-item" => Self::DictItem,
200            "typeddict-item" => Self::TypedDictItem,
201            "typeddict-unknown-key" => Self::TypedDictUnknownKey,
202            "has-type" => Self::HasType,
203            "import" => Self::Import,
204            "import-not-found" => Self::ImportNotFound,
205            "import-untyped" => Self::ImportUntyped,
206            "no-redef" => Self::NoRedef,
207            "func-returns-value" => Self::FuncReturnsValue,
208            "abstract" => Self::Abstract,
209            "type-abstract" => Self::TypeAbstract,
210            "safe-super" => Self::SafeSuper,
211            "valid-newtype" => Self::ValidNewtype,
212            "exit-return" => Self::ExitReturn,
213            "name-match" => Self::NameMatch,
214            "literal-required" => Self::LiteralRequired,
215            "no-overload-impl" => Self::NoOverloadImpl,
216            "unused-coroutine" => Self::UnusedCoroutine,
217            "top-level-await" => Self::TopLevelAwait,
218            "await-not-async" => Self::AwaitNotAsync,
219            "assert-type" => Self::AssertType,
220            "truthy-function" => Self::TruthyFunction,
221            "str-format" => Self::StrFormat,
222            "str-bytes-safe" => Self::StrBytesSafe,
223            "overload-overlap" => Self::OverloadOverlap,
224            "overload-cannot-match" => Self::OverloadCannotMatch,
225            "annotation-unchecked" => Self::AnnotationUnchecked,
226            "prop-decorator" => Self::PropDecorator,
227            "syntax" => Self::Syntax,
228            "typeddict-readonly-mutated" => Self::TypedDictReadonlyMutated,
229            "narrowed-type-not-subtype" => Self::NarrowedTypeNotSubtype,
230            "misc" => Self::Misc,
231
232            // MyPy optional codes
233            "type-arg" => Self::TypeArg,
234            "no-untyped-def" => Self::NoUntypedDef,
235            "redundant-cast" => Self::RedundantCast,
236            "redundant-self" => Self::RedundantSelf,
237            "comparison-overlap" => Self::ComparisonOverlap,
238            "no-untyped-call" => Self::NoUntypedCall,
239            "no-any-return" => Self::NoAnyReturn,
240            "no-any-unimported" => Self::NoAnyUnimported,
241            "unreachable" => Self::Unreachable,
242            "deprecated" => Self::Deprecated,
243            "redundant-expr" => Self::RedundantExpr,
244            "possibly-undefined" => Self::PossiblyUndefined,
245            "truthy-bool" => Self::TruthyBool,
246            "truthy-iterable" => Self::TruthyIterable,
247            "ignore-without-code" => Self::IgnoreWithoutCode,
248            "unused-awaitable" => Self::UnusedAwaitable,
249            "unused-ignore" => Self::UnusedIgnore,
250            "explicit-override" => Self::ExplicitOverride,
251            "mutable-override" => Self::MutableOverride,
252            "unimported-reveal" => Self::UnimportedReveal,
253            "explicit-any" => Self::ExplicitAny,
254            "exhaustive-match" => Self::ExhaustiveMatch,
255
256            // Pyright diagnostic rules
257            "reportGeneralTypeIssues" => Self::ReportGeneralTypeIssues,
258            "reportPropertyTypeMismatch" => Self::ReportPropertyTypeMismatch,
259            "reportFunctionMemberAccess" => Self::ReportFunctionMemberAccess,
260            "reportMissingImports" => Self::ReportMissingImports,
261            "reportMissingModuleSource" => Self::ReportMissingModuleSource,
262            "reportInvalidTypeForm" => Self::ReportInvalidTypeForm,
263            "reportMissingTypeStubs" => Self::ReportMissingTypeStubs,
264            "reportImportCycles" => Self::ReportImportCycles,
265            "reportUnusedImport" => Self::ReportUnusedImport,
266            "reportUnusedClass" => Self::ReportUnusedClass,
267            "reportUnusedFunction" => Self::ReportUnusedFunction,
268            "reportUnusedVariable" => Self::ReportUnusedVariable,
269            "reportDuplicateImport" => Self::ReportDuplicateImport,
270            "reportWildcardImportFromLibrary" => Self::ReportWildcardImportFromLibrary,
271            "reportAbstractUsage" => Self::ReportAbstractUsage,
272            "reportArgumentType" => Self::ReportArgumentType,
273            "reportAssertTypeFailure" => Self::ReportAssertTypeFailure,
274            "reportAssignmentType" => Self::ReportAssignmentType,
275            "reportAttributeAccessIssue" => Self::ReportAttributeAccessIssue,
276            "reportCallIssue" => Self::ReportCallIssue,
277            "reportInconsistentOverload" => Self::ReportInconsistentOverload,
278            "reportIndexIssue" => Self::ReportIndexIssue,
279            "reportInvalidTypeArguments" => Self::ReportInvalidTypeArguments,
280            "reportInvalidTypeVarUse" => Self::ReportInvalidTypeVarUse,
281            "reportMissingParameterType" => Self::ReportMissingParameterType,
282            "reportMissingTypeArgument" => Self::ReportMissingTypeArgument,
283            "reportOperatorIssue" => Self::ReportOperatorIssue,
284            "reportOptionalMemberAccess" => Self::ReportOptionalMemberAccess,
285            "reportOptionalSubscript" => Self::ReportOptionalSubscript,
286            "reportOptionalIterable" => Self::ReportOptionalIterable,
287            "reportOptionalCall" => Self::ReportOptionalCall,
288            "reportOptionalOperand" => Self::ReportOptionalOperand,
289            "reportOptionalContextManager" => Self::ReportOptionalContextManager,
290            "reportPrivateImportUsage" => Self::ReportPrivateImportUsage,
291            "reportPrivateUsage" => Self::ReportPrivateUsage,
292            "reportRedeclaration" => Self::ReportRedeclaration,
293            "reportReturnType" => Self::ReportReturnType,
294            "reportTypedDictNotRequiredAccess" => Self::ReportTypedDictNotRequiredAccess,
295            "reportUndefinedVariable" => Self::ReportUndefinedVariable,
296            "reportUnknownArgumentType" => Self::ReportUnknownArgumentType,
297            "reportUnknownLambdaType" => Self::ReportUnknownLambdaType,
298            "reportUnknownMemberType" => Self::ReportUnknownMemberType,
299            "reportUnknownParameterType" => Self::ReportUnknownParameterType,
300            "reportUnknownVariableType" => Self::ReportUnknownVariableType,
301            "reportUnnecessaryCast" => Self::ReportUnnecessaryCast,
302            "reportUnnecessaryComparison" => Self::ReportUnnecessaryComparison,
303            "reportUnnecessaryContains" => Self::ReportUnnecessaryContains,
304            "reportUnnecessaryIsInstance" => Self::ReportUnnecessaryIsInstance,
305            "reportUnnecessaryTypeIgnoreComment" => Self::ReportUnnecessaryTypeIgnoreComment,
306            "reportUnsupportedDunderAll" => Self::ReportUnsupportedDunderAll,
307            "reportUntypedBaseClass" => Self::ReportUntypedBaseClass,
308            "reportUntypedClassDecorator" => Self::ReportUntypedClassDecorator,
309            "reportUntypedFunctionDecorator" => Self::ReportUntypedFunctionDecorator,
310            "reportUntypedNamedTuple" => Self::ReportUntypedNamedTuple,
311            "reportIncompatibleMethodOverride" => Self::ReportIncompatibleMethodOverride,
312            "reportIncompatibleVariableOverride" => Self::ReportIncompatibleVariableOverride,
313            "reportInvalidStringEscapeSequence" => Self::ReportInvalidStringEscapeSequence,
314            "reportMissingCallArgument" => Self::ReportMissingCallArgument,
315            "reportUnboundVariable" => Self::ReportUnboundVariable,
316            "reportPossiblyUnboundVariable" => Self::ReportPossiblyUnboundVariable,
317            "reportImplicitOverride" => Self::ReportImplicitOverride,
318            "reportInvalidStubStatement" => Self::ReportInvalidStubStatement,
319            "reportIncompleteStub" => Self::ReportIncompleteStub,
320            "reportUnusedCoroutine" => Self::ReportUnusedCoroutine,
321            "reportAwaitNotAsync" => Self::ReportAwaitNotAsync,
322            "reportMatchNotExhaustive" => Self::ReportMatchNotExhaustive,
323            "reportShadowedImports" => Self::ReportShadowedImports,
324            "reportImplicitStringConcatenation" => Self::ReportImplicitStringConcatenation,
325            "reportDeprecated" => Self::ReportDeprecated,
326            "reportNoOverloadImplementation" => Self::ReportNoOverloadImplementation,
327            "reportTypeCommentUsage" => Self::ReportTypeCommentUsage,
328            "reportConstantRedefinition" => Self::ReportConstantRedefinition,
329            "reportInconsistentConstructor" => Self::ReportInconsistentConstructor,
330            "reportOverlappingOverload" => Self::ReportOverlappingOverload,
331            "reportMissingSuperCall" => Self::ReportMissingSuperCall,
332            "reportUninitializedInstanceVariable" => Self::ReportUninitializedInstanceVariable,
333            "reportCallInDefaultInitializer" => Self::ReportCallInDefaultInitializer,
334            "reportAssertAlwaysTrue" => Self::ReportAssertAlwaysTrue,
335            "reportSelfClsParameterName" => Self::ReportSelfClsParameterName,
336            "reportUnhashable" => Self::ReportUnhashable,
337            "reportUnusedCallResult" => Self::ReportUnusedCallResult,
338            "reportUnusedExcept" => Self::ReportUnusedExcept,
339            "reportUnusedExpression" => Self::ReportUnusedExpression,
340            "reportUnreachable" => Self::ReportUnreachable,
341
342            // Fall back to custom
343            other => Self::Custom(other.to_string()),
344        };
345        Ok(result)
346    }
347}
348
349impl RuleName {
350    /// Check if this is a known rule (not custom)
351    pub fn is_known(&self) -> bool {
352        !matches!(self, Self::Custom(_))
353    }
354}
355
356impl fmt::Display for RuleName {
357    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
358        match self {
359            // MyPy error codes
360            Self::AttrDefined => write!(f, "attr-defined"),
361            Self::UnionAttr => write!(f, "union-attr"),
362            Self::NameDefined => write!(f, "name-defined"),
363            Self::UsedBeforeDef => write!(f, "used-before-def"),
364            Self::CallArg => write!(f, "call-arg"),
365            Self::ArgType => write!(f, "arg-type"),
366            Self::CallOverload => write!(f, "call-overload"),
367            Self::ValidType => write!(f, "valid-type"),
368            Self::VarAnnotated => write!(f, "var-annotated"),
369            Self::Override => write!(f, "override"),
370            Self::Return => write!(f, "return"),
371            Self::EmptyBody => write!(f, "empty-body"),
372            Self::ReturnValue => write!(f, "return-value"),
373            Self::Assignment => write!(f, "assignment"),
374            Self::MethodAssign => write!(f, "method-assign"),
375            Self::TypeVar => write!(f, "type-var"),
376            Self::Operator => write!(f, "operator"),
377            Self::Index => write!(f, "index"),
378            Self::ListItem => write!(f, "list-item"),
379            Self::DictItem => write!(f, "dict-item"),
380            Self::TypedDictItem => write!(f, "typeddict-item"),
381            Self::TypedDictUnknownKey => write!(f, "typeddict-unknown-key"),
382            Self::HasType => write!(f, "has-type"),
383            Self::Import => write!(f, "import"),
384            Self::ImportNotFound => write!(f, "import-not-found"),
385            Self::ImportUntyped => write!(f, "import-untyped"),
386            Self::NoRedef => write!(f, "no-redef"),
387            Self::FuncReturnsValue => write!(f, "func-returns-value"),
388            Self::Abstract => write!(f, "abstract"),
389            Self::TypeAbstract => write!(f, "type-abstract"),
390            Self::SafeSuper => write!(f, "safe-super"),
391            Self::ValidNewtype => write!(f, "valid-newtype"),
392            Self::ExitReturn => write!(f, "exit-return"),
393            Self::NameMatch => write!(f, "name-match"),
394            Self::LiteralRequired => write!(f, "literal-required"),
395            Self::NoOverloadImpl => write!(f, "no-overload-impl"),
396            Self::UnusedCoroutine => write!(f, "unused-coroutine"),
397            Self::TopLevelAwait => write!(f, "top-level-await"),
398            Self::AwaitNotAsync => write!(f, "await-not-async"),
399            Self::AssertType => write!(f, "assert-type"),
400            Self::TruthyFunction => write!(f, "truthy-function"),
401            Self::StrFormat => write!(f, "str-format"),
402            Self::StrBytesSafe => write!(f, "str-bytes-safe"),
403            Self::OverloadOverlap => write!(f, "overload-overlap"),
404            Self::OverloadCannotMatch => write!(f, "overload-cannot-match"),
405            Self::AnnotationUnchecked => write!(f, "annotation-unchecked"),
406            Self::PropDecorator => write!(f, "prop-decorator"),
407            Self::Syntax => write!(f, "syntax"),
408            Self::TypedDictReadonlyMutated => write!(f, "typeddict-readonly-mutated"),
409            Self::NarrowedTypeNotSubtype => write!(f, "narrowed-type-not-subtype"),
410            Self::Misc => write!(f, "misc"),
411
412            // MyPy optional codes
413            Self::TypeArg => write!(f, "type-arg"),
414            Self::NoUntypedDef => write!(f, "no-untyped-def"),
415            Self::RedundantCast => write!(f, "redundant-cast"),
416            Self::RedundantSelf => write!(f, "redundant-self"),
417            Self::ComparisonOverlap => write!(f, "comparison-overlap"),
418            Self::NoUntypedCall => write!(f, "no-untyped-call"),
419            Self::NoAnyReturn => write!(f, "no-any-return"),
420            Self::NoAnyUnimported => write!(f, "no-any-unimported"),
421            Self::Unreachable => write!(f, "unreachable"),
422            Self::Deprecated => write!(f, "deprecated"),
423            Self::RedundantExpr => write!(f, "redundant-expr"),
424            Self::PossiblyUndefined => write!(f, "possibly-undefined"),
425            Self::TruthyBool => write!(f, "truthy-bool"),
426            Self::TruthyIterable => write!(f, "truthy-iterable"),
427            Self::IgnoreWithoutCode => write!(f, "ignore-without-code"),
428            Self::UnusedAwaitable => write!(f, "unused-awaitable"),
429            Self::UnusedIgnore => write!(f, "unused-ignore"),
430            Self::ExplicitOverride => write!(f, "explicit-override"),
431            Self::MutableOverride => write!(f, "mutable-override"),
432            Self::UnimportedReveal => write!(f, "unimported-reveal"),
433            Self::ExplicitAny => write!(f, "explicit-any"),
434            Self::ExhaustiveMatch => write!(f, "exhaustive-match"),
435
436            // Pyright rules - use the original names
437            Self::ReportGeneralTypeIssues => write!(f, "reportGeneralTypeIssues"),
438            Self::ReportPropertyTypeMismatch => write!(f, "reportPropertyTypeMismatch"),
439            Self::ReportFunctionMemberAccess => write!(f, "reportFunctionMemberAccess"),
440            Self::ReportMissingImports => write!(f, "reportMissingImports"),
441            Self::ReportMissingModuleSource => write!(f, "reportMissingModuleSource"),
442            Self::ReportInvalidTypeForm => write!(f, "reportInvalidTypeForm"),
443            Self::ReportMissingTypeStubs => write!(f, "reportMissingTypeStubs"),
444            Self::ReportImportCycles => write!(f, "reportImportCycles"),
445            Self::ReportUnusedImport => write!(f, "reportUnusedImport"),
446            Self::ReportUnusedClass => write!(f, "reportUnusedClass"),
447            Self::ReportUnusedFunction => write!(f, "reportUnusedFunction"),
448            Self::ReportUnusedVariable => write!(f, "reportUnusedVariable"),
449            Self::ReportDuplicateImport => write!(f, "reportDuplicateImport"),
450            Self::ReportWildcardImportFromLibrary => write!(f, "reportWildcardImportFromLibrary"),
451            Self::ReportAbstractUsage => write!(f, "reportAbstractUsage"),
452            Self::ReportArgumentType => write!(f, "reportArgumentType"),
453            Self::ReportAssertTypeFailure => write!(f, "reportAssertTypeFailure"),
454            Self::ReportAssignmentType => write!(f, "reportAssignmentType"),
455            Self::ReportAttributeAccessIssue => write!(f, "reportAttributeAccessIssue"),
456            Self::ReportCallIssue => write!(f, "reportCallIssue"),
457            Self::ReportInconsistentOverload => write!(f, "reportInconsistentOverload"),
458            Self::ReportIndexIssue => write!(f, "reportIndexIssue"),
459            Self::ReportInvalidTypeArguments => write!(f, "reportInvalidTypeArguments"),
460            Self::ReportInvalidTypeVarUse => write!(f, "reportInvalidTypeVarUse"),
461            Self::ReportMissingParameterType => write!(f, "reportMissingParameterType"),
462            Self::ReportMissingTypeArgument => write!(f, "reportMissingTypeArgument"),
463            Self::ReportOperatorIssue => write!(f, "reportOperatorIssue"),
464            Self::ReportOptionalMemberAccess => write!(f, "reportOptionalMemberAccess"),
465            Self::ReportOptionalSubscript => write!(f, "reportOptionalSubscript"),
466            Self::ReportOptionalIterable => write!(f, "reportOptionalIterable"),
467            Self::ReportOptionalCall => write!(f, "reportOptionalCall"),
468            Self::ReportOptionalOperand => write!(f, "reportOptionalOperand"),
469            Self::ReportOptionalContextManager => write!(f, "reportOptionalContextManager"),
470            Self::ReportPrivateImportUsage => write!(f, "reportPrivateImportUsage"),
471            Self::ReportPrivateUsage => write!(f, "reportPrivateUsage"),
472            Self::ReportRedeclaration => write!(f, "reportRedeclaration"),
473            Self::ReportReturnType => write!(f, "reportReturnType"),
474            Self::ReportTypedDictNotRequiredAccess => write!(f, "reportTypedDictNotRequiredAccess"),
475            Self::ReportUndefinedVariable => write!(f, "reportUndefinedVariable"),
476            Self::ReportUnknownArgumentType => write!(f, "reportUnknownArgumentType"),
477            Self::ReportUnknownLambdaType => write!(f, "reportUnknownLambdaType"),
478            Self::ReportUnknownMemberType => write!(f, "reportUnknownMemberType"),
479            Self::ReportUnknownParameterType => write!(f, "reportUnknownParameterType"),
480            Self::ReportUnknownVariableType => write!(f, "reportUnknownVariableType"),
481            Self::ReportUnnecessaryCast => write!(f, "reportUnnecessaryCast"),
482            Self::ReportUnnecessaryComparison => write!(f, "reportUnnecessaryComparison"),
483            Self::ReportUnnecessaryContains => write!(f, "reportUnnecessaryContains"),
484            Self::ReportUnnecessaryIsInstance => write!(f, "reportUnnecessaryIsInstance"),
485            Self::ReportUnnecessaryTypeIgnoreComment => {
486                write!(f, "reportUnnecessaryTypeIgnoreComment")
487            }
488            Self::ReportUnsupportedDunderAll => write!(f, "reportUnsupportedDunderAll"),
489            Self::ReportUntypedBaseClass => write!(f, "reportUntypedBaseClass"),
490            Self::ReportUntypedClassDecorator => write!(f, "reportUntypedClassDecorator"),
491            Self::ReportUntypedFunctionDecorator => write!(f, "reportUntypedFunctionDecorator"),
492            Self::ReportUntypedNamedTuple => write!(f, "reportUntypedNamedTuple"),
493            Self::ReportIncompatibleMethodOverride => write!(f, "reportIncompatibleMethodOverride"),
494            Self::ReportIncompatibleVariableOverride => {
495                write!(f, "reportIncompatibleVariableOverride")
496            }
497            Self::ReportInvalidStringEscapeSequence => {
498                write!(f, "reportInvalidStringEscapeSequence")
499            }
500            Self::ReportMissingCallArgument => write!(f, "reportMissingCallArgument"),
501            Self::ReportUnboundVariable => write!(f, "reportUnboundVariable"),
502            Self::ReportPossiblyUnboundVariable => write!(f, "reportPossiblyUnboundVariable"),
503            Self::ReportImplicitOverride => write!(f, "reportImplicitOverride"),
504            Self::ReportInvalidStubStatement => write!(f, "reportInvalidStubStatement"),
505            Self::ReportIncompleteStub => write!(f, "reportIncompleteStub"),
506            Self::ReportUnusedCoroutine => write!(f, "reportUnusedCoroutine"),
507            Self::ReportAwaitNotAsync => write!(f, "reportAwaitNotAsync"),
508            Self::ReportMatchNotExhaustive => write!(f, "reportMatchNotExhaustive"),
509            Self::ReportShadowedImports => write!(f, "reportShadowedImports"),
510            Self::ReportImplicitStringConcatenation => {
511                write!(f, "reportImplicitStringConcatenation")
512            }
513            Self::ReportDeprecated => write!(f, "reportDeprecated"),
514            Self::ReportNoOverloadImplementation => write!(f, "reportNoOverloadImplementation"),
515            Self::ReportTypeCommentUsage => write!(f, "reportTypeCommentUsage"),
516            Self::ReportConstantRedefinition => write!(f, "reportConstantRedefinition"),
517            Self::ReportInconsistentConstructor => write!(f, "reportInconsistentConstructor"),
518            Self::ReportOverlappingOverload => write!(f, "reportOverlappingOverload"),
519            Self::ReportMissingSuperCall => write!(f, "reportMissingSuperCall"),
520            Self::ReportUninitializedInstanceVariable => {
521                write!(f, "reportUninitializedInstanceVariable")
522            }
523            Self::ReportCallInDefaultInitializer => write!(f, "reportCallInDefaultInitializer"),
524            Self::ReportAssertAlwaysTrue => write!(f, "reportAssertAlwaysTrue"),
525            Self::ReportSelfClsParameterName => write!(f, "reportSelfClsParameterName"),
526            Self::ReportUnhashable => write!(f, "reportUnhashable"),
527            Self::ReportUnusedCallResult => write!(f, "reportUnusedCallResult"),
528            Self::ReportUnusedExcept => write!(f, "reportUnusedExcept"),
529            Self::ReportUnusedExpression => write!(f, "reportUnusedExpression"),
530            Self::ReportUnreachable => write!(f, "reportUnreachable"),
531
532            Self::Custom(s) => write!(f, "{}", s),
533        }
534    }
535}
536
537#[cfg(test)]
538mod tests {
539    use super::*;
540
541    #[test]
542    fn test_mypy_error_codes() {
543        assert_eq!(
544            "attr-defined".parse::<RuleName>().unwrap(),
545            RuleName::AttrDefined
546        );
547        assert_eq!(RuleName::AttrDefined.to_string(), "attr-defined");
548
549        assert_eq!(
550            "union-attr".parse::<RuleName>().unwrap(),
551            RuleName::UnionAttr
552        );
553        assert_eq!(RuleName::UnionAttr.to_string(), "union-attr");
554    }
555
556    #[test]
557    fn test_pyright_rules() {
558        assert_eq!(
559            "reportGeneralTypeIssues".parse::<RuleName>().unwrap(),
560            RuleName::ReportGeneralTypeIssues
561        );
562        assert_eq!(
563            RuleName::ReportGeneralTypeIssues.to_string(),
564            "reportGeneralTypeIssues"
565        );
566    }
567
568    #[test]
569    fn test_custom_rule() {
570        assert_eq!(
571            "unknown-rule".parse::<RuleName>().unwrap(),
572            RuleName::Custom("unknown-rule".to_string())
573        );
574        assert_eq!(RuleName::Custom("custom".to_string()).to_string(), "custom");
575        assert!("attr-defined".parse::<RuleName>().unwrap().is_known());
576        assert!(!"unknown-rule".parse::<RuleName>().unwrap().is_known());
577    }
578}