@@ -9,6 +9,7 @@ const validHbs = [
99 options : [ { allowedMethods : [ 'get' ] } ] ,
1010 code : '<form method="GET"></form>' ,
1111 } ,
12+ // No options → default-enabled with POST,GET,DIALOG.
1213 '<form method="POST"></form>' ,
1314 '<form method="post"></form>' ,
1415 '<form method="GET"></form>' ,
@@ -20,9 +21,24 @@ const validHbs = [
2021 '<div/>' ,
2122 '<div></div>' ,
2223 '<div method="randomType"></div>' ,
24+ // Explicit `true` behaves identically to no options.
25+ { options : [ true ] , code : '<form method="POST"></form>' } ,
26+ // Explicit `false` disables the rule.
27+ { options : [ false ] , code : '<form></form>' } ,
2328] ;
2429
2530const invalidHbs = [
31+ // Default-enabled: no options → rule active with POST,GET,DIALOG.
32+ {
33+ code : '<form></form>' ,
34+ output : '<form method="POST"></form>' ,
35+ errors : [ { message : DEFAULT_ERROR } ] ,
36+ } ,
37+ {
38+ code : '<form method="NOT_A_VALID_METHOD"></form>' ,
39+ output : '<form method="POST"></form>' ,
40+ errors : [ { message : DEFAULT_ERROR } ] ,
41+ } ,
2642 {
2743 options : [ { allowedMethods : [ 'get' ] } ] ,
2844 code : '<form method="POST"></form>' ,
@@ -40,26 +56,31 @@ const invalidHbs = [
4056 ] ,
4157 } ,
4258 {
59+ options : [ true ] ,
4360 code : '<form></form>' ,
4461 output : '<form method="POST"></form>' ,
4562 errors : [ { message : DEFAULT_ERROR } ] ,
4663 } ,
4764 {
65+ options : [ true ] ,
4866 code : '<form method=""></form>' ,
4967 output : '<form method="POST"></form>' ,
5068 errors : [ { message : DEFAULT_ERROR } ] ,
5169 } ,
5270 {
71+ options : [ true ] ,
5372 code : '<form method=42></form>' ,
5473 output : '<form method="POST"></form>' ,
5574 errors : [ { message : DEFAULT_ERROR } ] ,
5675 } ,
5776 {
77+ options : [ true ] ,
5878 code : '<form method=" ge t "></form>' ,
5979 output : '<form method="POST"></form>' ,
6080 errors : [ { message : DEFAULT_ERROR } ] ,
6181 } ,
6282 {
83+ options : [ true ] ,
6384 code : '<form method=" pos t "></form>' ,
6485 output : '<form method="POST"></form>' ,
6586 errors : [ { message : DEFAULT_ERROR } ] ,
@@ -100,3 +121,28 @@ hbsRuleTester.run('template-require-form-method', rule, {
100121 valid : validHbs ,
101122 invalid : invalidHbs ,
102123} ) ;
124+
125+ // parseConfig should throw on an invalid `allowedMethods` entry so that
126+ // misconfiguration is surfaced immediately rather than silently ignored.
127+ describe ( 'template-require-form-method invalid configuration' , ( ) => {
128+ const { Linter } = require ( 'eslint' ) ;
129+
130+ function lintWith ( options ) {
131+ const linter = new Linter ( ) ;
132+ linter . defineParser ( 'ember-eslint-parser/hbs' , require ( 'ember-eslint-parser/hbs' ) ) ;
133+ linter . defineRule ( 'template-require-form-method' , rule ) ;
134+ return linter . verify ( '<form method="POST"></form>' , {
135+ parser : 'ember-eslint-parser/hbs' ,
136+ parserOptions : { ecmaVersion : 2022 , sourceType : 'module' } ,
137+ rules : { 'template-require-form-method' : [ 'error' , options ] } ,
138+ } ) ;
139+ }
140+
141+ test ( 'throws on unknown method in allowedMethods' , ( ) => {
142+ expect ( ( ) => lintWith ( { allowedMethods : [ 'PATCH' ] } ) ) . toThrow ( / i n v a l i d c o n f i g u r a t i o n / ) ;
143+ } ) ;
144+
145+ test ( 'throws on mixed valid/invalid method list' , ( ) => {
146+ expect ( ( ) => lintWith ( { allowedMethods : [ 'GET' , 'BOGUS' ] } ) ) . toThrow ( / i n v a l i d c o n f i g u r a t i o n / ) ;
147+ } ) ;
148+ } ) ;
0 commit comments