source: imaps-frontend/node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 * @fileoverview Enforce ES5 or ES6 class for React Components
3 * @author Dan Hamilton
4 */
5
6'use strict';
7
8const componentUtil = require('../util/componentUtil');
9const docsUrl = require('../util/docsUrl');
10const report = require('../util/report');
11
12// ------------------------------------------------------------------------------
13// Rule Definition
14// ------------------------------------------------------------------------------
15
16const messages = {
17 shouldUseES6Class: 'Component should use es6 class instead of createClass',
18 shouldUseCreateClass: 'Component should use createClass instead of es6 class',
19};
20
21/** @type {import('eslint').Rule.RuleModule} */
22module.exports = {
23 meta: {
24 docs: {
25 description: 'Enforce ES5 or ES6 class for React Components',
26 category: 'Stylistic Issues',
27 recommended: false,
28 url: docsUrl('prefer-es6-class'),
29 },
30
31 messages,
32
33 schema: [{
34 enum: ['always', 'never'],
35 }],
36 },
37
38 create(context) {
39 const configuration = context.options[0] || 'always';
40
41 return {
42 ObjectExpression(node) {
43 if (componentUtil.isES5Component(node, context) && configuration === 'always') {
44 report(context, messages.shouldUseES6Class, 'shouldUseES6Class', {
45 node,
46 });
47 }
48 },
49 ClassDeclaration(node) {
50 if (componentUtil.isES6Component(node, context) && configuration === 'never') {
51 report(context, messages.shouldUseCreateClass, 'shouldUseCreateClass', {
52 node,
53 });
54 }
55 },
56 };
57 },
58};
Note: See TracBrowser for help on using the repository browser.