eslint 9.38.0 → 9.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,6 @@ import type {
33
33
  LanguageOptions as GenericLanguageOptions,
34
34
  RuleContext as CoreRuleContext,
35
35
  RuleDefinition,
36
- RuleVisitor,
37
36
  SourceRange,
38
37
  TextSourceCode,
39
38
  TraversalStep,
@@ -56,11 +55,40 @@ import type {
56
55
  ProcessorFile as CoreProcessorFile,
57
56
  JavaScriptParserOptionsConfig,
58
57
  RulesMeta,
58
+ RuleConfig,
59
59
  RuleTextEditor,
60
60
  RuleTextEdit,
61
+ RuleVisitor,
62
+ BaseConfig as CoreBaseConfig,
63
+ RuleFixer as CoreRuleFixer,
64
+ ViolationReportBase,
65
+ ViolationMessage,
66
+ ViolationLocation,
67
+ SuggestionMessage,
68
+ LintSuggestion as CoreLintSuggestion,
69
+ JavaScriptSourceType,
70
+ HasRules as CoreHasRules,
71
+ SuggestedEditBase,
72
+ SuggestedEdit,
73
+ ViolationReport,
61
74
  } from "@eslint/core";
62
75
  import { LegacyESLint } from "./use-at-your-own-risk.js";
63
76
 
77
+ //------------------------------------------------------------------------------
78
+ // Helpers
79
+ //------------------------------------------------------------------------------
80
+
81
+ /** Adds matching `:exit` selectors for all properties of a `RuleVisitor`. */
82
+ type WithExit<RuleVisitorType extends RuleVisitor> = {
83
+ [Key in keyof RuleVisitorType as
84
+ | Key
85
+ | `${Key & string}:exit`]: RuleVisitorType[Key];
86
+ };
87
+
88
+ //------------------------------------------------------------------------------
89
+ // Exports
90
+ //------------------------------------------------------------------------------
91
+
64
92
  export namespace AST {
65
93
  type TokenType =
66
94
  | "Boolean"
@@ -133,6 +161,10 @@ export namespace Scope {
133
161
  references: Reference[];
134
162
  through: Reference[];
135
163
  functionExpressionScope: boolean;
164
+ implicit?: {
165
+ variables: Variable[];
166
+ set: Map<string, Variable>;
167
+ };
136
168
  }
137
169
 
138
170
  interface Variable {
@@ -173,7 +205,14 @@ export namespace Scope {
173
205
  node: ESTree.FunctionDeclaration | ESTree.FunctionExpression;
174
206
  parent: null;
175
207
  }
176
- | { type: "ImplicitGlobalVariable"; node: ESTree.Program; parent: null }
208
+ | {
209
+ type: "ImplicitGlobalVariable";
210
+ node:
211
+ | ESTree.AssignmentExpression
212
+ | ESTree.ForInStatement
213
+ | ESTree.ForOfStatement;
214
+ parent: null;
215
+ }
177
216
  | {
178
217
  type: "ImportBinding";
179
218
  node:
@@ -640,480 +679,35 @@ export namespace Rule {
640
679
  LangOptions: Linter.LanguageOptions;
641
680
  Code: SourceCode;
642
681
  RuleOptions: any[];
643
- Visitor: NodeListener;
682
+ Visitor: RuleListener;
644
683
  Node: JSSyntaxElement;
645
684
  MessageIds: string;
646
685
  ExtRuleDocs: {};
647
686
  }> {
648
- create(context: RuleContext): NodeListener;
687
+ create(context: RuleContext): RuleListener;
649
688
  }
650
689
 
651
690
  type NodeTypes = ESTree.Node["type"];
652
- interface NodeListener extends RuleVisitor {
653
- ArrayExpression?:
654
- | ((node: ESTree.ArrayExpression & NodeParentExtension) => void)
655
- | undefined;
656
- "ArrayExpression:exit"?:
657
- | ((node: ESTree.ArrayExpression & NodeParentExtension) => void)
658
- | undefined;
659
- ArrayPattern?:
660
- | ((node: ESTree.ArrayPattern & NodeParentExtension) => void)
661
- | undefined;
662
- "ArrayPattern:exit"?:
663
- | ((node: ESTree.ArrayPattern & NodeParentExtension) => void)
664
- | undefined;
665
- ArrowFunctionExpression?:
666
- | ((
667
- node: ESTree.ArrowFunctionExpression & NodeParentExtension,
668
- ) => void)
669
- | undefined;
670
- "ArrowFunctionExpression:exit"?:
671
- | ((
672
- node: ESTree.ArrowFunctionExpression & NodeParentExtension,
673
- ) => void)
674
- | undefined;
675
- AssignmentExpression?:
676
- | ((
677
- node: ESTree.AssignmentExpression & NodeParentExtension,
678
- ) => void)
679
- | undefined;
680
- "AssignmentExpression:exit"?:
681
- | ((
682
- node: ESTree.AssignmentExpression & NodeParentExtension,
683
- ) => void)
684
- | undefined;
685
- AssignmentPattern?:
686
- | ((node: ESTree.AssignmentPattern & NodeParentExtension) => void)
687
- | undefined;
688
- "AssignmentPattern:exit"?:
689
- | ((node: ESTree.AssignmentPattern & NodeParentExtension) => void)
690
- | undefined;
691
- AwaitExpression?:
692
- | ((node: ESTree.AwaitExpression & NodeParentExtension) => void)
693
- | undefined;
694
- "AwaitExpression:exit"?:
695
- | ((node: ESTree.AwaitExpression & NodeParentExtension) => void)
696
- | undefined;
697
- BinaryExpression?:
698
- | ((node: ESTree.BinaryExpression & NodeParentExtension) => void)
699
- | undefined;
700
- "BinaryExpression:exit"?:
701
- | ((node: ESTree.BinaryExpression & NodeParentExtension) => void)
702
- | undefined;
703
- BlockStatement?:
704
- | ((node: ESTree.BlockStatement & NodeParentExtension) => void)
705
- | undefined;
706
- "BlockStatement:exit"?:
707
- | ((node: ESTree.BlockStatement & NodeParentExtension) => void)
708
- | undefined;
709
- BreakStatement?:
710
- | ((node: ESTree.BreakStatement & NodeParentExtension) => void)
711
- | undefined;
712
- "BreakStatement:exit"?:
713
- | ((node: ESTree.BreakStatement & NodeParentExtension) => void)
714
- | undefined;
715
- CallExpression?:
716
- | ((node: ESTree.CallExpression & NodeParentExtension) => void)
717
- | undefined;
718
- "CallExpression:exit"?:
719
- | ((node: ESTree.CallExpression & NodeParentExtension) => void)
720
- | undefined;
721
- CatchClause?:
722
- | ((node: ESTree.CatchClause & NodeParentExtension) => void)
723
- | undefined;
724
- "CatchClause:exit"?:
725
- | ((node: ESTree.CatchClause & NodeParentExtension) => void)
726
- | undefined;
727
- ChainExpression?:
728
- | ((node: ESTree.ChainExpression & NodeParentExtension) => void)
729
- | undefined;
730
- "ChainExpression:exit"?:
731
- | ((node: ESTree.ChainExpression & NodeParentExtension) => void)
732
- | undefined;
733
- ClassBody?:
734
- | ((node: ESTree.ClassBody & NodeParentExtension) => void)
735
- | undefined;
736
- "ClassBody:exit"?:
737
- | ((node: ESTree.ClassBody & NodeParentExtension) => void)
738
- | undefined;
739
- ClassDeclaration?:
740
- | ((node: ESTree.ClassDeclaration & NodeParentExtension) => void)
741
- | undefined;
742
- "ClassDeclaration:exit"?:
743
- | ((node: ESTree.ClassDeclaration & NodeParentExtension) => void)
744
- | undefined;
745
- ClassExpression?:
746
- | ((node: ESTree.ClassExpression & NodeParentExtension) => void)
747
- | undefined;
748
- "ClassExpression:exit"?:
749
- | ((node: ESTree.ClassExpression & NodeParentExtension) => void)
750
- | undefined;
751
- ConditionalExpression?:
752
- | ((
753
- node: ESTree.ConditionalExpression & NodeParentExtension,
754
- ) => void)
755
- | undefined;
756
- "ConditionalExpression:exit"?:
757
- | ((
758
- node: ESTree.ConditionalExpression & NodeParentExtension,
759
- ) => void)
760
- | undefined;
761
- ContinueStatement?:
762
- | ((node: ESTree.ContinueStatement & NodeParentExtension) => void)
763
- | undefined;
764
- "ContinueStatement:exit"?:
765
- | ((node: ESTree.ContinueStatement & NodeParentExtension) => void)
766
- | undefined;
767
- DebuggerStatement?:
768
- | ((node: ESTree.DebuggerStatement & NodeParentExtension) => void)
769
- | undefined;
770
- "DebuggerStatement:exit"?:
771
- | ((node: ESTree.DebuggerStatement & NodeParentExtension) => void)
772
- | undefined;
773
- DoWhileStatement?:
774
- | ((node: ESTree.DoWhileStatement & NodeParentExtension) => void)
775
- | undefined;
776
- "DoWhileStatement:exit"?:
777
- | ((node: ESTree.DoWhileStatement & NodeParentExtension) => void)
778
- | undefined;
779
- EmptyStatement?:
780
- | ((node: ESTree.EmptyStatement & NodeParentExtension) => void)
781
- | undefined;
782
- "EmptyStatement:exit"?:
783
- | ((node: ESTree.EmptyStatement & NodeParentExtension) => void)
784
- | undefined;
785
- ExportAllDeclaration?:
786
- | ((
787
- node: ESTree.ExportAllDeclaration & NodeParentExtension,
788
- ) => void)
789
- | undefined;
790
- "ExportAllDeclaration:exit"?:
791
- | ((
792
- node: ESTree.ExportAllDeclaration & NodeParentExtension,
793
- ) => void)
794
- | undefined;
795
- ExportDefaultDeclaration?:
796
- | ((
797
- node: ESTree.ExportDefaultDeclaration & NodeParentExtension,
798
- ) => void)
799
- | undefined;
800
- "ExportDefaultDeclaration:exit"?:
801
- | ((
802
- node: ESTree.ExportDefaultDeclaration & NodeParentExtension,
803
- ) => void)
804
- | undefined;
805
- ExportNamedDeclaration?:
806
- | ((
807
- node: ESTree.ExportNamedDeclaration & NodeParentExtension,
808
- ) => void)
809
- | undefined;
810
- "ExportNamedDeclaration:exit"?:
811
- | ((
812
- node: ESTree.ExportNamedDeclaration & NodeParentExtension,
813
- ) => void)
814
- | undefined;
815
- ExportSpecifier?:
816
- | ((node: ESTree.ExportSpecifier & NodeParentExtension) => void)
817
- | undefined;
818
- "ExportSpecifier:exit"?:
819
- | ((node: ESTree.ExportSpecifier & NodeParentExtension) => void)
820
- | undefined;
821
- ExpressionStatement?:
822
- | ((node: ESTree.ExpressionStatement & NodeParentExtension) => void)
823
- | undefined;
824
- "ExpressionStatement:exit"?:
825
- | ((node: ESTree.ExpressionStatement & NodeParentExtension) => void)
826
- | undefined;
827
- ForInStatement?:
828
- | ((node: ESTree.ForInStatement & NodeParentExtension) => void)
829
- | undefined;
830
- "ForInStatement:exit"?:
831
- | ((node: ESTree.ForInStatement & NodeParentExtension) => void)
832
- | undefined;
833
- ForOfStatement?:
834
- | ((node: ESTree.ForOfStatement & NodeParentExtension) => void)
835
- | undefined;
836
- "ForOfStatement:exit"?:
837
- | ((node: ESTree.ForOfStatement & NodeParentExtension) => void)
838
- | undefined;
839
- ForStatement?:
840
- | ((node: ESTree.ForStatement & NodeParentExtension) => void)
841
- | undefined;
842
- "ForStatement:exit"?:
843
- | ((node: ESTree.ForStatement & NodeParentExtension) => void)
844
- | undefined;
845
- FunctionDeclaration?:
846
- | ((node: ESTree.FunctionDeclaration & NodeParentExtension) => void)
847
- | undefined;
848
- "FunctionDeclaration:exit"?:
849
- | ((node: ESTree.FunctionDeclaration & NodeParentExtension) => void)
850
- | undefined;
851
- FunctionExpression?:
852
- | ((node: ESTree.FunctionExpression & NodeParentExtension) => void)
853
- | undefined;
854
- "FunctionExpression:exit"?:
855
- | ((node: ESTree.FunctionExpression & NodeParentExtension) => void)
856
- | undefined;
857
- Identifier?:
858
- | ((node: ESTree.Identifier & NodeParentExtension) => void)
859
- | undefined;
860
- "Identifier:exit"?:
861
- | ((node: ESTree.Identifier & NodeParentExtension) => void)
862
- | undefined;
863
- IfStatement?:
864
- | ((node: ESTree.IfStatement & NodeParentExtension) => void)
865
- | undefined;
866
- "IfStatement:exit"?:
867
- | ((node: ESTree.IfStatement & NodeParentExtension) => void)
868
- | undefined;
869
- ImportDeclaration?:
870
- | ((node: ESTree.ImportDeclaration & NodeParentExtension) => void)
871
- | undefined;
872
- "ImportDeclaration:exit"?:
873
- | ((node: ESTree.ImportDeclaration & NodeParentExtension) => void)
874
- | undefined;
875
- ImportDefaultSpecifier?:
876
- | ((
877
- node: ESTree.ImportDefaultSpecifier & NodeParentExtension,
878
- ) => void)
879
- | undefined;
880
- "ImportDefaultSpecifier:exit"?:
881
- | ((
882
- node: ESTree.ImportDefaultSpecifier & NodeParentExtension,
883
- ) => void)
884
- | undefined;
885
- ImportExpression?:
886
- | ((node: ESTree.ImportExpression & NodeParentExtension) => void)
887
- | undefined;
888
- "ImportExpression:exit"?:
889
- | ((node: ESTree.ImportExpression & NodeParentExtension) => void)
890
- | undefined;
891
- ImportNamespaceSpecifier?:
892
- | ((
893
- node: ESTree.ImportNamespaceSpecifier & NodeParentExtension,
894
- ) => void)
895
- | undefined;
896
- "ImportNamespaceSpecifier:exit"?:
897
- | ((
898
- node: ESTree.ImportNamespaceSpecifier & NodeParentExtension,
899
- ) => void)
900
- | undefined;
901
- ImportSpecifier?:
902
- | ((node: ESTree.ImportSpecifier & NodeParentExtension) => void)
903
- | undefined;
904
- "ImportSpecifier:exit"?:
905
- | ((node: ESTree.ImportSpecifier & NodeParentExtension) => void)
906
- | undefined;
907
- LabeledStatement?:
908
- | ((node: ESTree.LabeledStatement & NodeParentExtension) => void)
909
- | undefined;
910
- "LabeledStatement:exit"?:
911
- | ((node: ESTree.LabeledStatement & NodeParentExtension) => void)
912
- | undefined;
913
- Literal?:
914
- | ((node: ESTree.Literal & NodeParentExtension) => void)
915
- | undefined;
916
- "Literal:exit"?:
917
- | ((node: ESTree.Literal & NodeParentExtension) => void)
918
- | undefined;
919
- LogicalExpression?:
920
- | ((node: ESTree.LogicalExpression & NodeParentExtension) => void)
921
- | undefined;
922
- "LogicalExpression:exit"?:
923
- | ((node: ESTree.LogicalExpression & NodeParentExtension) => void)
924
- | undefined;
925
- MemberExpression?:
926
- | ((node: ESTree.MemberExpression & NodeParentExtension) => void)
927
- | undefined;
928
- "MemberExpression:exit"?:
929
- | ((node: ESTree.MemberExpression & NodeParentExtension) => void)
930
- | undefined;
931
- MetaProperty?:
932
- | ((node: ESTree.MetaProperty & NodeParentExtension) => void)
933
- | undefined;
934
- "MetaProperty:exit"?:
935
- | ((node: ESTree.MetaProperty & NodeParentExtension) => void)
936
- | undefined;
937
- MethodDefinition?:
938
- | ((node: ESTree.MethodDefinition & NodeParentExtension) => void)
939
- | undefined;
940
- "MethodDefinition:exit"?:
941
- | ((node: ESTree.MethodDefinition & NodeParentExtension) => void)
942
- | undefined;
943
- NewExpression?:
944
- | ((node: ESTree.NewExpression & NodeParentExtension) => void)
945
- | undefined;
946
- "NewExpression:exit"?:
947
- | ((node: ESTree.NewExpression & NodeParentExtension) => void)
948
- | undefined;
949
- ObjectExpression?:
950
- | ((node: ESTree.ObjectExpression & NodeParentExtension) => void)
951
- | undefined;
952
- "ObjectExpression:exit"?:
953
- | ((node: ESTree.ObjectExpression & NodeParentExtension) => void)
954
- | undefined;
955
- ObjectPattern?:
956
- | ((node: ESTree.ObjectPattern & NodeParentExtension) => void)
957
- | undefined;
958
- "ObjectPattern:exit"?:
959
- | ((node: ESTree.ObjectPattern & NodeParentExtension) => void)
960
- | undefined;
961
- PrivateIdentifier?:
962
- | ((node: ESTree.PrivateIdentifier & NodeParentExtension) => void)
963
- | undefined;
964
- "PrivateIdentifier:exit"?:
965
- | ((node: ESTree.PrivateIdentifier & NodeParentExtension) => void)
966
- | undefined;
967
- Program?: ((node: ESTree.Program) => void) | undefined;
968
- "Program:exit"?: ((node: ESTree.Program) => void) | undefined;
969
- Property?:
970
- | ((node: ESTree.Property & NodeParentExtension) => void)
971
- | undefined;
972
- "Property:exit"?:
973
- | ((node: ESTree.Property & NodeParentExtension) => void)
974
- | undefined;
975
- PropertyDefinition?:
976
- | ((node: ESTree.PropertyDefinition & NodeParentExtension) => void)
977
- | undefined;
978
- "PropertyDefinition:exit"?:
979
- | ((node: ESTree.PropertyDefinition & NodeParentExtension) => void)
980
- | undefined;
981
- RestElement?:
982
- | ((node: ESTree.RestElement & NodeParentExtension) => void)
983
- | undefined;
984
- "RestElement:exit"?:
985
- | ((node: ESTree.RestElement & NodeParentExtension) => void)
986
- | undefined;
987
- ReturnStatement?:
988
- | ((node: ESTree.ReturnStatement & NodeParentExtension) => void)
989
- | undefined;
990
- "ReturnStatement:exit"?:
991
- | ((node: ESTree.ReturnStatement & NodeParentExtension) => void)
992
- | undefined;
993
- SequenceExpression?:
994
- | ((node: ESTree.SequenceExpression & NodeParentExtension) => void)
995
- | undefined;
996
- "SequenceExpression:exit"?:
997
- | ((node: ESTree.SequenceExpression & NodeParentExtension) => void)
998
- | undefined;
999
- SpreadElement?:
1000
- | ((node: ESTree.SpreadElement & NodeParentExtension) => void)
1001
- | undefined;
1002
- "SpreadElement:exit"?:
1003
- | ((node: ESTree.SpreadElement & NodeParentExtension) => void)
1004
- | undefined;
1005
- StaticBlock?:
1006
- | ((node: ESTree.StaticBlock & NodeParentExtension) => void)
1007
- | undefined;
1008
- "StaticBlock:exit"?:
1009
- | ((node: ESTree.StaticBlock & NodeParentExtension) => void)
1010
- | undefined;
1011
- Super?:
1012
- | ((node: ESTree.Super & NodeParentExtension) => void)
1013
- | undefined;
1014
- "Super:exit"?:
1015
- | ((node: ESTree.Super & NodeParentExtension) => void)
1016
- | undefined;
1017
- SwitchCase?:
1018
- | ((node: ESTree.SwitchCase & NodeParentExtension) => void)
1019
- | undefined;
1020
- "SwitchCase:exit"?:
1021
- | ((node: ESTree.SwitchCase & NodeParentExtension) => void)
1022
- | undefined;
1023
- SwitchStatement?:
1024
- | ((node: ESTree.SwitchStatement & NodeParentExtension) => void)
1025
- | undefined;
1026
- "SwitchStatement:exit"?:
1027
- | ((node: ESTree.SwitchStatement & NodeParentExtension) => void)
1028
- | undefined;
1029
- TaggedTemplateExpression?:
1030
- | ((
1031
- node: ESTree.TaggedTemplateExpression & NodeParentExtension,
1032
- ) => void)
1033
- | undefined;
1034
- "TaggedTemplateExpression:exit"?:
1035
- | ((
1036
- node: ESTree.TaggedTemplateExpression & NodeParentExtension,
1037
- ) => void)
1038
- | undefined;
1039
- TemplateElement?:
1040
- | ((node: ESTree.TemplateElement & NodeParentExtension) => void)
1041
- | undefined;
1042
- "TemplateElement:exit"?:
1043
- | ((node: ESTree.TemplateElement & NodeParentExtension) => void)
1044
- | undefined;
1045
- TemplateLiteral?:
1046
- | ((node: ESTree.TemplateLiteral & NodeParentExtension) => void)
1047
- | undefined;
1048
- "TemplateLiteral:exit"?:
1049
- | ((node: ESTree.TemplateLiteral & NodeParentExtension) => void)
1050
- | undefined;
1051
- ThisExpression?:
1052
- | ((node: ESTree.ThisExpression & NodeParentExtension) => void)
1053
- | undefined;
1054
- "ThisExpression:exit"?:
1055
- | ((node: ESTree.ThisExpression & NodeParentExtension) => void)
1056
- | undefined;
1057
- ThrowStatement?:
1058
- | ((node: ESTree.ThrowStatement & NodeParentExtension) => void)
1059
- | undefined;
1060
- "ThrowStatement:exit"?:
1061
- | ((node: ESTree.ThrowStatement & NodeParentExtension) => void)
1062
- | undefined;
1063
- TryStatement?:
1064
- | ((node: ESTree.TryStatement & NodeParentExtension) => void)
1065
- | undefined;
1066
- "TryStatement:exit"?:
1067
- | ((node: ESTree.TryStatement & NodeParentExtension) => void)
1068
- | undefined;
1069
- UnaryExpression?:
1070
- | ((node: ESTree.UnaryExpression & NodeParentExtension) => void)
1071
- | undefined;
1072
- "UnaryExpression:exit"?:
1073
- | ((node: ESTree.UnaryExpression & NodeParentExtension) => void)
1074
- | undefined;
1075
- UpdateExpression?:
1076
- | ((node: ESTree.UpdateExpression & NodeParentExtension) => void)
1077
- | undefined;
1078
- "UpdateExpression:exit"?:
1079
- | ((node: ESTree.UpdateExpression & NodeParentExtension) => void)
1080
- | undefined;
1081
- VariableDeclaration?:
1082
- | ((node: ESTree.VariableDeclaration & NodeParentExtension) => void)
1083
- | undefined;
1084
- "VariableDeclaration:exit"?:
1085
- | ((node: ESTree.VariableDeclaration & NodeParentExtension) => void)
1086
- | undefined;
1087
- VariableDeclarator?:
1088
- | ((node: ESTree.VariableDeclarator & NodeParentExtension) => void)
1089
- | undefined;
1090
- "VariableDeclarator:exit"?:
1091
- | ((node: ESTree.VariableDeclarator & NodeParentExtension) => void)
1092
- | undefined;
1093
- WhileStatement?:
1094
- | ((node: ESTree.WhileStatement & NodeParentExtension) => void)
1095
- | undefined;
1096
- "WhileStatement:exit"?:
1097
- | ((node: ESTree.WhileStatement & NodeParentExtension) => void)
1098
- | undefined;
1099
- WithStatement?:
1100
- | ((node: ESTree.WithStatement & NodeParentExtension) => void)
1101
- | undefined;
1102
- "WithStatement:exit"?:
1103
- | ((node: ESTree.WithStatement & NodeParentExtension) => void)
1104
- | undefined;
1105
- YieldExpression?:
1106
- | ((node: ESTree.YieldExpression & NodeParentExtension) => void)
1107
- | undefined;
1108
- "YieldExpression:exit"?:
1109
- | ((node: ESTree.YieldExpression & NodeParentExtension) => void)
1110
- | undefined;
1111
- }
691
+
692
+ interface NodeListener
693
+ extends WithExit<
694
+ {
695
+ [Node in Rule.Node as Node["type"]]?:
696
+ | ((node: Node) => void)
697
+ | undefined;
698
+ } & {
699
+ // A `Program` visitor's node type has no `parent` property.
700
+ Program?: ((node: AST.Program) => void) | undefined;
701
+ }
702
+ > {}
1112
703
 
1113
704
  interface NodeParentExtension {
1114
705
  parent: Node;
1115
706
  }
1116
- type Node = ESTree.Node & NodeParentExtension;
707
+
708
+ type Node =
709
+ | (AST.Program & { parent: null })
710
+ | (Exclude<ESTree.Node, ESTree.Program> & NodeParentExtension);
1117
711
 
1118
712
  interface RuleListener extends NodeListener {
1119
713
  onCodePathStart?(codePath: CodePath, node: Node): void;
@@ -1124,6 +718,16 @@ export namespace Rule {
1124
718
 
1125
719
  onCodePathSegmentEnd?(segment: CodePathSegment, node: Node): void;
1126
720
 
721
+ onUnreachableCodePathSegmentStart?(
722
+ segment: CodePathSegment,
723
+ node: Node,
724
+ ): void;
725
+
726
+ onUnreachableCodePathSegmentEnd?(
727
+ segment: CodePathSegment,
728
+ node: Node,
729
+ ): void;
730
+
1127
731
  onCodePathSegmentLoop?(
1128
732
  fromSegment: CodePathSegment,
1129
733
  toSegment: CodePathSegment,
@@ -1178,37 +782,21 @@ export namespace Rule {
1178
782
  MessageIds: string;
1179
783
  }> {}
1180
784
 
1181
- type ReportFixer = (
1182
- fixer: RuleFixer,
1183
- ) => null | Fix | IterableIterator<Fix> | Fix[];
785
+ type ReportFixer = CoreRuleFixer;
1184
786
 
1185
- interface ReportDescriptorOptionsBase {
1186
- data?: { [key: string]: string };
787
+ /** @deprecated Use `ReportDescriptorOptions` instead. */
788
+ type ReportDescriptorOptionsBase = ViolationReportBase;
1187
789
 
1188
- fix?: null | ReportFixer;
1189
- }
790
+ type SuggestionReportOptions = SuggestedEditBase;
791
+ type SuggestionDescriptorMessage = SuggestionMessage;
792
+ type SuggestionReportDescriptor = SuggestedEdit;
1190
793
 
1191
- interface SuggestionReportOptions {
1192
- data?: { [key: string]: string };
794
+ // redundant with ReportDescriptorOptionsBase but kept for clarity
795
+ type ReportDescriptorOptions = ViolationReportBase;
1193
796
 
1194
- fix: ReportFixer;
1195
- }
1196
-
1197
- type SuggestionDescriptorMessage = { desc: string } | { messageId: string };
1198
- type SuggestionReportDescriptor = SuggestionDescriptorMessage &
1199
- SuggestionReportOptions;
1200
-
1201
- interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
1202
- suggest?: SuggestionReportDescriptor[] | null | undefined;
1203
- }
1204
-
1205
- type ReportDescriptor = ReportDescriptorMessage &
1206
- ReportDescriptorLocation &
1207
- ReportDescriptorOptions;
1208
- type ReportDescriptorMessage = { message: string } | { messageId: string };
1209
- type ReportDescriptorLocation =
1210
- | { node: ESTree.Node }
1211
- | { loc: AST.SourceLocation | { line: number; column: number } };
797
+ type ReportDescriptor = ViolationReport<ESTree.Node>;
798
+ type ReportDescriptorMessage = ViolationMessage;
799
+ type ReportDescriptorLocation = ViolationLocation<ESTree.Node>;
1212
800
 
1213
801
  type RuleFixer = RuleTextEditor<ESTree.Node | AST.Token>;
1214
802
  type Fix = RuleTextEdit;
@@ -1222,7 +810,7 @@ export type JSRuleDefinition<
1222
810
  {
1223
811
  LangOptions: Linter.LanguageOptions;
1224
812
  Code: SourceCode;
1225
- Visitor: Rule.NodeListener;
813
+ Visitor: Rule.RuleListener;
1226
814
  Node: JSSyntaxElement;
1227
815
  },
1228
816
  Options
@@ -1318,9 +906,7 @@ export namespace Linter {
1318
906
  *
1319
907
  * @see [Rules](https://eslint.org/docs/latest/use/configure/rules)
1320
908
  */
1321
- type RuleEntry<Options extends any[] = any[]> =
1322
- | RuleSeverity
1323
- | RuleSeverityAndOptions<Options>;
909
+ type RuleEntry<Options extends any[] = any[]> = RuleConfig<Options>;
1324
910
 
1325
911
  /**
1326
912
  * The rules config object is a key/value map of rule names and their severity and options.
@@ -1330,9 +916,8 @@ export namespace Linter {
1330
916
  /**
1331
917
  * A configuration object that may have a `rules` block.
1332
918
  */
1333
- interface HasRules<Rules extends RulesConfig = RulesConfig> {
1334
- rules?: Partial<Rules> | undefined;
1335
- }
919
+ type HasRules<Rules extends RulesConfig = RulesConfig> =
920
+ CoreHasRules<Rules>;
1336
921
 
1337
922
  /**
1338
923
  * The ECMAScript version of the code being linted.
@@ -1342,99 +927,17 @@ export namespace Linter {
1342
927
  /**
1343
928
  * The type of JavaScript source code.
1344
929
  */
1345
- // TODO: Refactor to JavaScriptSourceType when exported from @eslint/core.
1346
- type SourceType = "script" | "module" | "commonjs";
930
+ type SourceType = JavaScriptSourceType;
1347
931
 
1348
932
  /**
1349
933
  * ESLint legacy configuration.
1350
934
  *
1351
935
  * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/)
1352
936
  */
1353
- interface BaseConfig<
937
+ type BaseConfig<
1354
938
  Rules extends RulesConfig = RulesConfig,
1355
939
  OverrideRules extends RulesConfig = Rules,
1356
- > extends HasRules<Rules> {
1357
- $schema?: string | undefined;
1358
-
1359
- /**
1360
- * An environment provides predefined global variables.
1361
- *
1362
- * @see [Environments](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-environments)
1363
- */
1364
- env?: { [name: string]: boolean } | undefined;
1365
-
1366
- /**
1367
- * Extending configuration files.
1368
- *
1369
- * @see [Extends](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#extending-configuration-files)
1370
- */
1371
- extends?: string | string[] | undefined;
1372
-
1373
- /**
1374
- * Specifying globals.
1375
- *
1376
- * @see [Globals](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-globals)
1377
- */
1378
- globals?: Linter.Globals | undefined;
1379
-
1380
- /**
1381
- * Disable processing of inline comments.
1382
- *
1383
- * @see [Disabling Inline Comments](https://eslint.org/docs/latest/use/configure/rules-deprecated#disabling-inline-comments)
1384
- */
1385
- noInlineConfig?: boolean | undefined;
1386
-
1387
- /**
1388
- * Overrides can be used to use a differing configuration for matching sub-directories and files.
1389
- *
1390
- * @see [How do overrides work](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#how-do-overrides-work)
1391
- */
1392
- overrides?: Array<ConfigOverride<OverrideRules>> | undefined;
1393
-
1394
- /**
1395
- * Parser.
1396
- *
1397
- * @see [Working with Custom Parsers](https://eslint.org/docs/latest/extend/custom-parsers)
1398
- * @see [Specifying Parser](https://eslint.org/docs/latest/use/configure/parser-deprecated)
1399
- */
1400
- parser?: string | undefined;
1401
-
1402
- /**
1403
- * Parser options.
1404
- *
1405
- * @see [Working with Custom Parsers](https://eslint.org/docs/latest/extend/custom-parsers)
1406
- * @see [Specifying Parser Options](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options)
1407
- */
1408
- parserOptions?: JavaScriptParserOptionsConfig | undefined;
1409
-
1410
- /**
1411
- * Which third-party plugins define additional rules, environments, configs, etc. for ESLint to use.
1412
- *
1413
- * @see [Configuring Plugins](https://eslint.org/docs/latest/use/configure/plugins-deprecated#configure-plugins)
1414
- */
1415
- plugins?: string[] | undefined;
1416
-
1417
- /**
1418
- * Specifying processor.
1419
- *
1420
- * @see [processor](https://eslint.org/docs/latest/use/configure/plugins-deprecated#specify-a-processor)
1421
- */
1422
- processor?: string | undefined;
1423
-
1424
- /**
1425
- * Report unused eslint-disable comments as warning.
1426
- *
1427
- * @see [Report unused eslint-disable comments](https://eslint.org/docs/latest/use/configure/rules-deprecated#report-unused-eslint-disable-comments)
1428
- */
1429
- reportUnusedDisableDirectives?: boolean | undefined;
1430
-
1431
- /**
1432
- * Settings.
1433
- *
1434
- * @see [Settings](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#adding-shared-settings)
1435
- */
1436
- settings?: { [name: string]: any } | undefined;
1437
- }
940
+ > = CoreBaseConfig<Rules, OverrideRules>;
1438
941
 
1439
942
  /**
1440
943
  * The overwrites that apply more differing configuration to specific files or directories.
@@ -1477,18 +980,7 @@ export namespace Linter {
1477
980
  reportUnusedDisableDirectives?: boolean | undefined;
1478
981
  }
1479
982
 
1480
- // TODO: Once exported from @eslint/core, remove this and use that instead
1481
- interface LintSuggestion {
1482
- /** A short description. */
1483
- desc: string;
1484
-
1485
- /** Fix result info. */
1486
- fix: Rule.Fix;
1487
-
1488
- /** Id referencing a message for the description. */
1489
- messageId?: string | undefined;
1490
- }
1491
-
983
+ type LintSuggestion = CoreLintSuggestion;
1492
984
  type LintMessage = CoreLintMessage;
1493
985
 
1494
986
  interface LintSuppression {