Sha256: 7a9372a9e0e8f4784d7cd5653ea6b7bf70d50c7da7b08bb344996709a8f52744

Contents?: true

Size: 1.33 KB

Versions: 43

Compression:

Stored size: 1.33 KB

Contents

/**
 * @fileoverview Enforce ES5 or ES6 class for React Components
 * @author Dan Hamilton
 */
'use strict';

const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------

module.exports = {
  meta: {
    docs: {
      description: 'Enforce ES5 or ES6 class for React Components',
      category: 'Stylistic Issues',
      recommended: false,
      url: docsUrl('prefer-es6-class')
    },

    schema: [{
      enum: ['always', 'never']
    }]
  },

  create: Components.detect((context, components, utils) => {
    const configuration = context.options[0] || 'always';

    return {
      ObjectExpression: function(node) {
        if (utils.isES5Component(node) && configuration === 'always') {
          context.report({
            node: node,
            message: 'Component should use es6 class instead of createClass'
          });
        }
      },
      ClassDeclaration: function(node) {
        if (utils.isES6Component(node) && configuration === 'never') {
          context.report({
            node: node,
            message: 'Component should use createClass instead of es6 class'
          });
        }
      }
    };
  })
};

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-17.6.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.5.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.4.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.3.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.2.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.1.1 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.1.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.0.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.29.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.28.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.27.1 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.27.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.26.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.25.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.24.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.23.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.22.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.21.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.20.1 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-16.20.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js