UNPKG

737 BJavaScriptView Raw
1const {docsUrl} = require('../utilities');
2
3module.exports = {
4 meta: {
5 docs: {
6 description: 'Prevent the usage of unnecessary computed properties.',
7 category: 'Best Practices',
8 recommended: false,
9 uri: docsUrl('no-useless-computed-properties'),
10 },
11 },
12
13 create(context) {
14 function hasLiteralComputedKey(prop) {
15 return prop.computed && prop.key.type === 'Literal';
16 }
17
18 function checkProperty(node) {
19 if (hasLiteralComputedKey(node)) {
20 context.report({
21 node,
22 message: 'Computed property is using a literal key unnecessarily.',
23 });
24 }
25 }
26
27 return {
28 MethodDefinition: checkProperty,
29 Property: checkProperty,
30 };
31 },
32};