Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
facundocabrera committed Mar 22, 2016
1 parent 001fb8b commit c47c90d
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 128 deletions.
30 changes: 18 additions & 12 deletions packages/splitio-engine/es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const parser = require('./parser');

function Split(baseInfo, evaluator, segments) {
if (!(this instanceof Split)) {
return new Split(baseInfo, evaluator, segments);
return new Split(baseInfo, evaluator, segments);
}

this.baseInfo = baseInfo;
Expand All @@ -15,32 +15,38 @@ Split.parse = function parse(splitFlatStructure, storage) {
let {evaluator, segments} = parser(conditions, storage);

return new Split(baseInfo, evaluator, segments);
}
};

Split.prototype.getKey = function getKey() {
return this.baseInfo.name;
};

Split.prototype.getSegments = function getSegments() {
return this.segments;
}
};

Split.prototype.getTreatment = function getTreatment(key, attributes) {
if (this.baseInfo.killed) {
return this.baseInfo.defaultTreatment;
let {
killed,
seed,
defaultTreatment
} = this.baseInfo;

if (killed) {
return defaultTreatment;
} else {
let treatment = this.evaluator(key, seed, attributes);

return treatment !== undefined ? treatment : defaultTreatment;
}

let treatment = this.evaluator(key, this.baseInfo.seed, attributes);

return treatment !== undefined ? treatment : this.baseInfo.defaultTreatment;
}
};

Split.prototype.isTreatment = function isTreatment(key, treatment) {
return this.getTreatment(key) === treatment;
}
};

Split.prototype.isGarbage = function isGarbage() {
return this.baseInfo.status === 'ARCHIVED';
}
};

module.exports = Split;
2 changes: 1 addition & 1 deletion packages/splitio-engine/es6/matchers/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
return this.enum.GREATER_THAN_OR_EQUAL_TO;
case 'LESS_THAN_OR_EQUAL_TO':
return this.enum.LESS_THAN_OR_EQUAL_TO;
case 'BETWEEN': Symbol()
case 'BETWEEN':
return this.enum.BETWEEN;
default:
throw new Error('Invalid matcher type provided');
Expand Down
1 change: 0 additions & 1 deletion packages/splitio-engine/es6/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function parse(conditions /*: Iterable<Object> */, storage /*: Storage */) /*: P
for (let condition of conditions) {
let {
matcherGroup: {
combiner,
matchers
},
partitions
Expand Down
2 changes: 1 addition & 1 deletion packages/splitio-engine/es6/transforms/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function transform(matchers /*: Array<object> */) /*: Array<MatcherDTO> */ {
userDefinedSegmentMatcherData: segmentObject /*: segmentObject */,
whitelistMatcherData: whitelistObject /*: whiteListObject */,
unaryNumericMatcherData: unaryNumericObject /*: unaryNumericObject */,
betweenMatcherData: betweenObject /*: betweenObject */,
betweenMatcherData: betweenObject /*: betweenObject */
} = matcher;

let attribute = keySelector && keySelector.attribute;
Expand Down
222 changes: 111 additions & 111 deletions packages/splitio-engine/test/es6/parser/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,31 @@ tape('PARSER / if user is in segment ["u1", "u2", "u3", "u4"] then split 100%:on

tape('PARSER / if user.account is in list ["v1", "v2", "v3"] then split 100:on', assert => {

let {evaluator, segments} = parser([{
"matcherGroup": {
"combiner": "AND",
"matchers": [{
"keySelector": {
"trafficType": "user",
"attribute": "account"
let {evaluator} = parser([{
matcherGroup: {
combiner: 'AND',
matchers: [{
keySelector: {
trafficType: 'user',
attribute: 'account'
},
"matcherType": "WHITELIST",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": {
"whitelist": [
"v1",
"v2",
"v3"
matcherType: 'WHITELIST',
negate: false,
userDefinedSegmentMatcherData: null,
whitelistMatcherData: {
whitelist: [
'v1',
'v2',
'v3'
]
},
"unaryNumericMatcherData": null,
"betweenMatcherData": null
unaryNumericMatcherData: null,
betweenMatcherData: null
}]
},
"partitions": [{
"treatment": "on",
"size": 100
partitions: [{
treatment: 'on',
size: 100
}]
}]);

Expand All @@ -147,26 +147,26 @@ tape('PARSER / if user.account is in list ["v1", "v2", "v3"] then split 100:on',

tape('PARSER / if user.account is in segment all then split 100:on', assert => {

let {evaluator, segments} = parser([{
"matcherGroup": {
"combiner": "AND",
"matchers": [{
"keySelector": {
"trafficType": "user",
"attribute": "account"
let {evaluator} = parser([{
matcherGroup: {
combiner: 'AND',
matchers: [{
keySelector: {
trafficType: 'user',
attribute: 'account'
},
"matcherType": "ALL_KEYS",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null,
"unaryNumericMatcherData": null,
"betweenMatcherData": null,
"unaryStringMatcherData": null
matcherType: 'ALL_KEYS',
negate: false,
userDefinedSegmentMatcherData: null,
whitelistMatcherData: null,
unaryNumericMatcherData: null,
betweenMatcherData: null,
unaryStringMatcherData: null
}]
},
"partitions": [{
"treatment": "on",
"size": 100
partitions: [{
treatment: 'on',
size: 100
}]
}]);

Expand All @@ -176,37 +176,37 @@ tape('PARSER / if user.account is in segment all then split 100:on', assert => {

assert.true(
evaluator('[email protected]', 31) === undefined,
"missing attribute account but using segment all evaluates to on"
'missing attribute should evaluates to undefined'
);

assert.end();
});

tape('PARSER / if user.attr is between 10 and 20 then split 100:on', assert => {

let {evaluator, segments} = parser([{
"matcherGroup": {
"combiner": "AND",
"matchers": [{
"keySelector": {
"trafficType": "user",
"attribute": "attr"
let {evaluator} = parser([{
matcherGroup: {
combiner: 'AND',
matchers: [{
keySelector: {
trafficType: 'user',
attribute: 'attr'
},
"matcherType": "BETWEEN",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null,
"unaryNumericMatcherData": null,
"betweenMatcherData": {
"dataType": "NUMBER",
"start": 10,
"end": 20
matcherType: 'BETWEEN',
negate: false,
userDefinedSegmentMatcherData: null,
whitelistMatcherData: null,
unaryNumericMatcherData: null,
betweenMatcherData: {
dataType: 'NUMBER',
start: 10,
end: 20
}
}]
},
"partitions": [{
"treatment": "on",
"size": 100
partitions: [{
treatment: 'on',
size: 100
}]
}]);

Expand All @@ -228,28 +228,28 @@ tape('PARSER / if user.attr is between 10 and 20 then split 100:on', assert => {

tape('PARSER / if user.attr <= datetime 1458240947021 then split 100:on', assert => {

let {evaluator, segments} = parser([{
"matcherGroup": {
"combiner": "AND",
"matchers": [{
"keySelector": {
"trafficType": "user",
"attribute": "attr"
let {evaluator} = parser([{
matcherGroup: {
combiner: 'AND',
matchers: [{
keySelector: {
trafficType: 'user',
attribute: 'attr'
},
"matcherType": "LESS_THAN_OR_EQUAL_TO",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null,
"unaryNumericMatcherData": {
"dataType": "DATETIME",
"value": 1458240947021
matcherType: 'LESS_THAN_OR_EQUAL_TO',
negate: false,
userDefinedSegmentMatcherData: null,
whitelistMatcherData: null,
unaryNumericMatcherData: {
dataType: 'DATETIME',
value: 1458240947021
},
"betweenMatcherData": null
betweenMatcherData: null
}]
},
"partitions": [{
"treatment": "on",
"size": 100
partitions: [{
treatment: 'on',
size: 100
}]
}]);

Expand All @@ -275,28 +275,28 @@ tape('PARSER / if user.attr <= datetime 1458240947021 then split 100:on', assert

tape('PARSER / if user.attr >= datetime 1458240947021 then split 100:on', assert => {

let {evaluator, segments} = parser([{
"matcherGroup": {
"combiner": "AND",
"matchers": [{
"keySelector": {
"trafficType": "user",
"attribute": "attr"
let {evaluator} = parser([{
matcherGroup: {
combiner: 'AND',
matchers: [{
keySelector: {
trafficType: 'user',
attribute: 'attr'
},
"matcherType": "GREATER_THAN_OR_EQUAL_TO",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null,
"unaryNumericMatcherData": {
"dataType": "DATETIME",
"value": 1458240947021
matcherType: 'GREATER_THAN_OR_EQUAL_TO',
negate: false,
userDefinedSegmentMatcherData: null,
whitelistMatcherData: null,
unaryNumericMatcherData: {
dataType: 'DATETIME',
value: 1458240947021
},
"betweenMatcherData": null
betweenMatcherData: null
}]
},
"partitions": [{
"treatment": "on",
"size": 100
partitions: [{
treatment: 'on',
size: 100
}]
}]);

Expand All @@ -322,28 +322,28 @@ tape('PARSER / if user.attr >= datetime 1458240947021 then split 100:on', assert

tape('PARSER / if user.attr = datetime 1458240947021 then split 100:on', assert => {

let {evaluator, segments} = parser([{
"matcherGroup": {
"combiner": "AND",
"matchers": [{
"keySelector": {
"trafficType": "user",
"attribute": "attr"
let {evaluator} = parser([{
matcherGroup: {
combiner: 'AND',
matchers: [{
keySelector: {
trafficType: 'user',
attribute: 'attr'
},
"matcherType": "EQUAL_TO",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null,
"unaryNumericMatcherData": {
"dataType": "DATETIME",
"value": 1458240947021
matcherType: 'EQUAL_TO',
negate: false,
userDefinedSegmentMatcherData: null,
whitelistMatcherData: null,
unaryNumericMatcherData: {
dataType: 'DATETIME',
value: 1458240947021
},
"betweenMatcherData": null
betweenMatcherData: null
}]
},
"partitions": [{
"treatment": "on",
"size": 100
partitions: [{
treatment: 'on',
size: 100
}]
}]);

Expand Down
2 changes: 1 addition & 1 deletion packages/splitio-utils/es6/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function defaults(custom /*: Settings */) /*: Settings */ {
featuresRefreshRate: 30, // 30 sec
segmentsRefreshRate: 60, // 60 sec
metricsRefreshRate: 60, // 60 sec
impressionsRefreshRate: 60, // 60 sec
impressionsRefreshRate: 60 // 60 sec
}
};

Expand Down
5 changes: 4 additions & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@

# Verify our code is good enough for machines at least.

eslint packages/*/es6/**/*.js \

eslint packages/*/es6/*.js \
packages/*/es6/**/*.js \
packages/*/test/es6/*.js \
packages/*/test/es6/**/*.js

0 comments on commit c47c90d

Please sign in to comment.