From b271efb7d3d8972bf872fed40d5450a001e2c0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 1 Mar 2016 15:40:52 -0800 Subject: [PATCH 1/2] Convert to .eslintrc.js --- .eslintrc | 66 ----------------------------------------------- .eslintrc.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 66 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index f299267262..0000000000 --- a/.eslintrc +++ /dev/null @@ -1,66 +0,0 @@ ---- -parser: babel-eslint - -extends: - - ./node_modules/fbjs-scripts/eslint/.eslintrc.js - -plugins: - - react - - react-internal - -ecmaFeatures: - modules: false - -# We're stricter than the default config, mostly. We'll override a few rules and -# then enable some React specific ones. -rules: - accessor-pairs: 0 - brace-style: [2, 1tbs] - comma-dangle: [2, always-multiline] - consistent-return: 2 - dot-location: [2, property] - dot-notation: 2 - eol-last: 2 - eqeqeq: [2, allow-null] - indent: [2, 2, {SwitchCase: 1}] - jsx-quotes: [2, prefer-double] - no-bitwise: 0 - no-dupe-class-members: 2 - no-multi-spaces: 2 - no-restricted-syntax: [2, WithStatement] - no-shadow: 2 - no-unused-expressions: 2 - no-unused-vars: [2, {args: none}] - quotes: [2, single, avoid-escape] - space-after-keywords: 2 - space-before-blocks: 2 - space-before-keywords: 2 - strict: [2, global] - - # JSX - # Our transforms set this automatically - react/display-name: 0 - react/jsx-boolean-value: [2, always] - react/jsx-no-undef: 2 - # We don't care to do this - react/jsx-sort-prop-types: 0 - react/jsx-sort-props: 0 - react/jsx-uses-react: 2 - react/jsx-uses-vars: 2 - # It's easier to test some things this way - react/no-did-mount-set-state: 0 - react/no-did-update-set-state: 0 - # We define multiple components in test files - react/no-multi-comp: 0 - react/no-unknown-property: 2 - # This isn't useful in our test code - react/prop-types: 0 - react/react-in-jsx-scope: 2 - react/self-closing-comp: 2 - # We don't care to do this - react/sort-comp: 0 - react/wrap-multilines: [2, {declaration: false, assignment: false}] - - # CUSTOM RULES - # the second argument of warning/invariant should be a literal string - react-internal/warning-and-invariant-args: 2 diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000000..e7c9b46d53 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,73 @@ +const OFF = 0; +const WARNING = 1; +const ERROR = 2; + +module.exports = { + parser: 'babel-eslint', + + extends: './node_modules/fbjs-scripts/eslint/.eslintrc.js', + + plugins: [ + 'react', + 'react-internal', + ], + + ecmaFeatures: { + modules: false + }, + + // We're stricter than the default config, mostly. We'll override a few rules + // and then enable some React specific ones. + rules: { + 'accessor-pairs': OFF, + 'brace-style': [ERROR, '1tbs'], + 'comma-dangle': [ERROR, 'always-multiline'], + 'consistent-return': ERROR, + 'dot-location': [ERROR, 'property'], + 'dot-notation': ERROR, + 'eol-last': ERROR, + 'eqeqeq': [ERROR, 'allow-null'], + 'indent': [ERROR, 2, {SwitchCase: 1}], + 'jsx-quotes': [ERROR, 'prefer-double'], + 'no-bitwise': OFF, + 'no-dupe-class-members': ERROR, + 'no-multi-spaces': ERROR, + 'no-restricted-syntax': [ERROR, 'WithStatement'], + 'no-shadow': ERROR, + 'no-unused-expressions': ERROR, + 'no-unused-vars': [ERROR, {args: 'none'}], + 'quotes': [ERROR, 'single', 'avoid-escape'], + 'space-after-keywords': ERROR, + 'space-before-blocks': ERROR, + 'space-before-keywords': ERROR, + 'strict': [ERROR, 'global'], + + // React & JSX + // Our transforms set this automatically + 'react/display-name': OFF, + 'react/jsx-boolean-value': [ERROR, 'always'], + 'react/jsx-no-undef': ERROR, + // We don't care to do this + 'react/jsx-sort-prop-types': OFF, + 'react/jsx-sort-props': OFF, + 'react/jsx-uses-react': ERROR, + 'react/jsx-uses-vars': ERROR, + // It's easier to test some things this way + 'react/no-did-mount-set-state': OFF, + 'react/no-did-update-set-state': OFF, + // We define multiple components in test files + 'react/no-multi-comp': OFF, + 'react/no-unknown-property': ERROR, + // This isn't useful in our test code + 'react/prop-types': OFF, + 'react/react-in-jsx-scope': ERROR, + 'react/self-closing-comp': ERROR, + // We don't care to do this + 'react/sort-comp': OFF, + 'react/wrap-multilines': [ERROR, {declaration: false, assignment: false}], + + // CUSTOM RULES + // the second argument of warning/invariant should be a literal string + 'react-internal/warning-and-invariant-args': ERROR, + } +}; From 093bb220301ab8a1fc5b6248ca433d413d043021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Wed, 2 Mar 2016 15:07:45 -0800 Subject: [PATCH 2/2] Update lint config, dependencies, fix issues This also fixes messages from new synthetic events warnings --- .eslintrc.js | 4 +- package.json | 4 +- .../__tests__/SyntheticEvent-test.js | 54 +++++++++++-------- .../dom/shared/DOMPropertyOperations.js | 5 +- src/test/__tests__/ReactTestUtils-test.js | 3 +- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e7c9b46d53..a099d6bfca 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -30,7 +30,6 @@ module.exports = { 'indent': [ERROR, 2, {SwitchCase: 1}], 'jsx-quotes': [ERROR, 'prefer-double'], 'no-bitwise': OFF, - 'no-dupe-class-members': ERROR, 'no-multi-spaces': ERROR, 'no-restricted-syntax': [ERROR, 'WithStatement'], 'no-shadow': ERROR, @@ -39,6 +38,7 @@ module.exports = { 'quotes': [ERROR, 'single', 'avoid-escape'], 'space-after-keywords': ERROR, 'space-before-blocks': ERROR, + 'space-before-function-paren': [ERROR, {anonymous: 'never', named: 'never'}], 'space-before-keywords': ERROR, 'strict': [ERROR, 'global'], @@ -57,7 +57,7 @@ module.exports = { 'react/no-did-update-set-state': OFF, // We define multiple components in test files 'react/no-multi-comp': OFF, - 'react/no-unknown-property': ERROR, + 'react/no-unknown-property': OFF, // This isn't useful in our test code 'react/prop-types': OFF, 'react/react-in-jsx-scope': ERROR, diff --git a/package.json b/package.json index 54234a3413..f0c1fc9e89 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "del": "^2.0.2", "derequire": "^2.0.3", "envify": "^3.0.0", - "eslint": "1.9.0", - "eslint-plugin-react": "3.8.0", + "eslint": "1.10.3", + "eslint-plugin-react": "4.1.0", "eslint-plugin-react-internal": "file:eslint-rules", "fbjs": "^0.6.1", "fbjs-scripts": "0.6.0-alpha.2", diff --git a/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js b/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js index 68ac8ab75e..d05ebdf367 100644 --- a/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js +++ b/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js @@ -86,11 +86,14 @@ describe('SyntheticEvent', function() { expect(syntheticEvent.type).toBe(null); expect(syntheticEvent.nativeEvent).toBe(null); expect(syntheticEvent.target).toBe(null); - expect(console.error.calls.length).toBe(3); // once for each property accessed - expect(console.error.argsForCall[0][0]).toBe( // assert the first warning for accessing `type` - 'Warning: This synthetic event is reused for performance reasons. If you\'re seeing this, ' + - 'you\'re accessing the property `type` on a released/nullified synthetic event. This is set to null. ' + - 'If you must keep the original synthetic event around, use event.persist(). ' + + // once for each property accessed + expect(console.error.calls.length).toBe(3); + // assert the first warning for accessing `type` + expect(console.error.argsForCall[0][0]).toBe( + 'Warning: This synthetic event is reused for performance reasons. If ' + + 'you\'re seeing this, you\'re accessing the property `type` on a ' + + 'released/nullified synthetic event. This is set to null. If you must ' + + 'keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.' ); }); @@ -103,10 +106,11 @@ describe('SyntheticEvent', function() { expect(syntheticEvent.type = 'MouseEvent').toBe('MouseEvent'); expect(console.error.calls.length).toBe(1); expect(console.error.argsForCall[0][0]).toBe( - 'Warning: This synthetic event is reused for performance reasons. If you\'re seeing this, ' + - 'you\'re setting the property `type` on a released/nullified synthetic event. This is ' + - 'effectively a no-op. If you must keep the original synthetic event around, use ' + - 'event.persist(). See https://fb.me/react-event-pooling for more information.' + 'Warning: This synthetic event is reused for performance reasons. If ' + + 'you\'re seeing this, you\'re setting the property `type` on a ' + + 'released/nullified synthetic event. This is effectively a no-op. If you must ' + + 'keep the original synthetic event around, use event.persist(). ' + + 'See https://fb.me/react-event-pooling for more information.' ); }); @@ -117,10 +121,11 @@ describe('SyntheticEvent', function() { syntheticEvent.preventDefault(); expect(console.error.calls.length).toBe(1); expect(console.error.argsForCall[0][0]).toBe( - 'Warning: This synthetic event is reused for performance reasons. If you\'re seeing this, ' + - 'you\'re accessing the method `preventDefault` on a released/nullified synthetic event. ' + - 'This is a no-op function. If you must keep the original synthetic event around, ' + - 'use event.persist(). See https://fb.me/react-event-pooling for more information.' + 'Warning: This synthetic event is reused for performance reasons. If ' + + 'you\'re seeing this, you\'re accessing the method `preventDefault` on a ' + + 'released/nullified synthetic event. This is a no-op function. If you must ' + + 'keep the original synthetic event around, use event.persist(). ' + + 'See https://fb.me/react-event-pooling for more information.' ); }); @@ -131,10 +136,11 @@ describe('SyntheticEvent', function() { syntheticEvent.stopPropagation(); expect(console.error.calls.length).toBe(1); expect(console.error.argsForCall[0][0]).toBe( - 'Warning: This synthetic event is reused for performance reasons. If you\'re seeing this, ' + - 'you\'re accessing the method `stopPropagation` on a released/nullified synthetic event. ' + - 'This is a no-op function. If you must keep the original synthetic event around, ' + - 'use event.persist(). See https://fb.me/react-event-pooling for more information.' + 'Warning: This synthetic event is reused for performance reasons. If ' + + 'you\'re seeing this, you\'re accessing the method `stopPropagation` on a ' + + 'released/nullified synthetic event. This is a no-op function. If you must ' + + 'keep the original synthetic event around, use event.persist(). ' + + 'See https://fb.me/react-event-pooling for more information.' ); }); @@ -154,9 +160,10 @@ describe('SyntheticEvent', function() { expect(console.error.calls.length).toBe(1); expect(console.error.argsForCall[0][0]).toBe( - 'Warning: This synthetic event is reused for performance reasons. If you\'re seeing this, ' + - 'you\'re accessing the property `nativeEvent` on a released/nullified synthetic event. ' + - 'This is set to null. If you must keep the original synthetic event around, use event.persist(). ' + + 'Warning: This synthetic event is reused for performance reasons. If ' + + 'you\'re seeing this, you\'re accessing the property `nativeEvent` on a ' + + 'released/nullified synthetic event. This is set to null. If you must ' + + 'keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.' ); }); @@ -170,9 +177,10 @@ describe('SyntheticEvent', function() { if (typeof Proxy === 'function') { expect(console.error.calls.length).toBe(1); expect(console.error.argsForCall[0][0]).toBe( - 'Warning: This synthetic event is reused for performance reasons. If you\'re ' + - 'seeing this, you\'re adding a new property in the synthetic event object. ' + - 'The property is never released. See https://fb.me/react-event-pooling for more information.' + 'Warning: This synthetic event is reused for performance reasons. If ' + + 'you\'re seeing this, you\'re adding a new property in the synthetic ' + + 'event object. The property is never released. ' + + 'See https://fb.me/react-event-pooling for more information.' ); } else { expect(console.error.calls.length).toBe(0); diff --git a/src/renderers/dom/shared/DOMPropertyOperations.js b/src/renderers/dom/shared/DOMPropertyOperations.js index 90858f03bb..dc0c3fb7f9 100644 --- a/src/renderers/dom/shared/DOMPropertyOperations.js +++ b/src/renderers/dom/shared/DOMPropertyOperations.js @@ -18,8 +18,9 @@ var ReactPerf = require('ReactPerf'); var quoteAttributeValueForBrowser = require('quoteAttributeValueForBrowser'); var warning = require('warning'); -var VALID_ATTRIBUTE_NAME_REGEX = new RegExp('^[' + DOMProperty.ATTRIBUTE_NAME_START_CHAR + - '][' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$'); +var VALID_ATTRIBUTE_NAME_REGEX = new RegExp( + '^[' + DOMProperty.ATTRIBUTE_NAME_START_CHAR + '][' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$' +); var illegalAttributeNameCache = {}; var validatedAttributeNameCache = {}; diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/test/__tests__/ReactTestUtils-test.js index dbe421e020..a7cf4ab846 100644 --- a/src/test/__tests__/ReactTestUtils-test.js +++ b/src/test/__tests__/ReactTestUtils-test.js @@ -206,8 +206,7 @@ describe('ReactTestUtils', function() { ref={() => {}} onClick={this.handleUserClick} className={this.state.clicked ? 'clicked' : ''} - > - + /> ); }, });