Skip to content

Commit

Permalink
Merge pull request facebook#6175 from zpao/eslintrc-fixes
Browse files Browse the repository at this point in the history
ESLint upgrade & fixes
  • Loading branch information
zpao committed Mar 3, 2016
2 parents f8046f2 + 093bb22 commit b89e7d2
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 95 deletions.
66 changes: 0 additions & 66 deletions .eslintrc

This file was deleted.

73 changes: 73 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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-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-function-paren': [ERROR, {anonymous: 'never', named: 'never'}],
'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': OFF,
// 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,
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
});
Expand All @@ -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.'
);
});

Expand All @@ -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.'
);
});

Expand All @@ -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.'
);
});

Expand All @@ -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.'
);
});
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/renderers/dom/shared/DOMPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
3 changes: 1 addition & 2 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ describe('ReactTestUtils', function() {
ref={() => {}}
onClick={this.handleUserClick}
className={this.state.clicked ? 'clicked' : ''}
>
</div>
/>
);
},
});
Expand Down

0 comments on commit b89e7d2

Please sign in to comment.