Skip to content

Commit b317310

Browse files
committed
Extract rule: template-deprecated-inline-view-helper
1 parent 5d2ad94 commit b317310

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ rules in templates can be disabled with eslint directives with mustache or html
236236
| [no-observers](docs/rules/no-observers.md) | disallow usage of observers || | |
237237
| [no-old-shims](docs/rules/no-old-shims.md) | disallow usage of old shims for modules || 🔧 | |
238238
| [no-string-prototype-extensions](docs/rules/no-string-prototype-extensions.md) | disallow usage of `String` prototype extensions || | |
239+
| [template-deprecated-inline-view-helper](docs/rules/template-deprecated-inline-view-helper.md) | disallow inline {{view}} helper | | | |
239240

240241
### Ember Data
241242

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ember/template-deprecated-inline-view-helper
2+
3+
<!-- end auto-generated rule header -->
4+
5+
## Examples
6+
7+
See ember-template-lint documentation.
8+
9+
## References
10+
11+
- [ember-template-lint](https://github.com/ember-template-lint/ember-template-lint)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/** @type {import('eslint').Rule.RuleModule} */
2+
module.exports = {
3+
meta: {
4+
type: 'suggestion',
5+
docs: {
6+
description: 'disallow inline {{view}} helper',
7+
category: 'Deprecations',
8+
strictGjs: true,
9+
strictGts: true,
10+
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-deprecated-inline-view-helper.md',
11+
},
12+
fixable: null,
13+
schema: [],
14+
messages: {
15+
deprecated:
16+
'The inline form of `view` is deprecated. Please use `Ember.Component` instead. See http://emberjs.com/deprecations/v1.x/#toc_ember-view',
17+
},
18+
},
19+
20+
create(context) {
21+
function checkForView(node) {
22+
if (
23+
node.path &&
24+
node.path.type === 'GlimmerPathExpression' &&
25+
node.path.original === 'view'
26+
) {
27+
// Check if it has hash pairs (attributes), which indicates inline usage
28+
if (node.hash && node.hash.pairs && node.hash.pairs.length > 0) {
29+
context.report({
30+
node,
31+
messageId: 'deprecated',
32+
});
33+
}
34+
}
35+
}
36+
37+
return {
38+
GlimmerMustacheStatement(node) {
39+
checkForView(node);
40+
},
41+
42+
GlimmerBlockStatement(node) {
43+
checkForView(node);
44+
},
45+
};
46+
},
47+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const rule = require('../../../lib/rules/template-deprecated-inline-view-helper');
2+
const RuleTester = require('eslint').RuleTester;
3+
4+
const ruleTester = new RuleTester({
5+
parser: require.resolve('ember-eslint-parser'),
6+
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
7+
});
8+
9+
ruleTester.run('template-deprecated-inline-view-helper', rule, {
10+
valid: ['<template><MyComponent /></template>', '<template>{{view}}</template>'],
11+
invalid: [
12+
{
13+
code: '<template>{{view class="foo"}}</template>',
14+
output: null,
15+
errors: [{ messageId: 'deprecated' }],
16+
},
17+
],
18+
});

0 commit comments

Comments
 (0)