-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathconfigOptions.ts
More file actions
2188 lines (1930 loc) · 85.3 KB
/
configOptions.ts
File metadata and controls
2188 lines (1930 loc) · 85.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* configOptions.ts
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
* Author: Eric Traut
*
* Class that holds the configuration options for the analyzer.
*/
import { ImportLogger } from '../analyzer/importLogger';
import { getPathsFromPthFiles } from '../analyzer/pythonPathUtils';
import * as pathConsts from '../common/pathConsts';
import { appendArray } from './collectionUtils';
import {
DiagnosticBooleanOverridesMap,
DiagnosticSeverityOverrides,
DiagnosticSeverityOverridesMap,
getDiagnosticSeverityOverrides,
} from './commandLineOptions';
import { ConsoleInterface, NoErrorConsole, NullConsole } from './console';
import { isBoolean } from './core';
import { TaskListToken } from './diagnostic';
import { DiagnosticRule } from './diagnosticRules';
import { FileSystem } from './fileSystem';
import { Host } from './host';
import { PythonVersion, latestStablePythonVersion } from './pythonVersion';
import { ServiceKeys } from './serviceKeys';
import { ServiceProvider } from './serviceProvider';
import { Uri } from './uri/uri';
import { FileSpec, getFileSpec, isDirectory } from './uri/uriUtils';
import { userFacingOptionsList } from './stringUtils';
// prevent upstream changes from sneaking in and adding errors using console.error,
// which is cringe because it doesn't change the exit code
/* eslint no-console: ["error", { allow: ["log"] }] */
export enum PythonPlatform {
Darwin = 'Darwin',
Windows = 'Windows',
Linux = 'Linux',
}
export class ExecutionEnvironment {
// Root directory for execution.
// Undefined if this is a rootless environment (e.g., open file mode).
root?: Uri;
// Name of a virtual environment if there is one, otherwise
// just the path to the python executable.
name: string;
// Always default to the latest stable version of the language.
pythonVersion: PythonVersion;
// Default to no platform.
pythonPlatform?: string | undefined;
// Default to no extra paths.
extraPaths: Uri[] = [];
// Diagnostic rules with overrides.
diagnosticRuleSet: DiagnosticRuleSet;
// Skip import resolution attempts for native libraries. These can
// be expensive and are not needed for some use cases (e.g. web-based
// tools or playgrounds).
skipNativeLibraries: boolean;
// Default to "." which indicates every file in the project.
constructor(
name: string,
root: Uri,
defaultDiagRuleSet: DiagnosticRuleSet,
defaultPythonVersion: PythonVersion | undefined,
defaultPythonPlatform: string | undefined,
defaultExtraPaths: Uri[] | undefined,
skipNativeLibraries = false
) {
this.name = name;
this.root = root;
this.pythonVersion = defaultPythonVersion ?? latestStablePythonVersion;
this.pythonPlatform = defaultPythonPlatform;
this.extraPaths = Array.from(defaultExtraPaths ?? []);
this.diagnosticRuleSet = { ...defaultDiagRuleSet };
this.skipNativeLibraries = skipNativeLibraries;
}
}
export type DiagnosticLevel = 'none' | 'information' | 'warning' | 'error' | 'hint';
export type TypeCheckingMode = (typeof allTypeCheckingModes)[number];
export enum SignatureDisplayType {
compact = 'compact',
formatted = 'formatted',
}
export interface DiagnosticRuleSet {
// Should "Unknown" types be reported as "Any"?
printUnknownAsAny: boolean;
// Should type arguments to a generic class be omitted
// when printed if all arguments are Unknown?
omitTypeArgsIfUnknown: boolean;
// Should parameter type be omitted if it is not annotated?
omitUnannotatedParamType: boolean;
// Indicate when a type is conditional based on a constrained
// type variable type?
omitConditionalConstraint: boolean;
// Should Union and Optional types be printed in PEP 604 format?
pep604Printing: boolean;
// Use strict inference rules for list expressions?
strictListInference: boolean;
// Use strict inference rules for set expressions?
strictSetInference: boolean;
// Use strict inference rules for dictionary expressions?
strictDictionaryInference: boolean;
// Analyze functions and methods that have no annotations?
analyzeUnannotatedFunctions: boolean;
// Use strict type rules for parameters assigned default of None?
strictParameterNoneValue: boolean;
// Enable experimental features that are not yet part of the
// official Python typing spec?
enableExperimentalFeatures: boolean;
// Enable support for type: ignore comments?
enableTypeIgnoreComments: boolean;
// Use tagged hints to identify unreachable code via type analysis?
enableReachabilityAnalysis: boolean;
// Treat old typing aliases as deprecated if pythonVersion >= 3.9?
deprecateTypingAliases: boolean;
// No longer treat bytearray and memoryview as subclasses of bytes?
disableBytesTypePromotions: boolean;
// Report general type issues?
reportGeneralTypeIssues: DiagnosticLevel;
// Report mismatch in types between property getter and setter?
reportPropertyTypeMismatch: DiagnosticLevel;
// Report the use of unknown member accesses on function objects?
reportFunctionMemberAccess: DiagnosticLevel;
// Report missing imports?
reportMissingImports: DiagnosticLevel;
// Report missing imported module source files?
reportMissingModuleSource: DiagnosticLevel;
// Report invalid type annotation forms?
reportInvalidTypeForm: DiagnosticLevel;
// Report missing type stub files?
reportMissingTypeStubs: DiagnosticLevel;
// Report cycles in import graph?
reportImportCycles: DiagnosticLevel;
// Report imported symbol that is not accessed?
reportUnusedImport: DiagnosticLevel;
// Report private class that is not accessed?
reportUnusedClass: DiagnosticLevel;
// Report private function or method that is not accessed?
reportUnusedFunction: DiagnosticLevel;
// Report variable that is not accessed?
reportUnusedVariable: DiagnosticLevel;
// Report symbol or module that is imported more than once?
reportDuplicateImport: DiagnosticLevel;
// Report use of wildcard import for non-local imports?
reportWildcardImportFromLibrary: DiagnosticLevel;
// Report use of abstract method or variable?
reportAbstractUsage: DiagnosticLevel;
// Report instantiation of abstract class with no abstract methods?
reportExplicitAbstractUsage: DiagnosticLevel;
// Report argument type incompatibilities?
reportArgumentType: DiagnosticLevel;
// Report failure of assert_type call?
reportAssertTypeFailure: DiagnosticLevel;
// Report type incompatibility for assignments?
reportAssignmentType: DiagnosticLevel;
// Report issues related to attribute access expressions?
reportAttributeAccessIssue: DiagnosticLevel;
// Report issues related to call expressions?
reportCallIssue: DiagnosticLevel;
// Report inconsistencies with function overload signatures?
reportInconsistentOverload: DiagnosticLevel;
// Report issues with index operations and expressions?
reportIndexIssue: DiagnosticLevel;
// Report invalid type argument usage?
reportInvalidTypeArguments: DiagnosticLevel;
// Report missing overloaded function implementation?
reportNoOverloadImplementation: DiagnosticLevel;
// Report issues related to the use of unary or binary operators?
reportOperatorIssue: DiagnosticLevel;
// Report attempts to subscript (index) an Optional type?
reportOptionalSubscript: DiagnosticLevel;
// Report attempts to access members on a Optional type?
reportOptionalMemberAccess: DiagnosticLevel;
// Report attempts to call a Optional type?
reportOptionalCall: DiagnosticLevel;
// Report attempts to use an Optional type as an iterable?
reportOptionalIterable: DiagnosticLevel;
// Report attempts to use an Optional type in a "with" statement?
reportOptionalContextManager: DiagnosticLevel;
// Report attempts to use an Optional type in a binary or unary operation?
reportOptionalOperand: DiagnosticLevel;
// Report attempts to redeclare the type of a symbol?
reportRedeclaration: DiagnosticLevel;
// Report return type mismatches?
reportReturnType: DiagnosticLevel;
// Report accesses to non-required TypedDict fields?
reportTypedDictNotRequiredAccess: DiagnosticLevel;
// Report untyped function decorators that obscure the function type?
reportUntypedFunctionDecorator: DiagnosticLevel;
// Report untyped class decorators that obscure the class type?
reportUntypedClassDecorator: DiagnosticLevel;
// Report untyped base class that obscure the class type?
reportUntypedBaseClass: DiagnosticLevel;
// Report use of untyped namedtuple factory method?
reportUntypedNamedTuple: DiagnosticLevel;
// Report usage of private variables and functions outside of
// the owning class or module?
reportPrivateUsage: DiagnosticLevel;
// Report usage of deprecated type comments.
reportTypeCommentUsage: DiagnosticLevel;
// Report usage of an import from a py.typed module that is
// not meant to be re-exported from that module.
reportPrivateImportUsage: DiagnosticLevel;
// Report attempts to redefine variables that are in all-caps.
reportConstantRedefinition: DiagnosticLevel;
// Report use of deprecated classes or functions.
reportDeprecated: DiagnosticLevel;
// Report usage of method override that is incompatible with
// the base class method of the same name?
reportIncompatibleMethodOverride: DiagnosticLevel;
// Report usage of variable override that is incompatible with
// the base class symbol of the same name?
reportIncompatibleVariableOverride: DiagnosticLevel;
// Report inconsistencies between __init__ and __new__ signatures.
reportInconsistentConstructor: DiagnosticLevel;
// Report function overloads that overlap in signature but have
// incompatible return types.
reportOverlappingOverload: DiagnosticLevel;
// Report usage of possibly unbound variables.
reportPossiblyUnboundVariable: DiagnosticLevel;
// Report failure to call super().__init__() in __init__ method.
reportMissingSuperCall: DiagnosticLevel;
// Report instance variables that are not initialized within
// the constructor.
reportUninitializedInstanceVariable: DiagnosticLevel;
// Report usage of invalid escape sequences in string literals?
reportInvalidStringEscapeSequence: DiagnosticLevel;
// Report usage of unknown input or return parameters for functions?
reportUnknownParameterType: DiagnosticLevel;
// Report usage of unknown arguments for function calls?
reportUnknownArgumentType: DiagnosticLevel;
// Report usage of unknown input or return parameters for lambdas?
reportUnknownLambdaType: DiagnosticLevel;
// Report usage of unknown input or return parameters?
reportUnknownVariableType: DiagnosticLevel;
// Report usage of unknown input or return parameters?
reportUnknownMemberType: DiagnosticLevel;
// Report input parameters that are missing type annotations?
reportMissingParameterType: DiagnosticLevel;
// Report usage of generic class without explicit type arguments?
reportMissingTypeArgument: DiagnosticLevel;
// Report improper usage of type variables within function signatures?
reportInvalidTypeVarUse: DiagnosticLevel;
// Report usage of function call within default value
// initialization expression?
reportCallInDefaultInitializer: DiagnosticLevel;
// Report calls to isinstance or issubclass that are statically determined
// to always be true.
reportUnnecessaryIsInstance: DiagnosticLevel;
// Report calls to cast that are statically determined
// to always unnecessary.
reportUnnecessaryCast: DiagnosticLevel;
// Report == or != operators that always evaluate to True or False.
reportUnnecessaryComparison: DiagnosticLevel;
// Report 'in' operations that always evaluate to True or False.
reportUnnecessaryContains: DiagnosticLevel;
// Report assert expressions that will always evaluate to true.
reportAssertAlwaysTrue: DiagnosticLevel;
// Report when "self" or "cls" parameter is missing or is misnamed.
reportSelfClsParameterName: DiagnosticLevel;
// Report implicit concatenation of string literals.
reportImplicitStringConcatenation: DiagnosticLevel;
// Report usage of undefined variables.
reportUndefinedVariable: DiagnosticLevel;
// Report usage of unbound variables.
reportUnboundVariable: DiagnosticLevel;
// Report use of unhashable type in a dictionary.
reportUnhashable: DiagnosticLevel;
// Report statements that are syntactically correct but
// have no semantic meaning within a type stub file.
reportInvalidStubStatement: DiagnosticLevel;
// Report usage of __getattr__ at the module level in a stub.
reportIncompleteStub: DiagnosticLevel;
// Report operations on __all__ symbol that are not supported
// by a static type checker.
reportUnsupportedDunderAll: DiagnosticLevel;
// Report cases where a call expression's return result is not
// None and is not used in any way.
reportUnusedCallResult: DiagnosticLevel;
// Report cases where a call expression's return result is Coroutine
// and is not used in any way.
reportUnusedCoroutine: DiagnosticLevel;
// Report except clause that is unreachable.
reportUnusedExcept: DiagnosticLevel;
// Report cases where a simple expression result is not used in any way.
reportUnusedExpression: DiagnosticLevel;
// Report cases where the removal of a "# type: ignore" or "# pyright: ignore"
// comment would have no effect.
reportUnnecessaryTypeIgnoreComment: DiagnosticLevel;
// Report cases where the a "match" statement is not exhaustive in
// covering all possible cases.
reportMatchNotExhaustive: DiagnosticLevel;
// Report code that is determined to be unreachable via type analysis.
reportUnreachable: DiagnosticLevel;
// Report missing @override decorator.
reportImplicitOverride: DiagnosticLevel;
// basedpyright options:
/**
* this probably doesn't really fit as a diagnostic rule config, but it's here because we want the default
* "fail on warnings" behavior to be different depending on the `typeCheckingMode`. this is kinda weird,
* but a compromize we're making to enforce the strictest checks by default without bombarding the user
* with too many errors.
* @see https://github.com/DetachHead/basedpyright/issues/603#issuecomment-2303297625
*/
failOnWarnings: boolean;
strictGenericNarrowing: boolean;
enableBasedFeatures: boolean;
reportAny: DiagnosticLevel;
reportExplicitAny: DiagnosticLevel;
reportIgnoreCommentWithoutRule: DiagnosticLevel;
reportPrivateLocalImportUsage: DiagnosticLevel;
reportImplicitRelativeImport: DiagnosticLevel;
reportInvalidCast: DiagnosticLevel;
reportUnsafeMultipleInheritance: DiagnosticLevel;
reportUnusedParameter: DiagnosticLevel;
reportImplicitAbstractClass: DiagnosticLevel;
reportUnannotatedClassAttribute: DiagnosticLevel;
reportIncompatibleUnannotatedOverride: DiagnosticLevel;
reportInvalidAbstractMethod: DiagnosticLevel;
reportSelfClsDefault: DiagnosticLevel;
allowedUntypedLibraries: string[];
}
export function cloneDiagnosticRuleSet(diagSettings: DiagnosticRuleSet): DiagnosticRuleSet {
// Create a shallow copy of the existing object.
return Object.assign({}, diagSettings);
}
// Returns a list of the diagnostic rules that are configured with
// a true or false value.
export function getBooleanDiagnosticRules(includeNonOverridable = false) {
const boolRules = [
DiagnosticRule.strictListInference,
DiagnosticRule.strictSetInference,
DiagnosticRule.strictDictionaryInference,
DiagnosticRule.analyzeUnannotatedFunctions,
DiagnosticRule.strictParameterNoneValue,
DiagnosticRule.enableBasedFeatures,
DiagnosticRule.enableExperimentalFeatures,
DiagnosticRule.deprecateTypingAliases,
DiagnosticRule.disableBytesTypePromotions,
DiagnosticRule.strictGenericNarrowing,
];
if (includeNonOverridable) {
// Do not include these because we don't
// want to support it within pyright comments.
boolRules.push(DiagnosticRule.enableTypeIgnoreComments);
boolRules.push(DiagnosticRule.enableReachabilityAnalysis);
boolRules.push(DiagnosticRule.failOnWarnings);
}
return boolRules;
}
// Returns a list of the diagnostic rules that are configured with
// a diagnostic level ('none', 'error', etc.).
export function getDiagLevelDiagnosticRules() {
return [
DiagnosticRule.reportGeneralTypeIssues,
DiagnosticRule.reportPropertyTypeMismatch,
DiagnosticRule.reportFunctionMemberAccess,
DiagnosticRule.reportMissingImports,
DiagnosticRule.reportMissingModuleSource,
DiagnosticRule.reportInvalidTypeForm,
DiagnosticRule.reportMissingTypeStubs,
DiagnosticRule.reportImportCycles,
DiagnosticRule.reportUnusedImport,
DiagnosticRule.reportUnusedClass,
DiagnosticRule.reportUnusedFunction,
DiagnosticRule.reportUnusedVariable,
DiagnosticRule.reportDuplicateImport,
DiagnosticRule.reportWildcardImportFromLibrary,
DiagnosticRule.reportAbstractUsage,
DiagnosticRule.reportExplicitAbstractUsage,
DiagnosticRule.reportArgumentType,
DiagnosticRule.reportAssertTypeFailure,
DiagnosticRule.reportAssignmentType,
DiagnosticRule.reportAttributeAccessIssue,
DiagnosticRule.reportCallIssue,
DiagnosticRule.reportInconsistentOverload,
DiagnosticRule.reportIndexIssue,
DiagnosticRule.reportInvalidTypeArguments,
DiagnosticRule.reportNoOverloadImplementation,
DiagnosticRule.reportOperatorIssue,
DiagnosticRule.reportOptionalSubscript,
DiagnosticRule.reportOptionalMemberAccess,
DiagnosticRule.reportOptionalCall,
DiagnosticRule.reportOptionalIterable,
DiagnosticRule.reportOptionalContextManager,
DiagnosticRule.reportOptionalOperand,
DiagnosticRule.reportRedeclaration,
DiagnosticRule.reportReturnType,
DiagnosticRule.reportTypedDictNotRequiredAccess,
DiagnosticRule.reportUntypedFunctionDecorator,
DiagnosticRule.reportUntypedClassDecorator,
DiagnosticRule.reportUntypedBaseClass,
DiagnosticRule.reportUntypedNamedTuple,
DiagnosticRule.reportPrivateUsage,
DiagnosticRule.reportTypeCommentUsage,
DiagnosticRule.reportPrivateImportUsage,
DiagnosticRule.reportConstantRedefinition,
DiagnosticRule.reportDeprecated,
DiagnosticRule.reportIncompatibleMethodOverride,
DiagnosticRule.reportIncompatibleVariableOverride,
DiagnosticRule.reportInconsistentConstructor,
DiagnosticRule.reportOverlappingOverload,
DiagnosticRule.reportPossiblyUnboundVariable,
DiagnosticRule.reportMissingSuperCall,
DiagnosticRule.reportUninitializedInstanceVariable,
DiagnosticRule.reportInvalidStringEscapeSequence,
DiagnosticRule.reportUnknownParameterType,
DiagnosticRule.reportUnknownArgumentType,
DiagnosticRule.reportUnknownLambdaType,
DiagnosticRule.reportUnknownVariableType,
DiagnosticRule.reportUnknownMemberType,
DiagnosticRule.reportMissingParameterType,
DiagnosticRule.reportMissingTypeArgument,
DiagnosticRule.reportInvalidTypeVarUse,
DiagnosticRule.reportCallInDefaultInitializer,
DiagnosticRule.reportUnnecessaryIsInstance,
DiagnosticRule.reportUnnecessaryCast,
DiagnosticRule.reportUnnecessaryComparison,
DiagnosticRule.reportUnnecessaryContains,
DiagnosticRule.reportAssertAlwaysTrue,
DiagnosticRule.reportSelfClsParameterName,
DiagnosticRule.reportImplicitStringConcatenation,
DiagnosticRule.reportUndefinedVariable,
DiagnosticRule.reportUnhashable,
DiagnosticRule.reportUnboundVariable,
DiagnosticRule.reportInvalidStubStatement,
DiagnosticRule.reportIncompleteStub,
DiagnosticRule.reportUnsupportedDunderAll,
DiagnosticRule.reportUnusedCallResult,
DiagnosticRule.reportUnusedCoroutine,
DiagnosticRule.reportUnusedExcept,
DiagnosticRule.reportUnusedExpression,
DiagnosticRule.reportUnnecessaryTypeIgnoreComment,
DiagnosticRule.reportMatchNotExhaustive,
DiagnosticRule.reportUnreachable,
DiagnosticRule.reportImplicitOverride,
DiagnosticRule.reportAny,
DiagnosticRule.reportExplicitAny,
DiagnosticRule.reportIgnoreCommentWithoutRule,
DiagnosticRule.reportInvalidCast,
DiagnosticRule.reportImplicitRelativeImport,
DiagnosticRule.reportPrivateLocalImportUsage,
DiagnosticRule.reportUnsafeMultipleInheritance,
DiagnosticRule.reportUnusedParameter,
DiagnosticRule.reportImplicitAbstractClass,
DiagnosticRule.reportUnannotatedClassAttribute,
DiagnosticRule.reportIncompatibleUnannotatedOverride,
DiagnosticRule.reportInvalidAbstractMethod,
DiagnosticRule.reportSelfClsDefault,
];
}
export const unreachableDiagnosticRules = () => [DiagnosticRule.reportUnreachable, DiagnosticRule.reportUnusedExcept];
export const unusedDiagnosticRules = () => [
DiagnosticRule.reportUnusedClass,
DiagnosticRule.reportUnusedImport,
DiagnosticRule.reportUnusedFunction,
DiagnosticRule.reportUnusedVariable,
DiagnosticRule.reportUnusedParameter,
];
export const deprecatedDiagnosticRules = () => [DiagnosticRule.reportDeprecated, DiagnosticRule.reportTypeCommentUsage];
// TODO: should this be removed? there was documentation stating that when typeCheckingMode is "strict"
// diagnostics can't be overridden with a less strict level. as far as i can tell this isn't the case
// so i think this function is useless
export function getStrictModeNotOverriddenRules() {
// In strict mode, the value in the user config file should be honored and
// not overwritten by the value from the strict rule set.
return [DiagnosticRule.reportMissingModuleSource];
}
export function getOffDiagnosticRuleSet(): DiagnosticRuleSet {
const diagSettings: DiagnosticRuleSet = {
printUnknownAsAny: true,
omitTypeArgsIfUnknown: true,
omitUnannotatedParamType: true,
omitConditionalConstraint: true,
pep604Printing: true,
strictListInference: false,
strictSetInference: false,
strictDictionaryInference: false,
analyzeUnannotatedFunctions: true, // required for completions
strictParameterNoneValue: false,
enableBasedFeatures: false,
enableExperimentalFeatures: false,
enableTypeIgnoreComments: true,
enableReachabilityAnalysis: false,
deprecateTypingAliases: false,
disableBytesTypePromotions: true,
reportGeneralTypeIssues: 'none',
reportPropertyTypeMismatch: 'none',
reportFunctionMemberAccess: 'none',
reportMissingImports: 'none',
reportMissingModuleSource: 'none',
reportInvalidTypeForm: 'none',
reportMissingTypeStubs: 'none',
reportImportCycles: 'none',
reportUnusedImport: 'hint',
reportUnusedClass: 'hint',
reportUnusedFunction: 'hint',
reportUnusedVariable: 'hint',
reportDuplicateImport: 'none',
reportWildcardImportFromLibrary: 'none',
reportAbstractUsage: 'none',
reportExplicitAbstractUsage: 'none',
reportArgumentType: 'none',
reportAssertTypeFailure: 'none',
reportAssignmentType: 'none',
reportAttributeAccessIssue: 'none',
reportCallIssue: 'none',
reportInconsistentOverload: 'none',
reportIndexIssue: 'none',
reportInvalidTypeArguments: 'none',
reportNoOverloadImplementation: 'none',
reportOperatorIssue: 'none',
reportOptionalSubscript: 'none',
reportOptionalMemberAccess: 'none',
reportOptionalCall: 'none',
reportOptionalIterable: 'none',
reportOptionalContextManager: 'none',
reportOptionalOperand: 'none',
reportRedeclaration: 'none',
reportReturnType: 'none',
reportTypedDictNotRequiredAccess: 'none',
reportUntypedFunctionDecorator: 'none',
reportUntypedClassDecorator: 'none',
reportUntypedBaseClass: 'none',
reportUntypedNamedTuple: 'none',
reportPrivateUsage: 'none',
reportTypeCommentUsage: 'hint',
reportPrivateImportUsage: 'none',
reportConstantRedefinition: 'none',
reportDeprecated: 'hint',
reportIncompatibleMethodOverride: 'none',
reportIncompatibleVariableOverride: 'none',
reportInconsistentConstructor: 'none',
reportOverlappingOverload: 'none',
reportPossiblyUnboundVariable: 'none',
reportMissingSuperCall: 'none',
reportUninitializedInstanceVariable: 'none',
reportInvalidStringEscapeSequence: 'none',
reportUnknownParameterType: 'none',
reportUnknownArgumentType: 'none',
reportUnknownLambdaType: 'none',
reportUnknownVariableType: 'none',
reportUnknownMemberType: 'none',
reportMissingParameterType: 'none',
reportMissingTypeArgument: 'none',
reportInvalidTypeVarUse: 'none',
reportCallInDefaultInitializer: 'none',
reportUnnecessaryIsInstance: 'none',
reportUnnecessaryCast: 'none',
reportUnnecessaryComparison: 'none',
reportUnnecessaryContains: 'none',
reportAssertAlwaysTrue: 'none',
reportSelfClsParameterName: 'none',
reportImplicitStringConcatenation: 'none',
reportUnboundVariable: 'none',
reportUnhashable: 'none',
reportUndefinedVariable: 'none',
reportInvalidStubStatement: 'none',
reportIncompleteStub: 'none',
reportUnsupportedDunderAll: 'none',
reportUnusedCallResult: 'none',
reportUnusedCoroutine: 'none',
reportUnusedExcept: 'hint',
reportUnusedExpression: 'none',
reportUnnecessaryTypeIgnoreComment: 'none',
reportMatchNotExhaustive: 'none',
reportUnreachable: 'hint',
reportImplicitOverride: 'none',
failOnWarnings: false,
strictGenericNarrowing: false,
reportAny: 'none',
reportExplicitAny: 'none',
reportIgnoreCommentWithoutRule: 'none',
reportPrivateLocalImportUsage: 'none',
reportImplicitRelativeImport: 'none',
reportInvalidCast: 'none',
reportUnsafeMultipleInheritance: 'none',
reportUnusedParameter: 'hint',
reportImplicitAbstractClass: 'none',
reportUnannotatedClassAttribute: 'none',
reportIncompatibleUnannotatedOverride: 'none',
reportInvalidAbstractMethod: 'none',
reportSelfClsDefault: 'none',
allowedUntypedLibraries: [],
};
return diagSettings;
}
export function getBasicDiagnosticRuleSet(): DiagnosticRuleSet {
const diagSettings: DiagnosticRuleSet = {
printUnknownAsAny: false,
omitTypeArgsIfUnknown: false,
omitUnannotatedParamType: true,
omitConditionalConstraint: false,
pep604Printing: true,
strictListInference: false,
strictSetInference: false,
strictDictionaryInference: false,
analyzeUnannotatedFunctions: true,
strictParameterNoneValue: true,
enableBasedFeatures: false,
enableExperimentalFeatures: false,
enableTypeIgnoreComments: true,
enableReachabilityAnalysis: true,
deprecateTypingAliases: false,
disableBytesTypePromotions: true,
reportGeneralTypeIssues: 'error',
reportPropertyTypeMismatch: 'none',
reportFunctionMemberAccess: 'none',
reportMissingImports: 'error',
reportMissingModuleSource: 'warning',
reportInvalidTypeForm: 'error',
reportMissingTypeStubs: 'none',
reportImportCycles: 'none',
reportUnusedImport: 'hint',
reportUnusedClass: 'hint',
reportUnusedFunction: 'hint',
reportUnusedVariable: 'hint',
reportDuplicateImport: 'none',
reportWildcardImportFromLibrary: 'warning',
reportAbstractUsage: 'error',
reportExplicitAbstractUsage: 'error',
reportArgumentType: 'error',
reportAssertTypeFailure: 'error',
reportAssignmentType: 'error',
reportAttributeAccessIssue: 'error',
reportCallIssue: 'error',
reportInconsistentOverload: 'error',
reportIndexIssue: 'error',
reportInvalidTypeArguments: 'error',
reportNoOverloadImplementation: 'error',
reportOperatorIssue: 'error',
reportOptionalSubscript: 'error',
reportOptionalMemberAccess: 'error',
reportOptionalCall: 'error',
reportOptionalIterable: 'error',
reportOptionalContextManager: 'error',
reportOptionalOperand: 'error',
reportRedeclaration: 'error',
reportReturnType: 'error',
reportTypedDictNotRequiredAccess: 'error',
reportUntypedFunctionDecorator: 'none',
reportUntypedClassDecorator: 'none',
reportUntypedBaseClass: 'none',
reportUntypedNamedTuple: 'none',
reportPrivateUsage: 'none',
reportTypeCommentUsage: 'hint',
reportPrivateImportUsage: 'error',
reportConstantRedefinition: 'none',
reportDeprecated: 'hint',
reportIncompatibleMethodOverride: 'none',
reportIncompatibleVariableOverride: 'none',
reportInconsistentConstructor: 'none',
reportOverlappingOverload: 'none',
reportPossiblyUnboundVariable: 'none',
reportMissingSuperCall: 'none',
reportUninitializedInstanceVariable: 'none',
reportInvalidStringEscapeSequence: 'warning',
reportUnknownParameterType: 'none',
reportUnknownArgumentType: 'none',
reportUnknownLambdaType: 'none',
reportUnknownVariableType: 'none',
reportUnknownMemberType: 'none',
reportMissingParameterType: 'none',
reportMissingTypeArgument: 'none',
reportInvalidTypeVarUse: 'warning',
reportCallInDefaultInitializer: 'none',
reportUnnecessaryIsInstance: 'none',
reportUnnecessaryCast: 'none',
reportUnnecessaryComparison: 'none',
reportUnnecessaryContains: 'none',
reportAssertAlwaysTrue: 'warning',
reportSelfClsParameterName: 'warning',
reportImplicitStringConcatenation: 'none',
reportUnboundVariable: 'error',
reportUnhashable: 'error',
reportUndefinedVariable: 'error',
reportInvalidStubStatement: 'none',
reportIncompleteStub: 'none',
reportUnsupportedDunderAll: 'warning',
reportUnusedCallResult: 'none',
reportUnusedCoroutine: 'error',
reportUnusedExcept: 'error',
reportUnusedExpression: 'warning',
reportUnnecessaryTypeIgnoreComment: 'none',
reportMatchNotExhaustive: 'none',
reportUnreachable: 'hint',
reportImplicitOverride: 'none',
failOnWarnings: false,
strictGenericNarrowing: false,
reportAny: 'none',
reportExplicitAny: 'none',
reportIgnoreCommentWithoutRule: 'none',
reportPrivateLocalImportUsage: 'none',
reportImplicitRelativeImport: 'none',
reportInvalidCast: 'none',
reportUnsafeMultipleInheritance: 'none',
reportUnusedParameter: 'hint',
reportImplicitAbstractClass: 'none',
reportUnannotatedClassAttribute: 'none',
reportIncompatibleUnannotatedOverride: 'none',
reportInvalidAbstractMethod: 'none',
reportSelfClsDefault: 'none',
allowedUntypedLibraries: [],
};
return diagSettings;
}
export function getStandardDiagnosticRuleSet(): DiagnosticRuleSet {
const diagSettings: DiagnosticRuleSet = {
printUnknownAsAny: false,
omitTypeArgsIfUnknown: false,
omitUnannotatedParamType: true,
omitConditionalConstraint: false,
pep604Printing: true,
strictListInference: false,
strictSetInference: false,
strictDictionaryInference: false,
analyzeUnannotatedFunctions: true,
strictParameterNoneValue: true,
enableBasedFeatures: false,
enableExperimentalFeatures: false,
enableTypeIgnoreComments: true,
enableReachabilityAnalysis: true,
deprecateTypingAliases: false,
disableBytesTypePromotions: true,
reportGeneralTypeIssues: 'error',
reportPropertyTypeMismatch: 'none',
reportFunctionMemberAccess: 'error',
reportMissingImports: 'error',
reportMissingModuleSource: 'warning',
reportInvalidTypeForm: 'error',
reportMissingTypeStubs: 'none',
reportImportCycles: 'none',
reportUnusedImport: 'hint',
reportUnusedClass: 'hint',
reportUnusedFunction: 'hint',
reportUnusedVariable: 'hint',
reportDuplicateImport: 'none',
reportWildcardImportFromLibrary: 'warning',
reportAbstractUsage: 'error',
reportExplicitAbstractUsage: 'error',
reportArgumentType: 'error',
reportAssertTypeFailure: 'error',
reportAssignmentType: 'error',
reportAttributeAccessIssue: 'error',
reportCallIssue: 'error',
reportInconsistentOverload: 'error',
reportIndexIssue: 'error',
reportInvalidTypeArguments: 'error',
reportNoOverloadImplementation: 'error',
reportOperatorIssue: 'error',
reportOptionalSubscript: 'error',
reportOptionalMemberAccess: 'error',
reportOptionalCall: 'error',
reportOptionalIterable: 'error',
reportOptionalContextManager: 'error',
reportOptionalOperand: 'error',
reportRedeclaration: 'error',
reportReturnType: 'error',
reportTypedDictNotRequiredAccess: 'error',
reportUntypedFunctionDecorator: 'none',
reportUntypedClassDecorator: 'none',
reportUntypedBaseClass: 'none',
reportUntypedNamedTuple: 'none',
reportPrivateUsage: 'none',
reportTypeCommentUsage: 'hint',
reportPrivateImportUsage: 'error',
reportConstantRedefinition: 'none',
reportDeprecated: 'hint',
reportIncompatibleMethodOverride: 'error',
reportIncompatibleVariableOverride: 'error',
reportInconsistentConstructor: 'none',
reportOverlappingOverload: 'error',
reportPossiblyUnboundVariable: 'error',
reportMissingSuperCall: 'none',
reportUninitializedInstanceVariable: 'none',
reportInvalidStringEscapeSequence: 'warning',
reportUnknownParameterType: 'none',
reportUnknownArgumentType: 'none',
reportUnknownLambdaType: 'none',
reportUnknownVariableType: 'none',
reportUnknownMemberType: 'none',
reportMissingParameterType: 'none',
reportMissingTypeArgument: 'none',
reportInvalidTypeVarUse: 'warning',
reportCallInDefaultInitializer: 'none',
reportUnnecessaryIsInstance: 'none',
reportUnnecessaryCast: 'none',
reportUnnecessaryComparison: 'none',
reportUnnecessaryContains: 'none',
reportAssertAlwaysTrue: 'warning',
reportSelfClsParameterName: 'warning',
reportImplicitStringConcatenation: 'none',
reportUnboundVariable: 'error',
reportUnhashable: 'error',
reportUndefinedVariable: 'error',
reportInvalidStubStatement: 'none',
reportIncompleteStub: 'none',
reportUnsupportedDunderAll: 'warning',
reportUnusedCallResult: 'none',
reportUnusedCoroutine: 'error',
reportUnusedExcept: 'error',
reportUnusedExpression: 'warning',
reportUnnecessaryTypeIgnoreComment: 'none',
reportMatchNotExhaustive: 'none',
reportUnreachable: 'hint',
reportImplicitOverride: 'none',
failOnWarnings: false,
strictGenericNarrowing: false,
reportAny: 'none',
reportExplicitAny: 'none',
reportIgnoreCommentWithoutRule: 'none',
reportPrivateLocalImportUsage: 'none',
reportImplicitRelativeImport: 'none',
reportInvalidCast: 'none',
reportUnsafeMultipleInheritance: 'none',
reportUnusedParameter: 'hint',
reportImplicitAbstractClass: 'none',
reportUnannotatedClassAttribute: 'none',
reportIncompatibleUnannotatedOverride: 'none',
reportInvalidAbstractMethod: 'none',
reportSelfClsDefault: 'none',
allowedUntypedLibraries: [],
};
return diagSettings;
}
export const getRecommendedDiagnosticRuleSet = (): DiagnosticRuleSet => ({
printUnknownAsAny: false,
omitTypeArgsIfUnknown: false,
omitUnannotatedParamType: false,
omitConditionalConstraint: false,
pep604Printing: true,
strictListInference: true,
strictSetInference: true,
strictDictionaryInference: true,
analyzeUnannotatedFunctions: true,
strictParameterNoneValue: true,
enableBasedFeatures: false,
enableExperimentalFeatures: false,
enableTypeIgnoreComments: false,
enableReachabilityAnalysis: true,
deprecateTypingAliases: true,
disableBytesTypePromotions: true,
reportGeneralTypeIssues: 'error',
reportPropertyTypeMismatch: 'warning',
reportFunctionMemberAccess: 'error',
reportMissingImports: 'error',
reportMissingModuleSource: 'error',
reportInvalidTypeForm: 'error',
reportMissingTypeStubs: 'warning',
reportImportCycles: 'error',
reportUnusedImport: 'warning',
reportUnusedClass: 'warning',
reportUnusedFunction: 'warning',
reportUnusedVariable: 'warning',
reportDuplicateImport: 'warning',
reportWildcardImportFromLibrary: 'warning',
reportAbstractUsage: 'error',
reportExplicitAbstractUsage: 'error',
reportArgumentType: 'error',
reportAssertTypeFailure: 'error',
reportAssignmentType: 'error',
reportAttributeAccessIssue: 'error',
reportCallIssue: 'error',
reportInconsistentOverload: 'error',
reportIndexIssue: 'error',
reportInvalidTypeArguments: 'error',
reportNoOverloadImplementation: 'error',
reportOperatorIssue: 'error',
reportOptionalSubscript: 'error',
reportOptionalMemberAccess: 'error',
reportOptionalCall: 'error',
reportOptionalIterable: 'error',