@@ -31,6 +31,7 @@ import {
31
31
Linter ,
32
32
loadESLint ,
33
33
Rule ,
34
+ JSRuleDefinition ,
34
35
RuleTester ,
35
36
Scope ,
36
37
SourceCode ,
@@ -52,7 +53,7 @@ import {
52
53
StaticBlock ,
53
54
WhileStatement ,
54
55
} from "estree" ;
55
- import { Language , RuleDefinition } from "@eslint/core" ;
56
+ import { Language , RuleDefinition , SettingsConfig } from "@eslint/core" ;
56
57
57
58
const SOURCE = `var foo = bar;` ;
58
59
@@ -809,6 +810,93 @@ type DeprecatedRuleContextKeys =
809
810
} ,
810
811
} ) ;
811
812
813
+ // All options optional - JSRuleDefinition and JSRuleDefinition<{}>
814
+ // should be the same type.
815
+ ( rule1 : JSRuleDefinition , rule2 : JSRuleDefinition < { } > ) => {
816
+ rule1 satisfies typeof rule2 ;
817
+ rule2 satisfies typeof rule1 ;
818
+ } ;
819
+
820
+ // Type restrictions should be enforced
821
+ ( ) : JSRuleDefinition < {
822
+ RuleOptions : [ string , number ] ;
823
+ MessageIds : "foo" | "bar" ;
824
+ ExtRuleDocs : { foo : string ; bar : number } ;
825
+ } > => ( {
826
+ meta : {
827
+ messages : {
828
+ foo : "FOO" ,
829
+
830
+ // @ts -expect-error Wrong type for message ID
831
+ bar : 42 ,
832
+ } ,
833
+ docs : {
834
+ foo : "FOO" ,
835
+
836
+ // @ts -expect-error Wrong type for declared property
837
+ bar : "BAR" ,
838
+
839
+ // @ts -expect-error Wrong type for predefined property
840
+ description : 42 ,
841
+ } ,
842
+ } ,
843
+ create ( { options } ) {
844
+ // Types for rule options
845
+ options [ 0 ] satisfies string ;
846
+ options [ 1 ] satisfies number ;
847
+
848
+ return { } ;
849
+ } ,
850
+ } ) ;
851
+
852
+ // Undeclared properties should produce an error
853
+ ( ) : JSRuleDefinition < {
854
+ MessageIds : "foo" | "bar" ;
855
+ ExtRuleDocs : { foo : number ; bar : string } ;
856
+ } > => ( {
857
+ meta : {
858
+ messages : {
859
+ foo : "FOO" ,
860
+
861
+ // Declared message ID is not required
862
+ // bar: "BAR",
863
+
864
+ // @ts -expect-error Undeclared message ID is not allowed
865
+ baz : "BAZ" ,
866
+ } ,
867
+ docs : {
868
+ foo : 42 ,
869
+
870
+ // Declared property is not required
871
+ // bar: "BAR",
872
+
873
+ // @ts -expect-error Undeclared property key is not allowed
874
+ baz : "BAZ" ,
875
+
876
+ // Predefined property is allowed
877
+ description : "Lorem ipsum" ,
878
+ } ,
879
+ } ,
880
+ create ( ) {
881
+ return { } ;
882
+ } ,
883
+ } ) ;
884
+
885
+ ( ) : JSRuleDefinition => ( {
886
+ create ( context ) {
887
+ context . cwd satisfies string ; // $ExpectType string
888
+ context . filename satisfies string ; // $ExpectType string
889
+ context . id satisfies string ; // $ExpectType string
890
+ context . languageOptions satisfies Linter . LanguageOptions ; // $ExpectType LanguageOptions
891
+ context . options satisfies unknown [ ] ; // $ExpectType unknown[]
892
+ context . physicalFilename satisfies string ; // $ExpectType string
893
+ context . settings satisfies SettingsConfig ; // $ExpectType SettingsConfig
894
+ context . sourceCode satisfies SourceCode ; // $ExpectType SourceCode
895
+
896
+ return { } ;
897
+ } ,
898
+ } ) ;
899
+
812
900
// #endregion
813
901
814
902
// #region Linter
0 commit comments