Fix lint errors

This commit is contained in:
Brandon Keepers 2016-10-28 11:30:10 -04:00
parent f9db96b7fd
commit 1572100fff
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
4 changed files with 39 additions and 38 deletions

View File

@ -4,4 +4,4 @@ module.exports = class Behavior {
this.conditions = conditions || [];
this.then = actions;
}
}
};

View File

@ -1,36 +1,7 @@
var walk = require('tree-walk');
const walk = require('tree-walk');
const Behavior = require('./behavior');
const actions = require('./actions');
module.exports = class Transformer {
constructor(tree) {
this.behaviors = walk.filter(tree, walk.preorder, function(node) {
return node.type === 'behavior';
});
}
transform() {
return walk.reduce(this.behaviors, this.walk.bind(this));
}
walk(result, node) {
if(this[node.type]) {
return this[node.type](result, node);
} else {
return result || node;
}
}
action(node, result) {
return new Action(node.name, node.value);
}
behavior(result, node) {
return new Behavior(result.events, result.conditions, result.then);
}
}
class Action {
constructor(name, value) {
this.name = name;
@ -41,3 +12,31 @@ class Action {
actions[this.name](github, payload, this.value);
}
}
module.exports = class Transformer {
constructor(tree) {
this.behaviors = walk.filter(tree, walk.preorder, node => {
return node.type === 'behavior';
});
}
transform() {
return walk.reduce(this.behaviors, this.walk.bind(this));
}
walk(result, node) {
if (this[node.type]) {
return this[node.type](result, node);
} else {
return result || node;
}
}
action(node) {
return new Action(node.name, node.value);
}
behavior(node) {
return new Behavior(node.events, node.conditions, node.then);
}
};

View File

@ -26,7 +26,9 @@
"xo": {
"esnext": true,
"space": true,
"rules": {},
"rules": {
"no-else-return": 0
},
"ignores": [],
"envs": [
"node",

View File

@ -42,9 +42,9 @@ describe('parser', () => {
it('parses an event and action', () => {
expect(parser.parse('on issues.opened then close;')).toEqual([{
type: 'behavior',
events: [{type: 'event', name: 'issues', action: 'opened'}],
then: [{type: 'action', name: 'close'}]
type: 'behavior',
events: [{type: 'event', name: 'issues', action: 'opened'}],
then: [{type: 'action', name: 'close'}]
}]);
});
@ -143,9 +143,9 @@ describe('parser', () => {
on issues # Ignore this
then close;
`)).toEqual([{
type: 'behavior',
events: [{type: 'event', name: 'issues'}],
then: [{type: 'action', name: 'close'}]
type: 'behavior',
events: [{type: 'event', name: 'issues'}],
then: [{type: 'action', name: 'close'}]
}]);
});
});