forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavoid-using-needs-in-controllers.js
More file actions
55 lines (46 loc) · 1.57 KB
/
avoid-using-needs-in-controllers.js
File metadata and controls
55 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const ember = require('../utils/ember');
//------------------------------------------------------------------------------
// Ember object rule - Avoid using needs in controllers
//------------------------------------------------------------------------------
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow using `needs` in controllers',
category: 'Controllers',
recommended: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/avoid-using-needs-in-controllers.md',
},
fixable: null,
schema: [],
},
create(context) {
const report = function (node) {
const message =
'`needs` API has been deprecated, `Ember.inject.controller` should be used instead';
context.report({ node, message });
};
const sourceCode = context.sourceCode ?? context.getSourceCode();
const { scopeManager } = sourceCode;
return {
CallExpression(node) {
const isReopenNode = ember.isReopenObject(node) || ember.isReopenClassObject(node);
if (!ember.isEmberController(context, node) && !isReopenNode) {
return;
}
const properties = ember.getModuleProperties(node, scopeManager);
for (const property of properties) {
if (
property.type === 'Property' &&
property.key.type === 'Identifier' &&
property.key.name === 'needs'
) {
report(property);
}
}
},
};
},
};