Skip to content

Commit

Permalink
Use shared eslint settings
Browse files Browse the repository at this point in the history
  • Loading branch information
glenjamin committed Apr 22, 2016
1 parent 37e898d commit 991dba5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 74 deletions.
32 changes: 1 addition & 31 deletions .eslintrc
@@ -1,36 +1,6 @@
{
"extends": "@glenjamin",
"env": {
"node": true
},
"rules": {
"strict": 0,
"quotes": 0,
"indent": [2, 2],
"curly": [2, "multi-line"],
"no-use-before-define": [1, "nofunc"],
"no-unused-vars": [2, "all"],
"no-mixed-requires": [1, true],
"max-depth": [1, 5],
"max-len": [1, 80, 4],
"max-params": [1, 6],
"max-statements": [1, 20],
"eqeqeq": 0,
"new-cap": 0,
"no-else-return": 1,
"no-eq-null": 1,
"no-lonely-if": 1,
"no-path-concat": 0,
"comma-dangle": 0,
"complexity": [1, 20],
"no-floating-decimal": 1,
"no-void": 1,
"no-sync": 1,
"consistent-this": [1, "nope-dont-capture-this"],
"max-nested-callbacks": [2, 3],
"no-nested-ternary": 1,
"space-after-keywords": [1, "always"],
"space-before-function-paren": [1, "never"],
"spaced-comment": [1, "always"],
"no-undef": 2
}
}
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,9 @@ node_js:
- "0.12"
- "4"
- "5"
script: "npm run travis"
script:
- "npm run lint"
- "npm run coverage"
after_script: "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
env:
- REACT=0.13
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "mocha",
"lint": "eslint . --max-warnings 0",
"travis": "npm run lint && istanbul cover _mocha --",
"coverage": "istanbul cover _mocha --",
"doc": "doctoc README.md"
},
"repository": {
Expand All @@ -33,9 +33,10 @@
"is-subset": "^0.1.1"
},
"devDependencies": {
"@glenjamin/eslint-config": "^1.1.0",
"chai": "^3.4.0",
"coveralls": "^2.11.2",
"eslint": "^1.10.3",
"eslint": "2.4.0",
"istanbul": "^0.4.0",
"mocha": "^2.2.5",
"react": "^0.14.0",
Expand Down
17 changes: 10 additions & 7 deletions skin-deep.js
Expand Up @@ -107,10 +107,7 @@ function SkinDeep(getCurrentNode, renderer, instance) {
var rawTree = tree.subTree(path);
if (!rawTree) throw new Error(path + ' not found in tree');
var node = rawTree.getRenderOutput();
tree = shallowRender(
function() {return React.createElement(node.type, node.props)},
context
);
tree = shallowRender(constantly(node), context);
}
return tree;
},
Expand Down Expand Up @@ -138,6 +135,7 @@ function SkinDeep(getCurrentNode, renderer, instance) {
},
findComponent: function(type, props) {
if (arguments.length == 1) {
// eslint-disable-next-line no-console
console.warn(
"Using a component in findComponent is deprecated. " +
"Pass name and props as separate arguments instead"
Expand All @@ -150,6 +148,7 @@ function SkinDeep(getCurrentNode, renderer, instance) {
},
findComponentLike: function(type, props) {
if (arguments.length == 1) {
// eslint-disable-next-line no-console
console.warn(
"Using a component in findComponent is deprecated. " +
"Pass name and props as separate arguments instead"
Expand Down Expand Up @@ -203,7 +202,7 @@ function createNodePredicate(query) {
}
// React Component itself
if (typeof query !== 'string') {
return function(n) { return n.type == query };
return function(n) { return n.type == query; };
}
if (query.match(/^\.[\S]+$/)) {
return findNodeByClass(query.substring(1));
Expand All @@ -227,13 +226,13 @@ function createFinder(selector, predicate, isLike) {
return isLike
? subset(node.props, predicate)
: subset(node.props, predicate) && subset(predicate, node.props);
}
};
} else if (typeof predicate === 'function') {
otherMatcher = predicate;
}
return function(node) {
return nodeMatcher(node) && otherMatcher(node);
}
};
}

function findNodeByClass(cls) {
Expand Down Expand Up @@ -321,6 +320,10 @@ function normaliseSpaces(str) {
return str.replace(/\s+/g, ' ');
}

function constantly(x) {
return function() { return x; };
}

function mapcat(array, fn) {
var result = [];
array.forEach(function(x, i) {
Expand Down
8 changes: 5 additions & 3 deletions test/new.js
Expand Up @@ -5,6 +5,7 @@ var React = require('react');
var React013 = (React.version.substring(0, 4) == '0.13');


/* eslint-disable no-console */
var consoleWarn = console.warn, consoleError = console.error;
function throwError(msg) {
throw new Error(msg);
Expand All @@ -15,6 +16,7 @@ function hardFailConsole() {
function resetConsole() {
console.warn = consoleWarn; console.error = consoleError;
}
/* eslint-enable no-console */


// var createFragment;
Expand Down Expand Up @@ -293,7 +295,7 @@ describe("skin-deep", function() {
});
beforeEach(function() {
tree = sd.shallowRender(
function() { return $(ContextComponent, { thing: 'A' }) },
function() { return $(ContextComponent, { thing: 'A' }); },
{ beep: false }
);
});
Expand All @@ -303,7 +305,7 @@ describe("skin-deep", function() {
function() { return $(ContextComponent, { thing: 'X' }); }
);
expect(tree.props).to.eql({ children: [ 'X', false ]});
})
});
it('should allow replacing context', function() {
expect(tree.props).to.eql({ children: [ 'A', false ]});
tree.reRender(
Expand All @@ -322,7 +324,7 @@ describe("skin-deep", function() {
expect(tree.props).to.eql({ children: [ 'A', false ]});
tree.reRender($(ContextComponent, { thing: 'X' }));
expect(tree.props).to.eql({ children: [ 'X', false ]});
})
});
it('should allow replacing context', function() {
expect(tree.props).to.eql({ children: [ 'A', false ]});
tree.reRender($(ContextComponent, { thing: 'X' }), { beep: true });
Expand Down
64 changes: 34 additions & 30 deletions test/test.js
Expand Up @@ -418,9 +418,9 @@ describe("skin-deep", function() {
var wut = tree.subTree("#wut", { id: 'wut', prop: "foo" });
expect(wut).to.eql(false);

var wut = tree.subTree("#wut", { id: 'wut', prop: "val" });
expect(wut).to.be.an('object');
expect(wut.getRenderOutput().props).to.have.property("id", "wut");
var wut2 = tree.subTree("#wut", { id: 'wut', prop: "val" });
expect(wut2).to.be.an('object');
expect(wut2.getRenderOutput().props).to.have.property("id", "wut");
});
it("should grab a subtree by class selector", function() {
var abc = tree.subTree(".abc");
Expand All @@ -431,9 +431,9 @@ describe("skin-deep", function() {
var yup = tree.subTree(".yup", { className: 'yup', prop: "foo" });
expect(yup).to.eql(false);

var yup = tree.subTree(".yup", { className: 'yup', prop: "val" });
expect(yup).to.be.an('object');
expect(yup.getRenderOutput().props).to.have.property("className", "yup");
var yup2 = tree.subTree(".yup", { className: 'yup', prop: "val" });
expect(yup2).to.be.an('object');
expect(yup2.getRenderOutput().props).to.have.property("className", "yup");
});
it("should grab a subtree by tag selector", function() {
var abc = tree.subTree("object");
Expand All @@ -445,9 +445,9 @@ describe("skin-deep", function() {
var subtree = tree.subTree("object", { children: 'not objection!' });
expect(subtree).to.eql(false);

var subtree = tree.subTree("object", { children: 'objection!' });
expect(subtree).to.be.an('object');
expect(subtree.getRenderOutput().type).to.eql('object');
var subtree2 = tree.subTree("object", { children: 'objection!' });
expect(subtree2).to.be.an('object');
expect(subtree2.getRenderOutput().type).to.eql('object');
});
it("should grab a subtree by component name", function() {
var abc = tree.subTree("Widget");
Expand All @@ -464,17 +464,17 @@ describe("skin-deep", function() {
var subtree = tree.subTree("Widget", { children: 'not stuff' });
expect(subtree).to.eql(false);

var subtree = tree.subTree("Widget", { children: 'stuff' });
expect(subtree).to.be.an('object');
expect(subtree.getRenderOutput().type).to.eql(Widget);
var subtree2 = tree.subTree("Widget", { children: 'stuff' });
expect(subtree2).to.be.an('object');
expect(subtree2.getRenderOutput().type).to.eql(Widget);
});
it("should grab a subtree by component + props", function() {
var subtree = tree.subTree(Widget, { children: 'not stuff' });
expect(subtree).to.eql(false);

var subtree = tree.subTree(Widget, { children: 'stuff' });
expect(subtree).to.be.an('object');
expect(subtree.type).to.eql(Widget);
var subtree2 = tree.subTree(Widget, { children: 'stuff' });
expect(subtree2).to.be.an('object');
expect(subtree2.type).to.eql(Widget);
});
it("should grab first subtree when using function matcher", function() {
var subtree = tree.subTree('*', function(node) {
Expand Down Expand Up @@ -503,7 +503,7 @@ describe("skin-deep", function() {
it("should expose .props", function() {
expect(tree.subTree('#wut').props).to.eql({
id: 'wut', prop: 'val'
})
});
});
});
});
Expand Down Expand Up @@ -546,9 +546,9 @@ describe("skin-deep", function() {
var wut = tree.subTreeLike("#wut", { id: 'wut', prop: "foo" });
expect(wut).to.eql(false);

var wut = tree.subTreeLike("#wut", { prop: "val" });
expect(wut).to.be.an('object');
expect(wut.getRenderOutput().props).to.have.property("id", "wut");
var wut2 = tree.subTreeLike("#wut", { prop: "val" });
expect(wut2).to.be.an('object');
expect(wut2.getRenderOutput().props).to.have.property("id", "wut");
});
it("should grab a subtree by class selector", function() {
var abc = tree.subTreeLike(".abc");
Expand All @@ -559,9 +559,9 @@ describe("skin-deep", function() {
var yup = tree.subTreeLike(".yup", { className: 'yup', prop: "foo" });
expect(yup).to.eql(false);

var yup = tree.subTreeLike(".yup", { prop: "val" });
expect(yup).to.be.an('object');
expect(yup.getRenderOutput().props).to.have.property("className", "yup");
var yup2 = tree.subTreeLike(".yup", { prop: "val" });
expect(yup2).to.be.an('object');
expect(yup2.getRenderOutput().props).to.have.property("className", "yup");
});
it("should grab a subtree by tag selector", function() {
var abc = tree.subTreeLike("object");
Expand All @@ -573,9 +573,9 @@ describe("skin-deep", function() {
var subtree = tree.subTreeLike("object", { children: 'not objection!' });
expect(subtree).to.eql(false);

var subtree = tree.subTreeLike("object", { children: 'objection!' });
expect(subtree).to.be.an('object');
expect(subtree.getRenderOutput().props).to.have.property('id', 'bob');
var subtree2 = tree.subTreeLike("object", { children: 'objection!' });
expect(subtree2).to.be.an('object');
expect(subtree2.getRenderOutput().props).to.have.property('id', 'bob');
});
it("should grab a subtree by component name", function() {
var abc = tree.subTreeLike("Widget");
Expand All @@ -587,9 +587,9 @@ describe("skin-deep", function() {
var subtree = tree.subTreeLike("Widget", { children: 'not stuff' });
expect(subtree).to.eql(false);

var subtree = tree.subTreeLike("Widget", { more: true });
expect(subtree).to.be.an('object');
expect(subtree.getRenderOutput().props).to.have.property('test', 'abc');
var subtree2 = tree.subTreeLike("Widget", { more: true });
expect(subtree2).to.be.an('object');
expect(subtree2.getRenderOutput().props).to.have.property('test', 'abc');
});
it("should grab first subtree by * selector + partial props", function() {
var subtree = tree.subTreeLike("*", { prop: 'val' });
Expand All @@ -616,7 +616,7 @@ describe("skin-deep", function() {
it("should expose .props", function() {
expect(tree.subTreeLike('#wut').props).to.eql({
id: 'wut', prop: 'val'
})
});
});
});
});
Expand Down Expand Up @@ -913,6 +913,7 @@ describe("skin-deep", function() {
.to.eql(false);
});
describe("back-compat with a warning", function() {
/* eslint-disable no-console */
var originalWarn = console.warn;
var warning;
beforeEach(function() {
Expand All @@ -922,6 +923,7 @@ describe("skin-deep", function() {
afterEach(function() {
console.warn = originalWarn;
});
/* eslint-enable no-console */
it("should find a DOM component", function() {
var c = tree.findComponent($('span', {}, "stuff", "and", "nonsense"));
expect(c).to.have.property('type', 'span');
Expand Down Expand Up @@ -1002,6 +1004,7 @@ describe("skin-deep", function() {
.to.eql(false);
});
describe("back-compat with a warning", function() {
/* eslint-disable no-console */
var originalWarn = console.warn;
var warning;
beforeEach(function() {
Expand All @@ -1011,6 +1014,7 @@ describe("skin-deep", function() {
afterEach(function() {
console.warn = originalWarn;
});
/* eslint-enable no-console */
it("should find a DOM component", function() {
var c = tree.findComponentLike($('span', {}, "stuff", "&", "nonsense"));
expect(c).to.have.property('type', 'span');
Expand Down Expand Up @@ -1132,7 +1136,7 @@ describe("skin-deep", function() {
var babyTrees = [
sd.shallowRender($(Baby, {goats: 'hello'})),
sd.shallowRender($(Baby, {goats: 'bye'}))
]
];
expect(result.getRenderOutput()).to.eql(
babyTrees[0].getRenderOutput()
);
Expand Down

0 comments on commit 991dba5

Please sign in to comment.