Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit caf36ae

Browse files
author
Derek Hammond
authored
refactor(core): Run Prettier on packages/optimizely-sdk (optimizely#420)
## Summary - [x] Run `prettier --write "**/*.js"` in `packages/optimizely-sdk` - [x] Run `prettier --write "**/*.ts"` in `packages/optimizely-sdk` Per the [convo in Slack](https://optimizely.slack.com/archives/C2F8YUGHL/p1583254191037200), we thought it would be a good idea to run Prettier on the entire `optimizely-sdk` directory. Going forward, prettier will automatically run if the users IDE has the editorConfig setup as such. For VS Code, I personally like to add the `"editor.formatOnSave": true,` to my `settings.json`. ## Test plan - Ensure tests pass
1 parent 6e00881 commit caf36ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3793
-2811
lines changed

packages/optimizely-sdk/karma.base.conf.js

+12-18
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
//browserStack setup
3030
browserStack: {
3131
username: process.env.BROWSER_STACK_USERNAME,
32-
accessKey: process.env.BROWSER_STACK_ACCESS_KEY
32+
accessKey: process.env.BROWSER_STACK_ACCESS_KEY,
3333
},
3434

3535
// to avoid DISCONNECTED messages when connecting to BrowserStack
@@ -45,46 +45,46 @@ module.exports = {
4545
browser: 'chrome',
4646
browser_version: '21.0',
4747
os: 'OS X',
48-
os_version: 'Mountain Lion'
48+
os_version: 'Mountain Lion',
4949
},
5050
bs_edge: {
5151
base: 'BrowserStack',
5252
os: 'Windows',
5353
os_version: '10',
5454
browser: 'edge',
5555
device: null,
56-
browser_version: '15.0'
56+
browser_version: '15.0',
5757
},
5858
bs_firefox_mac: {
5959
base: 'BrowserStack',
6060
browser: 'firefox',
6161
browser_version: '21.0',
6262
os: 'OS X',
63-
os_version: 'Mountain Lion'
63+
os_version: 'Mountain Lion',
6464
},
6565
bs_ie: {
6666
base: 'BrowserStack',
6767
os: 'Windows',
6868
os_version: '7',
6969
browser: 'ie',
7070
device: null,
71-
browser_version: '10.0'
71+
browser_version: '10.0',
7272
},
7373
bs_opera_mac: {
7474
base: 'BrowserStack',
7575
browser: 'opera',
7676
browser_version: '37',
7777
os: 'OS X',
78-
os_version: 'Mountain Lion'
78+
os_version: 'Mountain Lion',
7979
},
8080
bs_safari: {
8181
base: 'BrowserStack',
8282
os: 'OS X',
8383
os_version: 'Mountain Lion',
8484
browser: 'safari',
8585
device: null,
86-
browser_version: '6.2'
87-
}
86+
browser_version: '6.2',
87+
},
8888
},
8989

9090
browsers: ['bs_chrome_mac', 'bs_edge', 'bs_firefox_mac', 'bs_ie', 'bs_opera_mac', 'bs_safari'],
@@ -94,31 +94,25 @@ module.exports = {
9494
frameworks: ['mocha'],
9595

9696
// list of files to exclude
97-
exclude: [
98-
],
99-
97+
exclude: [],
10098

10199
// preprocess matching files before serving them to the browser
102100
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
103101
preprocessors: {
104-
'./lib/**/*tests.js': ['webpack']
102+
'./lib/**/*tests.js': ['webpack'],
105103
},
106104

107-
108105
// test results reporter to use
109106
// possible values: 'dots', 'progress'
110107
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
111108
reporters: ['progress'],
112109

113-
114110
// web server port
115111
port: 9876,
116112

117-
118113
// enable / disable colors in the output (reporters and logs)
119114
colors: true,
120115

121-
122116
// enable / disable watching file and executing tests whenever any file changes
123117
autoWatch: false,
124118

@@ -128,5 +122,5 @@ module.exports = {
128122

129123
// Concurrency level
130124
// how many browser should be started simultaneous
131-
concurrency: Infinity
132-
}
125+
concurrency: Infinity,
126+
};

packages/optimizely-sdk/karma.bs.conf.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
// Karma configuration for cross-browser testing
18-
const baseConfig = require('./karma.base.conf.js')
18+
const baseConfig = require('./karma.base.conf.js');
1919

2020
module.exports = function(config) {
2121
config.set({
@@ -26,8 +26,6 @@ module.exports = function(config) {
2626
logLevel: config.LOG_INFO,
2727

2828
// list of files / patterns to load in the browser
29-
files: [
30-
'./lib/index.browser.tests.js'
31-
],
29+
files: ['./lib/index.browser.tests.js'],
3230
});
3331
};

packages/optimizely-sdk/karma.umd.conf.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
// Karma configuration for UMD bundle testing
18-
const baseConfig = require('./karma.base.conf.js')
18+
const baseConfig = require('./karma.base.conf.js');
1919

2020
module.exports = function(config) {
2121
config.set({
@@ -26,9 +26,6 @@ module.exports = function(config) {
2626
logLevel: config.LOG_INFO,
2727

2828
// list of files / patterns to load in the browser
29-
files: [
30-
'./dist/optimizely.browser.umd.min.js',
31-
'./lib/index.browser.umdtests.js'
32-
],
29+
files: ['./dist/optimizely.browser.umd.min.js', './lib/index.browser.umdtests.js'],
3330
});
3431
};

packages/optimizely-sdk/lib/core/audience_evaluator/index.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var LOG_LEVEL = enums.LOG_LEVEL;
2626
var LOG_MESSAGES = enums.LOG_MESSAGES;
2727
var MODULE_NAME = 'AUDIENCE_EVALUATOR';
2828

29-
3029
/**
3130
* Construct an instance of AudienceEvaluator with given options
3231
* @param {Object=} UNSTABLE_conditionEvaluators A map of condition evaluators provided by the consumer. This enables matching
@@ -36,7 +35,7 @@ var MODULE_NAME = 'AUDIENCE_EVALUATOR';
3635
*/
3736
function AudienceEvaluator(UNSTABLE_conditionEvaluators) {
3837
this.typeToEvaluatorMap = fns.assign({}, UNSTABLE_conditionEvaluators, {
39-
'custom_attribute': customAttributeConditionEvaluator
38+
custom_attribute: customAttributeConditionEvaluator,
4039
});
4140
}
4241

@@ -66,8 +65,14 @@ AudienceEvaluator.prototype.evaluate = function(audienceConditions, audiencesByI
6665
var evaluateAudience = function(audienceId) {
6766
var audience = audiencesById[audienceId];
6867
if (audience) {
69-
logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.EVALUATING_AUDIENCE, MODULE_NAME, audienceId, JSON.stringify(audience.conditions)));
70-
var result = conditionTreeEvaluator.evaluate(audience.conditions, this.evaluateConditionWithUserAttributes.bind(this, userAttributes));
68+
logger.log(
69+
LOG_LEVEL.DEBUG,
70+
sprintf(LOG_MESSAGES.EVALUATING_AUDIENCE, MODULE_NAME, audienceId, JSON.stringify(audience.conditions))
71+
);
72+
var result = conditionTreeEvaluator.evaluate(
73+
audience.conditions,
74+
this.evaluateConditionWithUserAttributes.bind(this, userAttributes)
75+
);
7176
var resultText = result === null ? 'UNKNOWN' : result.toString().toUpperCase();
7277
logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.AUDIENCE_EVALUATION_RESULT, MODULE_NAME, audienceId, resultText));
7378
return result;
@@ -95,7 +100,10 @@ AudienceEvaluator.prototype.evaluateConditionWithUserAttributes = function(userA
95100
try {
96101
return evaluator.evaluate(condition, userAttributes, logger);
97102
} catch (err) {
98-
logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message));
103+
logger.log(
104+
LOG_LEVEL.ERROR,
105+
sprintf(ERROR_MESSAGES.CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message)
106+
);
99107
}
100108
return null;
101109
};

0 commit comments

Comments
 (0)