Repository: yannickcr/eslint-plugin-react
Pull request #508 (2016-03-21 13:03:52)

Fixes an Edge Case in jsx-pascal-case
A fun-size PR to support single letter component names. Since it's technically valid PascalCase, it shouldn't break (potential usecase: providing a wrapper component for the react tag elements).



Patch:
diff --git a/docs/rules/no-set-state.md b/docs/rules/no-set-state.md
index 7693ce5b..274dca03 100644
--- a/docs/rules/no-set-state.md
+++ b/docs/rules/no-set-state.md
@@ -1,6 +1,6 @@
 # Prevent usage of setState (no-set-state)
 
-When using an architecture that separates your application state from your UI components (e.g. Flux), it may be desirable to forbid the use of local component state. This rule is especially helpful in read-only applications (that don't use forms), since local component state should rarely be necessary in such cases.
+When using an architecture that separates your application state from your UI components (e.g. Flux), it may be desirable to forbid the use of local component state.
 
 ## Rule Details
 
diff --git a/index.js b/index.js
index effb5ae9..38b65504 100644
--- a/index.js
+++ b/index.js
@@ -41,8 +41,7 @@ module.exports = {
     'prefer-es6-class': require('./lib/rules/prefer-es6-class'),
     'jsx-key': require('./lib/rules/jsx-key'),
     'no-string-refs': require('./lib/rules/no-string-refs'),
-    'prefer-stateless-function': require('./lib/rules/prefer-stateless-function'),
-    'require-render-return': require('./lib/rules/require-render-return')
+    'prefer-stateless-function': require('./lib/rules/prefer-stateless-function')
   },
   configs: {
     recommended: {
diff --git a/lib/rules/jsx-pascal-case.js b/lib/rules/jsx-pascal-case.js
index bf102e6b..fde14d9b 100644
--- a/lib/rules/jsx-pascal-case.js
+++ b/lib/rules/jsx-pascal-case.js
@@ -9,7 +9,7 @@
 // Constants
 // ------------------------------------------------------------------------------
 
-var PASCAL_CASE_REGEX = /^[A-Z0-9]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*$/;
+var PASCAL_CASE_REGEX = /^([A-Z0-9]|[A-Z0-9]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*)$/;
 var COMPAT_TAG_REGEX = /^[a-z]|\-/;
 
 // ------------------------------------------------------------------------------
diff --git a/lib/rules/require-render-return.js b/lib/rules/require-render-return.js
deleted file mode 100644
index 84c6ec7e..00000000
--- a/lib/rules/require-render-return.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * @fileoverview Enforce ES5 or ES6 class for returning value in render function.
- * @author Mark Orel
- */
-'use strict';
-
-var Components = require('../util/Components');
-
-// ------------------------------------------------------------------------------
-// Rule Definition
-// ------------------------------------------------------------------------------
-
-module.exports = Components.detect(function(context) {
-  /**
-   * Helper for checking if parent node is render method.
-   * @param {ASTNode} node to check
-   * @returns {boolean} If previous node is method and name is render returns true, otherwise false;
-   */
-  function checkParent(node) {
-    return (node.parent.type === 'Property' || node.parent.type === 'MethodDefinition')
-        && node.parent.key
-        && node.parent.key.name === 'render';
-  }
-
-  /**
-   * Helper for checking if child node exists and if it's ReturnStatement
-   * @param {ASTNode} node to check
-   * @returns {boolean} True if ReturnStatement exists, otherwise false
-   */
-  function checkReturnStatementExistence(node) {
-    if (!node.body && !node.body.body && !node.body.body.length) {
-      return false;
-    }
-
-    var hasReturnStatement = node.body.body.some(function(elem) {
-      return elem.type === 'ReturnStatement';
-    });
-
-    return hasReturnStatement;
-  }
-
-
-  return {
-    FunctionExpression: function(node) {
-      if (checkParent(node) && !checkReturnStatementExistence(node)) {
-        context.report({
-          node: node,
-          message: 'Your render method should have return statement'
-        });
-      }
-    }
-  };
-});
-
-module.exports.schema = [{}];


Test patch:
diff --git a/tests/lib/rules/jsx-pascal-case.js b/tests/lib/rules/jsx-pascal-case.js
index e094da03..1e473afa 100644
--- a/tests/lib/rules/jsx-pascal-case.js
+++ b/tests/lib/rules/jsx-pascal-case.js
@@ -51,6 +51,10 @@ ruleTester.run('jsx-pascal-case', rule, {
   }, {
     code: '<T3stComp0nent />',
     parserOptions: parserOptions
+  },
+  {
+    code: '<T />',
+    parserOptions: parserOptions
   }],
 
   invalid: [{
diff --git a/tests/lib/rules/require-render-return.js b/tests/lib/rules/require-render-return.js
deleted file mode 100644
index 8010b573..00000000
--- a/tests/lib/rules/require-render-return.js
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * @fileoverview Enforce ES5 or ES6 class for returning value in render function.
- * @author Mark Orel
- */
-'use strict';
-
-// ------------------------------------------------------------------------------
-// Requirements
-// ------------------------------------------------------------------------------
-
-var rule = require('../../../lib/rules/require-render-return');
-var RuleTester = require('eslint').RuleTester;
-
-var parserOptions = {
-  ecmaVersion: 6,
-  ecmaFeatures: {
-    jsx: true
-  }
-};
-
-require('babel-eslint');
-
-// ------------------------------------------------------------------------------
-// Tests
-// ------------------------------------------------------------------------------
-
-var ruleTester = new RuleTester();
-ruleTester.run('require-render-return', rule, {
-
-  valid: [{
-    code: [
-      'class Hello extends React.Component {',
-      '  render() {',
-      '    return <div>Hello {this.props.name}</div>;',
-      '  }',
-      '}'
-    ].join('\n'),
-    parserOptions: parserOptions
-  }, {
-    code: [
-      'var Hello = React.createClass({',
-      '  displayName: \'Hello\',',
-      '  render: function() {',
-      '    return <div></div>',
-      '  }',
-      '});'
-    ].join('\n'),
-    parserOptions: parserOptions
-  }],
-
-  invalid: [{
-    code: [
-      'var Hello = React.createClass({',
-      '  displayName: \'Hello\',',
-      '  render: function() {}',
-      '});'
-    ].join('\n'),
-    parserOptions: parserOptions,
-    errors: [{
-      message: 'Your render method should have return statement'
-    }]
-  }, {
-    code: [
-      'class Hello extends React.Component {',
-      '  render() {} ',
-      '}'
-    ].join('\n'),
-    parserOptions: parserOptions,
-    errors: [{
-      message: 'Your render method should have return statement'
-    }]
-  }
-]});