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-18.0.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.21.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.20.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.19.1 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.19.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.18.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.17.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.16.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.15.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.14.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.13.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.12.2 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.12.1 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.12.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.11.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.10.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.9.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.8.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.7.0 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js
govuk_publishing_components-17.6.1 node_modules/eslint-plugin-react/lib/rules/prefer-es6-class.js