Skip to content

Commit

Permalink
Merge pull request #482 from airbnb/ljharb/lint_fix
Browse files Browse the repository at this point in the history
[Tests] clear up linter rules
  • Loading branch information
aweary authored Jul 5, 2016
2 parents f85d36c + f1fa280 commit fdaeb44
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 deletions.
24 changes: 17 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@
},
"rules": {
"id-length": 0,
"new-cap": 0,
"no-console": 0,
"new-cap": [2, { "capIsNewExceptions": ["AND"] }],
"react/jsx-pascal-case": [2, { "allowAllCaps": true }],
"no-underscore-dangle": 1,
"global-require": 1,
"import/no-mutable-exports": 1,
"import/no-unresolved": 1,
"no-restricted-syntax": 1,
"no-underscore-dangle": [2, {
"allowAfterThis": true,
"allow": [
"_context",
"_currentElement",
"_instance",
"_reactInternalComponent",
"_reactInternalInstance",
"_renderedChildren",
"_renderedComponent",
"_renderedNodeType",
"_state",
"_store",
"_stringText",
],
}],
}
}
31 changes: 12 additions & 19 deletions src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,18 @@ export function childrenOfInstInternal(inst) {
const publicInst = inst.getPublicInstance();
const currentElement = inst._currentElement;
if (isDOMComponent(publicInst)) {
const children = [];
const renderedChildren = renderedChildrenOfInst(inst);
let key;
for (key in renderedChildren) {
if (!renderedChildren.hasOwnProperty(key)) {
continue;
}
return Object.keys(renderedChildren || {}).filter((key) => {
if (REACT013 && !renderedChildren[key].getPublicInstance) {
continue;
return false;
}
return true;
}).map(key => {
if (!REACT013 && typeof renderedChildren[key]._currentElement.type === 'function') {
children.push(renderedChildren[key]._instance);
continue;
return renderedChildren[key]._instance;
}
children.push(renderedChildren[key].getPublicInstance());
}
return children;
return renderedChildren[key].getPublicInstance();
});
} else if (
!REACT013 &&
isElement(currentElement) &&
Expand Down Expand Up @@ -256,18 +251,16 @@ function findAllInRenderedTreeInternal(inst, test) {
const currentElement = inst._currentElement;
if (isDOMComponent(publicInst)) {
const renderedChildren = renderedChildrenOfInst(inst);
let key;
for (key in renderedChildren) {
if (!renderedChildren.hasOwnProperty(key)) {
continue;
}
Object.keys(renderedChildren || {}).filter((key) => {
if (REACT013 && !renderedChildren[key].getPublicInstance) {
continue;
return false;
}
return true;
}).forEach((key) => {
ret = ret.concat(
findAllInRenderedTreeInternal(renderedChildren[key], test)
);
}
});
} else if (
!REACT013 &&
isElement(currentElement) &&
Expand Down
3 changes: 2 additions & 1 deletion src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ export default class ReactWrapper {
*/
hasClass(className) {
if (className && className.indexOf('.') !== -1) {
console.log(
// eslint-disable-next-line no-console
console.warn(
'It looks like you\'re calling `ReactWrapper::hasClass()` with a CSS selector. ' +
'hasClass() expects a class name, not a CSS selector.'
);
Expand Down
1 change: 1 addition & 0 deletions src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ export default class ShallowWrapper {
*/
hasClass(className) {
if (className && className.indexOf('.') !== -1) {
// eslint-disable-next-line no-console
console.warn(
'It looks like you\'re calling `ShallowWrapper::hasClass()` with a CSS selector. ' +
'hasClass() expects a class name, not a CSS selector.'
Expand Down
16 changes: 12 additions & 4 deletions src/react-compat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/* eslint react/no-deprecated: 0 */
/* eslint
global-require: 0,
import/no-mutable-exports: 0,
import/no-unresolved: 0,
react/no-deprecated: 0
*/

import { REACT013 } from './version';
import objectAssign from 'object.assign';

Expand Down Expand Up @@ -67,6 +73,7 @@ if (REACT013) {
try {
ReactDOM = require('react-dom');
} catch (e) {
// eslint-disable-next-line no-console
console.error(
'react-dom is an implicit dependency in order to support react@0.13-14. ' +
'Please add the appropriate version to your devDependencies. ' +
Expand All @@ -86,6 +93,7 @@ if (REACT013) {
try {
TestUtils = require('react-addons-test-utils');
} catch (e) {
// eslint-disable-next-line no-console
console.error(
'react-addons-test-utils is an implicit dependency in order to support react@0.13-14. ' +
'Please add the appropriate version to your devDependencies. ' +
Expand All @@ -106,21 +114,21 @@ if (REACT013) {
const originalRender = renderer.render;
const originalRenderOutput = renderer.getRenderOutput;
let isDOM = false;
let _node;
let cachedNode;
return objectAssign(renderer, {
render(node, context) {
/* eslint consistent-return: 0 */
if (typeof node.type === 'string') {
isDOM = true;
_node = node;
cachedNode = node;
} else {
isDOM = false;
return originalRender.call(this, node, context);
}
},
getRenderOutput() {
if (isDOM) {
return _node;
return cachedNode;
}
return originalRenderOutput.call(this);
},
Expand Down

0 comments on commit fdaeb44

Please sign in to comment.