1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | const Components = require('../util/Components');
|
9 | const docsUrl = require('../util/docsUrl');
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | module.exports = {
|
16 | meta: {
|
17 | docs: {
|
18 | description: 'Enforce ES5 or ES6 class for React Components',
|
19 | category: 'Stylistic Issues',
|
20 | recommended: false,
|
21 | url: docsUrl('prefer-es6-class')
|
22 | },
|
23 |
|
24 | schema: [{
|
25 | enum: ['always', 'never']
|
26 | }]
|
27 | },
|
28 |
|
29 | create: Components.detect((context, components, utils) => {
|
30 | const configuration = context.options[0] || 'always';
|
31 |
|
32 | return {
|
33 | ObjectExpression(node) {
|
34 | if (utils.isES5Component(node) && configuration === 'always') {
|
35 | context.report({
|
36 | node,
|
37 | message: 'Component should use es6 class instead of createClass'
|
38 | });
|
39 | }
|
40 | },
|
41 | ClassDeclaration(node) {
|
42 | if (utils.isES6Component(node) && configuration === 'never') {
|
43 | context.report({
|
44 | node,
|
45 | message: 'Component should use createClass instead of es6 class'
|
46 | });
|
47 | }
|
48 | }
|
49 | };
|
50 | })
|
51 | };
|