-
-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathno-async-actions.js
More file actions
60 lines (52 loc) · 1.59 KB
/
no-async-actions.js
File metadata and controls
60 lines (52 loc) · 1.59 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
56
57
58
59
60
'use strict';
const utils = require('../utils/utils');
//------------------------------------------------------------------------------
// General rule - Don't use async actions
//------------------------------------------------------------------------------
const message = 'Do not use async actions';
module.exports = {
meta: {
docs: {
description: 'Disallow usage of async actions in components',
category: 'Possible Errors',
url: 'http://ember-concurrency.com/docs/tutorial'
},
fixable: null,
},
create(context) {
return {
Property(node) {
if (node.key.name === 'actions') {
const props = node.value.properties;
props.forEach((p) => {
const body = p.value.body.body;
if (p.value.async) {
context.report({
node: p,
message,
});
} else if (body.length === 1 && utils.isReturnStatement(body[0])) {
const retSt = body[0];
if (retSt.argument.type === 'CallExpression' &&
retSt.argument.callee.property.name === 'then') {
context.report({
node: retSt,
message,
});
}
}
});
} else if (node.decorators) {
if (node.decorators.find(d => d.expression.name === 'action')) {
if (node.value.async) {
context.report({
node,
message: 'Do not use async actions'
});
}
}
}
}
};
}
};