forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno-empty-attrs.js
More file actions
53 lines (44 loc) · 1.47 KB
/
no-empty-attrs.js
File metadata and controls
53 lines (44 loc) · 1.47 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
'use strict';
const ember = require('../utils/ember');
//------------------------------------------------------------------------------
// Ember Data - Be explicit with Ember data attribute types
//------------------------------------------------------------------------------
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow usage of empty attributes in Ember Data models',
category: 'Ember Data',
recommended: false,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/no-empty-attrs.md',
},
fixable: null,
schema: [],
},
create(context) {
const message = 'Supply proper attribute type';
const filePath = context.filename ?? context.getFilename();
const report = function (node) {
context.report({ node, message });
};
const sourceCode = context.sourceCode ?? context.getSourceCode();
const { scopeManager } = sourceCode;
return {
CallExpression(node) {
if (!ember.isDSModel(node, filePath)) {
return;
}
const allProperties = ember.getModuleProperties(node, scopeManager);
const isDSAttr = allProperties.filter((property) =>
ember.isModule(property.value, 'attr', 'DS')
);
for (const attr of isDSAttr) {
if (attr.value.arguments.length === 0) {
report(attr.value);
}
}
},
};
},
};