Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 54d2011

Browse files
authored
Merge pull request #89 from fathyb/chore/add-prettier
Add prettier + eslint
2 parents 64c5df9 + fdd5008 commit 54d2011

21 files changed

+1811
-227
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
test:
44
docker:
5-
- image: circleci/node:4-browsers
5+
- image: circleci/node:8-browsers
66
steps:
77
- checkout
88
- run: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
@@ -18,7 +18,7 @@ jobs:
1818
path: junit-reports
1919
publish:
2020
docker:
21-
- image: circleci/node:4-browsers
21+
- image: circleci/node:8-browsers
2222
steps:
2323
- checkout
2424
- attach_workspace: { at: . }

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": "@segment/eslint-config/browser/legacy"
2+
"extends": ["@segment/eslint-config/browser/legacy", "prettier"]
33
}

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Binaries
33
##
44

5-
ESLINT := node_modules/.bin/eslint
65
KARMA := node_modules/.bin/karma
76

87
##
@@ -58,12 +57,13 @@ distclean: clean
5857

5958
# Lint JavaScript source files.
6059
lint: install
61-
@$(ESLINT) $(ALL_FILES)
60+
yarn lint
61+
6262
.PHONY: lint
6363

6464
# Attempt to fix linting errors.
6565
fmt: install
66-
@$(ESLINT) --fix $(ALL_FILES)
66+
yarn format
6767
.PHONY: fmt
6868

6969
# Run browser unit tests in a browser.

lib/analytics.js

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ Analytics.prototype.addIntegration = function(Integration) {
102102
* @return {Analytics}
103103
*/
104104

105-
Analytics.prototype.init = Analytics.prototype.initialize = function(settings, options) {
105+
Analytics.prototype.init = Analytics.prototype.initialize = function(
106+
settings,
107+
options
108+
) {
106109
settings = settings || {};
107110
options = options || {};
108111

@@ -121,8 +124,8 @@ Analytics.prototype.init = Analytics.prototype.initialize = function(settings, o
121124
// Don't load disabled integrations
122125
if (options.integrations) {
123126
if (
124-
options.integrations[name] === false
125-
|| options.integrations.All === false && !options.integrations[name]
127+
options.integrations[name] === false ||
128+
(options.integrations.All === false && !options.integrations[name])
126129
) {
127130
return;
128131
}
@@ -158,7 +161,10 @@ Analytics.prototype.init = Analytics.prototype.initialize = function(settings, o
158161
// create a list of any integrations that did not initialize - this will be passed with all events for replay support:
159162
this.failedInitializations = [];
160163
each(function(integration) {
161-
if (options.initialPageview && integration.options.initialPageview === false) {
164+
if (
165+
options.initialPageview &&
166+
integration.options.initialPageview === false
167+
) {
162168
integration.page = after(2, integration.page);
163169
}
164170

@@ -226,9 +232,9 @@ Analytics.prototype.add = function(integration) {
226232
Analytics.prototype.identify = function(id, traits, options, fn) {
227233
// Argument reshuffling.
228234
/* eslint-disable no-unused-expressions, no-sequences */
229-
if (is.fn(options)) fn = options, options = null;
230-
if (is.fn(traits)) fn = traits, options = null, traits = null;
231-
if (is.object(id)) options = traits, traits = id, id = user.id();
235+
if (is.fn(options)) (fn = options), (options = null);
236+
if (is.fn(traits)) (fn = traits), (options = null), (traits = null);
237+
if (is.object(id)) (options = traits), (traits = id), (id = user.id());
232238
/* eslint-enable no-unused-expressions, no-sequences */
233239

234240
// clone traits before we manipulate so we don't do anything uncouth, and take
@@ -278,12 +284,11 @@ Analytics.prototype.user = function() {
278284
Analytics.prototype.group = function(id, traits, options, fn) {
279285
/* eslint-disable no-unused-expressions, no-sequences */
280286
if (!arguments.length) return group;
281-
if (is.fn(options)) fn = options, options = null;
282-
if (is.fn(traits)) fn = traits, options = null, traits = null;
283-
if (is.object(id)) options = traits, traits = id, id = group.id();
287+
if (is.fn(options)) (fn = options), (options = null);
288+
if (is.fn(traits)) (fn = traits), (options = null), (traits = null);
289+
if (is.object(id)) (options = traits), (traits = id), (id = group.id());
284290
/* eslint-enable no-unused-expressions, no-sequences */
285291

286-
287292
// grab from group again to make sure we're taking from the source
288293
group.identify(id, traits);
289294

@@ -318,8 +323,9 @@ Analytics.prototype.group = function(id, traits, options, fn) {
318323
Analytics.prototype.track = function(event, properties, options, fn) {
319324
// Argument reshuffling.
320325
/* eslint-disable no-unused-expressions, no-sequences */
321-
if (is.fn(options)) fn = options, options = null;
322-
if (is.fn(properties)) fn = properties, options = null, properties = null;
326+
if (is.fn(options)) (fn = options), (options = null);
327+
if (is.fn(properties))
328+
(fn = properties), (options = null), (properties = null);
323329
/* eslint-enable no-unused-expressions, no-sequences */
324330

325331
// figure out if the event is archived.
@@ -353,7 +359,10 @@ Analytics.prototype.track = function(event, properties, options, fn) {
353359
}
354360

355361
// Add the initialize integrations so the server-side ones can be disabled too
356-
defaults(msg.integrations, this._mergeInitializeAndPlanIntegrations(planIntegrationOptions));
362+
defaults(
363+
msg.integrations,
364+
this._mergeInitializeAndPlanIntegrations(planIntegrationOptions)
365+
);
357366

358367
this._invoke('track', new Track(msg));
359368

@@ -374,7 +383,11 @@ Analytics.prototype.track = function(event, properties, options, fn) {
374383
* @return {Analytics}
375384
*/
376385

377-
Analytics.prototype.trackClick = Analytics.prototype.trackLink = function(links, event, properties) {
386+
Analytics.prototype.trackClick = Analytics.prototype.trackLink = function(
387+
links,
388+
event,
389+
properties
390+
) {
378391
if (!links) return this;
379392
// always arrays, handles jquery
380393
if (type(links) === 'element') links = [links];
@@ -387,9 +400,10 @@ Analytics.prototype.trackClick = Analytics.prototype.trackLink = function(links,
387400
on(el, 'click', function(e) {
388401
var ev = is.fn(event) ? event(el) : event;
389402
var props = is.fn(properties) ? properties(el) : properties;
390-
var href = el.getAttribute('href')
391-
|| el.getAttributeNS('http://www.w3.org/1999/xlink', 'href')
392-
|| el.getAttribute('xlink:href');
403+
var href =
404+
el.getAttribute('href') ||
405+
el.getAttributeNS('http://www.w3.org/1999/xlink', 'href') ||
406+
el.getAttribute('xlink:href');
393407

394408
self.track(ev, props);
395409

@@ -417,14 +431,19 @@ Analytics.prototype.trackClick = Analytics.prototype.trackLink = function(links,
417431
* @return {Analytics}
418432
*/
419433

420-
Analytics.prototype.trackSubmit = Analytics.prototype.trackForm = function(forms, event, properties) {
434+
Analytics.prototype.trackSubmit = Analytics.prototype.trackForm = function(
435+
forms,
436+
event,
437+
properties
438+
) {
421439
if (!forms) return this;
422440
// always arrays, handles jquery
423441
if (type(forms) === 'element') forms = [forms];
424442

425443
var self = this;
426444
each(function(el) {
427-
if (type(el) !== 'element') throw new TypeError('Must pass HTMLElement to `analytics.trackForm`.');
445+
if (type(el) !== 'element')
446+
throw new TypeError('Must pass HTMLElement to `analytics.trackForm`.');
428447
function handler(e) {
429448
prevent(e);
430449

@@ -465,12 +484,15 @@ Analytics.prototype.trackSubmit = Analytics.prototype.trackForm = function(forms
465484
Analytics.prototype.page = function(category, name, properties, options, fn) {
466485
// Argument reshuffling.
467486
/* eslint-disable no-unused-expressions, no-sequences */
468-
if (is.fn(options)) fn = options, options = null;
469-
if (is.fn(properties)) fn = properties, options = properties = null;
470-
if (is.fn(name)) fn = name, options = properties = name = null;
471-
if (type(category) === 'object') options = name, properties = category, name = category = null;
472-
if (type(name) === 'object') options = properties, properties = name, name = null;
473-
if (type(category) === 'string' && type(name) !== 'string') name = category, category = null;
487+
if (is.fn(options)) (fn = options), (options = null);
488+
if (is.fn(properties)) (fn = properties), (options = properties = null);
489+
if (is.fn(name)) (fn = name), (options = properties = name = null);
490+
if (type(category) === 'object')
491+
(options = name), (properties = category), (name = category = null);
492+
if (type(name) === 'object')
493+
(options = properties), (properties = name), (name = null);
494+
if (type(category) === 'string' && type(name) !== 'string')
495+
(name = category), (category = null);
474496
/* eslint-enable no-unused-expressions, no-sequences */
475497

476498
properties = clone(properties) || {};
@@ -539,9 +561,9 @@ Analytics.prototype.pageview = function(url) {
539561
Analytics.prototype.alias = function(to, from, options, fn) {
540562
// Argument reshuffling.
541563
/* eslint-disable no-unused-expressions, no-sequences */
542-
if (is.fn(options)) fn = options, options = null;
543-
if (is.fn(from)) fn = from, options = null, from = null;
544-
if (is.object(from)) options = from, from = null;
564+
if (is.fn(options)) (fn = options), (options = null);
565+
if (is.fn(from)) (fn = from), (options = null), (from = null);
566+
if (is.object(from)) (options = from), (from = null);
545567
/* eslint-enable no-unused-expressions, no-sequences */
546568

547569
var msg = this.normalize({
@@ -660,7 +682,11 @@ Analytics.prototype._invoke = function(method, facade) {
660682
// Check if an integration failed to initialize.
661683
// If so, do not process the message as the integration is in an unstable state.
662684
if (failedInitializations.indexOf(name) >= 0) {
663-
self.log('Skipping invokation of .%s method of %s integration. Integation failed to initialize properly.', method, name);
685+
self.log(
686+
'Skipping invokation of .%s method of %s integration. Integation failed to initialize properly.',
687+
method,
688+
name
689+
);
664690
} else {
665691
try {
666692
metrics.increment('analytics_js.integration.invoke', {
@@ -673,7 +699,12 @@ Analytics.prototype._invoke = function(method, facade) {
673699
method: method,
674700
integration_name: integration.name
675701
});
676-
self.log('Error invoking .%s method of %s integration: %o', method, name, e);
702+
self.log(
703+
'Error invoking .%s method of %s integration: %o',
704+
method,
705+
name,
706+
e
707+
);
677708
}
678709
}
679710
}, this._integrations);
@@ -738,13 +769,17 @@ Analytics.prototype._parseQuery = function(query) {
738769
function pickPrefix(prefix, object) {
739770
var length = prefix.length;
740771
var sub;
741-
return foldl(function(acc, val, key) {
742-
if (key.substr(0, length) === prefix) {
743-
sub = key.substr(length);
744-
acc[sub] = val;
745-
}
746-
return acc;
747-
}, {}, object);
772+
return foldl(
773+
function(acc, val, key) {
774+
if (key.substr(0, length) === prefix) {
775+
sub = key.substr(length);
776+
acc[sub] = val;
777+
}
778+
return acc;
779+
},
780+
{},
781+
object
782+
);
748783
}
749784
};
750785

@@ -772,7 +807,9 @@ Analytics.prototype.normalize = function(msg) {
772807
* @param {Object} planIntegrations Tracking plan integrations.
773808
* @return {Object} The merged integrations.
774809
*/
775-
Analytics.prototype._mergeInitializeAndPlanIntegrations = function(planIntegrations) {
810+
Analytics.prototype._mergeInitializeAndPlanIntegrations = function(
811+
planIntegrations
812+
) {
776813
// Do nothing if there are no initialization integrations
777814
if (!this.options.integrations) {
778815
return planIntegrations;

lib/cookie.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function Cookie(options) {
2222
this.options(options);
2323
}
2424

25-
2625
/**
2726
* Get or set the cookie options.
2827
*
@@ -63,7 +62,6 @@ Cookie.prototype.options = function(options) {
6362
this.remove('ajs:test');
6463
};
6564

66-
6765
/**
6866
* Set a `key` and `value` in our cookie.
6967
*
@@ -82,7 +80,6 @@ Cookie.prototype.set = function(key, value) {
8280
}
8381
};
8482

85-
8683
/**
8784
* Get a value from our cookie by `key`.
8885
*
@@ -100,7 +97,6 @@ Cookie.prototype.get = function(key) {
10097
}
10198
};
10299

103-
104100
/**
105101
* Remove a value from our cookie by `key`.
106102
*
@@ -117,14 +113,12 @@ Cookie.prototype.remove = function(key) {
117113
}
118114
};
119115

120-
121116
/**
122117
* Expose the cookie singleton.
123118
*/
124119

125120
module.exports = bindAll(new Cookie());
126121

127-
128122
/**
129123
* Expose the `Cookie` constructor.
130124
*/

0 commit comments

Comments
 (0)