File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -185,6 +185,7 @@ rules in templates can be disabled with eslint directives with mustache or html
185185| Name | Description | 💼 | 🔧 | 💡 |
186186| :----------------------------------------------------------------------------------------- | :-------------------------------------------------------- | :- | :- | :- |
187187| [ template-builtin-component-arguments] ( docs/rules/template-builtin-component-arguments.md ) | disallow setting certain attributes on builtin components | | | |
188+ | [ template-no-builtin-form-components] ( docs/rules/template-no-builtin-form-components.md ) | disallow usage of built-in form components | | | |
188189| [ template-no-debugger] ( docs/rules/template-no-debugger.md ) | disallow {{debugger}} in templates | | | |
189190| [ template-no-log] ( docs/rules/template-no-log.md ) | disallow {{log}} in templates | | | |
190191
Original file line number Diff line number Diff line change 1+ # ember/template-no-builtin-form-components
2+
3+ <!-- end auto-generated rule header -->
4+
5+ Disallows usage of built-in form components.
6+
7+ ## Rule Details
8+
9+ Built-in Ember components like ` <Input> ` and ` <Textarea> ` should be replaced with native HTML elements for better performance and simpler code.
10+
11+ ## Examples
12+
13+ Examples of ** incorrect** code for this rule:
14+
15+ ``` gjs
16+ <template>
17+ <Input @type="text" />
18+ </template>
19+ ```
20+
21+ ``` gjs
22+ <template>
23+ <Textarea @value={{this.text}} />
24+ </template>
25+ ```
26+
27+ Examples of ** correct** code for this rule:
28+
29+ ``` gjs
30+ <template>
31+ <input type="text" />
32+ </template>
33+ ```
34+
35+ ``` gjs
36+ <template>
37+ <textarea></textarea>
38+ </template>
39+ ```
40+
41+ ## References
42+
43+ - [ eslint-plugin-ember no-builtin-form-components] ( https://github.com/eslint-plugin-ember/eslint-plugin-ember/blob/master/docs/rule/no-builtin-form-components.md )
Original file line number Diff line number Diff line change 1+ /** @type {import('eslint').Rule.RuleModule } */
2+ module . exports = {
3+ meta : {
4+ type : 'suggestion' ,
5+ docs : {
6+ description : 'disallow usage of built-in form components' ,
7+ category : 'Best Practices' ,
8+ strictGjs : true ,
9+ strictGts : true ,
10+ url : 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-builtin-form-components.md' ,
11+ } ,
12+ fixable : null ,
13+ schema : [ ] ,
14+ messages : {
15+ noBuiltinFormComponent :
16+ 'Do not use built-in form components. Use native HTML elements instead.' ,
17+ } ,
18+ } ,
19+
20+ create ( context ) {
21+ const BUILTIN_FORM_COMPONENTS = new Set ( [ 'Input' , 'Textarea' ] ) ;
22+
23+ return {
24+ GlimmerElementNode ( node ) {
25+ if ( BUILTIN_FORM_COMPONENTS . has ( node . tag ) ) {
26+ context . report ( {
27+ node,
28+ messageId : 'noBuiltinFormComponent' ,
29+ } ) ;
30+ }
31+ } ,
32+ } ;
33+ } ,
34+ } ;
Original file line number Diff line number Diff line change 1+ //------------------------------------------------------------------------------
2+ // Requirements
3+ //------------------------------------------------------------------------------
4+
5+ const rule = require ( '../../../lib/rules/template-no-builtin-form-components' ) ;
6+ const RuleTester = require ( 'eslint' ) . RuleTester ;
7+
8+ //------------------------------------------------------------------------------
9+ // Tests
10+ //------------------------------------------------------------------------------
11+
12+ const ruleTester = new RuleTester ( {
13+ parser : require . resolve ( 'ember-eslint-parser' ) ,
14+ parserOptions : { ecmaVersion : 2022 , sourceType : 'module' } ,
15+ } ) ;
16+
17+ ruleTester . run ( 'template-no-builtin-form-components' , rule , {
18+ valid : [
19+ `<template>
20+ <input type="text" />
21+ </template>` ,
22+ `<template>
23+ <textarea></textarea>
24+ </template>` ,
25+ `<template>
26+ <a href="/home">Home</a>
27+ </template>` ,
28+ ] ,
29+
30+ invalid : [
31+ {
32+ code : `<template>
33+ <Input @type="text" />
34+ </template>` ,
35+ output : null ,
36+ errors : [
37+ {
38+ message : 'Do not use built-in form components. Use native HTML elements instead.' ,
39+ type : 'GlimmerElementNode' ,
40+ } ,
41+ ] ,
42+ } ,
43+ {
44+ code : `<template>
45+ <Textarea @value={{this.text}} />
46+ </template>` ,
47+ output : null ,
48+ errors : [
49+ {
50+ message : 'Do not use built-in form components. Use native HTML elements instead.' ,
51+ type : 'GlimmerElementNode' ,
52+ } ,
53+ ] ,
54+ } ,
55+ ] ,
56+ } ) ;
You can’t perform that action at this time.
0 commit comments