forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-no-inline-styles.js
More file actions
47 lines (44 loc) · 1.38 KB
/
template-no-inline-styles.js
File metadata and controls
47 lines (44 loc) · 1.38 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
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow inline styles',
category: 'Best Practices',
recommendedGjs: false,
recommendedGts: false,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-inline-styles.md',
},
schema: [
{
type: 'object',
properties: {
allowDynamicStyles: { type: 'boolean' },
},
additionalProperties: false,
},
],
messages: { noInlineStyles: 'Inline styles are not allowed' },
},
create(context) {
const options = context.options[0] || {};
const allowDynamicStyles =
options.allowDynamicStyles === undefined ? true : options.allowDynamicStyles;
return {
GlimmerElementNode(node) {
const styleAttr = node.attributes?.find((a) => a.name === 'style');
if (!styleAttr) {
return;
}
// If allowDynamicStyles is true, skip dynamic style values (MustacheStatement/ConcatStatement)
if (allowDynamicStyles) {
const valType = styleAttr.value?.type;
if (valType === 'GlimmerMustacheStatement' || valType === 'GlimmerConcatStatement') {
return;
}
}
context.report({ node: styleAttr, messageId: 'noInlineStyles' });
},
};
},
};