Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/rules/template-no-class-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

馃捈 This rule is enabled in the 馃搵 `template-lint-migration` [config](https://github.com/ember-cli/eslint-plugin-ember#-configurations).

> **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 -->

Disallow passing `classBinding` or `classNameBindings` as arguments within templates. These are legacy Ember Classic patterns that should be replaced with modern approaches.
Expand Down
7 changes: 1 addition & 6 deletions lib/rules/template-no-class-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
description: 'disallow passing classBinding or classNameBindings as arguments in templates',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-class-bindings.md',
templateMode: 'loose',
templateMode: 'both',
},
fixable: null,
schema: [],
Expand All @@ -23,11 +23,6 @@ module.exports = {
},

create(context) {
const isStrictMode = context.filename.endsWith('.gjs') || context.filename.endsWith('.gts');
if (isStrictMode) {
return {};
}

const FORBIDDEN_ATTR_NAMES = new Set([
'classBinding',
'@classBinding',
Expand Down
33 changes: 24 additions & 9 deletions tests/lib/rules/template-no-class-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ ruleTester.run('template-no-class-bindings', rule, {
'<template>{{true}}</template>',
'<template>{{"hehe"}}</template>',
'<template><div class="foo"></div></template>',
// Rule is HBS-only: @classBinding in GJS/GTS may be a legitimate component argument
{
filename: 'test.gjs',
code: '<template><SomeThing @classBinding="lol:wat" /></template>',
},
{
filename: 'test.gts',
code: '<template>{{some-thing classNameBindings="lol:foo:bar"}}</template>',
},
],
invalid: [
{
Expand Down Expand Up @@ -64,6 +55,30 @@ ruleTester.run('template-no-class-bindings', rule, {
},
],
},
// `@ember/component` is still supported, so a classic component invoked from
// a strict-mode template still acts on these arguments.
{
filename: 'test.gjs',
code: '<template><SomeThing @classBinding="lol:wat" /></template>',
output: null,
errors: [
{
messageId: 'noClassBindings',
data: { name: '@classBinding' },
},
],
},
{
filename: 'test.gts',
code: '<template><SomeThing @classNameBindings="lol:foo:bar" /></template>',
output: null,
errors: [
{
messageId: 'noClassBindings',
data: { name: '@classNameBindings' },
},
],
},
],
});

Expand Down
Loading