Skip to content

Commit f610d1e

Browse files
committed
Merge pull request #11 from amplitude/linting
Global linting. Snippet testing and automation.
2 parents 7c13f87 + 41dedff commit f610d1e

20 files changed

+405
-217
lines changed

.jshintrc

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
// JSHint Default Configuration File (as on JSHint website)
3+
// See http://jshint.com/docs/ for more details
4+
5+
"maxerr" : 50, // {int} Maximum error before stopping
6+
7+
// Enforcing
8+
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
9+
"camelcase" : false, // true: Identifiers must be in camelCase
10+
"curly" : true, // true: Require {} for every new block or scope
11+
"eqeqeq" : true, // true: Require triple equals (===) for comparison
12+
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
13+
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
14+
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
15+
"indent" : 2, // {int} Number of spaces to use for indentation
16+
"latedef" : false, // true: Require variables/functions to be defined before being used
17+
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
18+
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
19+
"noempty" : true, // true: Prohibit use of empty blocks
20+
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
21+
"nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment)
22+
"plusplus" : false, // true: Prohibit use of `++` & `--`
23+
"quotmark" : false, // Quotation mark consistency:
24+
// false : do nothing (default)
25+
// true : ensure whatever is used is consistent
26+
// "single" : require single quotes
27+
// "double" : require double quotes
28+
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
29+
"unused" : true, // true: Require all defined variables be used
30+
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
31+
"maxparams" : false, // {int} Max number of formal params allowed per function
32+
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
33+
"maxstatements" : false, // {int} Max number statements per function
34+
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
35+
"maxlen" : false, // {int} Max number of characters per line
36+
37+
// Relaxing
38+
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
39+
"boss" : false, // true: Tolerate assignments where comparisons would be expected
40+
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
41+
"eqnull" : false, // true: Tolerate use of `== null`
42+
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
43+
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
44+
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
45+
// (ex: `for each`, multiple try/catch, function expression…)
46+
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
47+
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
48+
"funcscope" : false, // true: Tolerate defining variables inside control statements
49+
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
50+
"iterator" : false, // true: Tolerate using the `__iterator__` property
51+
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
52+
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
53+
"laxcomma" : false, // true: Tolerate comma-first style coding
54+
"loopfunc" : false, // true: Tolerate functions being defined in loops
55+
"multistr" : false, // true: Tolerate multi-line strings
56+
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
57+
"notypeof" : false, // true: Tolerate invalid typeof operator values
58+
"proto" : false, // true: Tolerate using the `__proto__` property
59+
"scripturl" : false, // true: Tolerate script-targeted URLs
60+
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
61+
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
62+
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
63+
"validthis" : false, // true: Tolerate using this in a non-constructor function
64+
65+
// Environments
66+
"browser" : true, // Web Browser (window, document, etc)
67+
"browserify" : false, // Browserify (node.js code in the browser)
68+
"couch" : false, // CouchDB
69+
"devel" : true, // Development/debugging (alert, confirm, etc)
70+
"dojo" : false, // Dojo Toolkit
71+
"jasmine" : false, // Jasmine
72+
"jquery" : false, // jQuery
73+
"mocha" : true, // Mocha
74+
"mootools" : false, // MooTools
75+
"node" : true, // Node.js
76+
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
77+
"prototypejs" : false, // Prototype and Scriptaculous
78+
"qunit" : false, // QUnit
79+
"rhino" : false, // Rhino
80+
"shelljs" : false, // ShellJS
81+
"worker" : false, // Web Workers
82+
"wsh" : false, // Windows Scripting Host
83+
"yui" : false, // Yahoo User Interface
84+
85+
// Custom Globals
86+
"globals" : {} // additional predefined global variables
87+
}

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
SRC = $(wildcard src/*.js)
2+
SNIPPET = src/amplitude-snippet.js
23
TESTS = $(wildcard test/*.js)
34
BINS = node_modules/.bin
45
DUO = $(BINS)/duo
56
MINIFY = $(BINS)/uglifyjs
7+
JSHINT = $(BINS)/jshint
68
BUILD_DIR = build
79
PROJECT = amplitude
810
OUT = $(PROJECT).js
11+
SNIPPET_OUT = $(PROJECT)-snippet.min.js
912
MIN_OUT = $(PROJECT).min.js
1013
MOCHA = $(BINS)/mocha-phantomjs
1114

@@ -31,6 +34,7 @@ clean:
3134

3235
test: build test/browser/index.html
3336
@$(MOCHA) test/browser/index.html
37+
@$(MOCHA) test/browser/snippet.html
3438

3539

3640
#
@@ -46,28 +50,42 @@ node_modules: package.json
4650
version: component.json package.json src/version.js
4751
node scripts/version
4852

53+
#
54+
# Target for updating readme.
55+
56+
README.md: $(SNIPPET_OUT) version
57+
node scripts/readme
58+
4959
#
5060
# Target for `amplitude.js` file.
5161
#
5262

5363
$(OUT): node_modules $(SRC) version
64+
@$(JSHINT) --verbose $(SRC)
5465
@$(DUO) --standalone amplitude src/index.js > $(OUT)
5566
@$(MINIFY) $(OUT) --output $(MIN_OUT)
5667

68+
#
69+
# Target for minified `amplitude-snippet.js` file. Update README.
70+
#
71+
$(SNIPPET_OUT): $(SRC) $(SNIPPET) version
72+
@$(JSHINT) --verbose $(SNIPPET)
73+
@$(MINIFY) $(SNIPPET) -m -b max-line-len=80,beautify=false --output $(SNIPPET_OUT)
5774

5875
#
5976
# Target for `tests-build.js` file.
6077
#
6178

62-
build: $(TESTS) $(OUT)
79+
build: $(TESTS) $(OUT) $(SNIPPET_OUT) README.md
6380
@-mkdir -p build
6481
@$(DUO) --development test/tests.js > build/tests.js
82+
@$(DUO) --development test/snippet-tests.js > build/snippet-tests.js
6583

6684
#
6785
# Target for release.
6886
#
6987

70-
release: $(OUT)
88+
release: $(OUT) $(SNIPPET_OUT) README.md
7189
@-mkdir -p dist
7290
node scripts/release
7391

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ Amplitude-Javascript
88
2. On every page that uses analytics, paste the following Javascript code between the `<head>` and `</head>` tags:
99

1010
<script type="text/javascript">
11-
(function(h,a){var f=h.amplitude||{};var b=a.createElement("script");b.type="text/javascript";
12-
b.async=true;b.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.0.4-min.js";
13-
var g=a.getElementsByTagName("script")[0];g.parentNode.insertBefore(b,g);
14-
f._q=[];function e(i){f[i]=function(){f._q.push([i].concat(Array.prototype.slice.call(arguments,0)))}}
15-
var c=["init","logEvent","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId",
16-
"setGlobalUserProperties"];
17-
for(var d=0;d<c.length;d++){e(c[d])}h.amplitude=f})(window,document);
11+
(function(e,t){var r=e.amplitude||{};var n=t.createElement("script");n.type="text/javascript";
12+
n.async=true;n.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.0.4-min.js";
13+
var s=t.getElementsByTagName("script")[0];s.parentNode.insertBefore(n,s);r._q=[];
14+
function a(e){r[e]=function(){r._q.push([e].concat(Array.prototype.slice.call(arguments,0)))
15+
}}var i=["init","logEvent","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties"];
16+
for(var o=0;o<i.length;o++){a(i[o])}e.amplitude=r})(window,document);
1817

1918
amplitude.init("YOUR_API_KEY_HERE");
2019
</script>

amplitude-snippet.min.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(function(e,t){var r=e.amplitude||{};var n=t.createElement("script");n.type="text/javascript";
2+
n.async=true;n.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.0.4-min.js";
3+
var s=t.getElementsByTagName("script")[0];s.parentNode.insertBefore(n,s);r._q=[];
4+
function a(e){r[e]=function(){r._q.push([e].concat(Array.prototype.slice.call(arguments,0)))
5+
}}var i=["init","logEvent","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties"];
6+
for(var o=0;o<i.length;o++){a(i[o])}e.amplitude=r})(window,document);

0 commit comments

Comments
 (0)