-
-
Notifications
You must be signed in to change notification settings - Fork 211
Extract rule: template-deprecated-render-helper #2451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NullVoxPopuli
merged 2 commits into
ember-cli:master
from
NullVoxPopuli:nvp/template-lint-extract-rule-template-deprecated-render-helper
Mar 13, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # ember/template-deprecated-render-helper | ||
|
|
||
| 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
|
||
| > **HBS Only**: This rule applies to classic `.hbs` template files only (loose mode). It is not relevant for `gjs`/`gts` files (strict mode), where these patterns cannot occur. | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| Disallows the {{render}} helper which is deprecated. | ||
|
|
||
| ## Examples | ||
|
|
||
| Incorrect: | ||
|
|
||
| ```hbs | ||
| {{render 'user'}} | ||
| ``` | ||
|
|
||
| Correct: | ||
|
|
||
| ```hbs | ||
| <User /> | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [eslint-plugin-ember template-deprecated-render-helper](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/template-deprecated-render-helper.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** @type {import('eslint').Rule.RuleModule} */ | ||
| module.exports = { | ||
| meta: { | ||
| type: 'suggestion', | ||
| docs: { | ||
| description: 'disallow {{render}} helper', | ||
| category: 'Deprecations', | ||
| url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-deprecated-render-helper.md', | ||
| templateMode: 'loose', | ||
| }, | ||
| fixable: 'code', | ||
| schema: [], | ||
| messages: { | ||
| deprecated: | ||
| 'The render helper is deprecated in favor of using components. See https://emberjs.com/deprecations/v2.x/#toc_code-render-code-helper', | ||
| }, | ||
| originallyFrom: { | ||
| name: 'ember-template-lint', | ||
| rule: 'lib/rules/deprecated-render-helper.js', | ||
| docs: 'docs/rule/deprecated-render-helper.md', | ||
| tests: 'test/unit/rules/deprecated-render-helper-test.js', | ||
| }, | ||
| }, | ||
|
|
||
| create(context) { | ||
| const sourceCode = context.sourceCode; | ||
|
|
||
| function buildFix(node) { | ||
| const first = node.params[0]; | ||
| if (!first || first.type !== 'GlimmerStringLiteral') { | ||
| return null; | ||
| } | ||
| const templateName = first.value; | ||
|
|
||
| if (node.params.length === 1) { | ||
| // {{render 'name'}} → {{name}} | ||
| return (fixer) => fixer.replaceText(node, `{{${templateName}}}`); | ||
| } | ||
|
|
||
| if (node.params.length === 2) { | ||
| // {{render 'name' model}} → {{name model=model}} | ||
| const model = sourceCode.getText(node.params[1]); | ||
| return (fixer) => fixer.replaceText(node, `{{${templateName} model=${model}}}`); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| function checkForRender(node) { | ||
| if ( | ||
| node.path && | ||
| node.path.type === 'GlimmerPathExpression' && | ||
| node.path.original === 'render' | ||
| ) { | ||
| context.report({ | ||
| node, | ||
| messageId: 'deprecated', | ||
| fix: buildFix(node), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| GlimmerMustacheStatement(node) { | ||
| checkForRender(node); | ||
| }, | ||
|
|
||
| GlimmerBlockStatement(node) { | ||
| checkForRender(node); | ||
| }, | ||
| }; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| const rule = require('../../../lib/rules/template-deprecated-render-helper'); | ||
| const RuleTester = require('eslint').RuleTester; | ||
|
|
||
| const ruleTester = new RuleTester({ | ||
| parser: require.resolve('ember-eslint-parser'), | ||
| parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, | ||
| }); | ||
|
|
||
| ruleTester.run('template-deprecated-render-helper', rule, { | ||
| valid: [ | ||
| '<template><MyComponent /></template>', | ||
| '<template>{{this.render}}</template>', | ||
| '<template>{{valid-compoennt}}</template>', | ||
| '<template>{{input placeholder=(t "email") value=email}}</template>', | ||
| '<template>{{title "CrossCheck Web" prepent=true separator=" | "}}</template>', | ||
| '<template>{{hockey-player teamName="Boston Bruins"}}</template>', | ||
| '<template>{{false}}</template>', | ||
| '<template>{{"foo"}}</template>', | ||
| '<template>{{42}}</template>', | ||
| '<template>{{null}}</template>', | ||
| '<template>{{undefined}}</template>', | ||
| ], | ||
| invalid: [ | ||
| { | ||
| code: '<template>{{render "user"}}</template>', | ||
| output: '<template>{{user}}</template>', | ||
| errors: [{ messageId: 'deprecated' }], | ||
| }, | ||
| { | ||
| code: "<template>{{render 'ken-griffey'}}</template>", | ||
| output: '<template>{{ken-griffey}}</template>', | ||
| errors: [{ messageId: 'deprecated' }], | ||
| }, | ||
| { | ||
| code: "<template>{{render 'baseball-player' pitcher}}</template>", | ||
| output: '<template>{{baseball-player model=pitcher}}</template>', | ||
| errors: [{ messageId: 'deprecated' }], | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| const hbsRuleTester = new RuleTester({ | ||
| parser: require.resolve('ember-eslint-parser/hbs'), | ||
| parserOptions: { | ||
| ecmaVersion: 2022, | ||
| sourceType: 'module', | ||
| }, | ||
| }); | ||
|
|
||
| hbsRuleTester.run('template-deprecated-render-helper', rule, { | ||
| valid: [ | ||
| '{{valid-compoennt}}', | ||
| '{{input placeholder=(t "email") value=email}}', | ||
| '{{title "CrossCheck Web" prepent=true separator=" | "}}', | ||
| '{{hockey-player teamName="Boston Bruins"}}', | ||
| '{{false}}', | ||
| '{{"foo"}}', | ||
| '{{42}}', | ||
| '{{null}}', | ||
| '{{undefined}}', | ||
| ], | ||
| invalid: [ | ||
| { | ||
| code: "{{render 'ken-griffey'}}", | ||
| output: '{{ken-griffey}}', | ||
| errors: [{ messageId: 'deprecated' }], | ||
| }, | ||
| { | ||
| code: "{{render 'baseball-player' pitcher}}", | ||
| output: '{{baseball-player model=pitcher}}', | ||
| errors: [{ messageId: 'deprecated' }], | ||
| }, | ||
| ], | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this worth having? This was deprecated 2.x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to put mental energy into anything other than porting over template-lint rules rn.
We have to do a major soon of eslint-plugin-ember anyway, and that is a great time to delete stuff
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
•
templateMode: 'loose'—{{render}}can't exist in strict mode (gjs/gts), or?• missing autofix.