Skip to content

Commit b471b30

Browse files
committed
Add full support for es6
Converts the tool chain to use babel, eslint, and webpack vs. the previous proprietary solutions. Additionally begins enforcing additional linting concerns as well as updates the code to reflect these rules. Fixes #855 Fixes #933
1 parent 2a02261 commit b471b30

Some content is hidden

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

51 files changed

+1789
-1542
lines changed

.eslintrc

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
{
2+
"globals": {
3+
"self": false
4+
},
5+
"env": {
6+
"node": true
7+
},
8+
"ecmaFeatures": {
9+
"modules": true
10+
},
11+
"rules": {
12+
// Possible Errors //
13+
//-----------------//
14+
15+
"comma-dangle": [2, "never"],
16+
"no-cond-assign": [2, "except-parens"],
17+
18+
// Allow for debugging
19+
"no-console": 1,
20+
21+
"no-constant-condition": 2,
22+
"no-control-regex": 2,
23+
24+
// Allow for debugging
25+
"no-debugger": 1,
26+
27+
"no-dupe-args": 2,
28+
"no-dupe-keys": 2,
29+
"no-duplicate-case": 2,
30+
"no-empty": 2,
31+
"no-empty-class": 2,
32+
"no-ex-assign": 2,
33+
"no-extra-boolean-cast": 2,
34+
"no-extra-parens": 0,
35+
"no-extra-semi": 2,
36+
"no-func-assign": 2,
37+
38+
// Stylistic... might consider disallowing in the future
39+
"no-inner-declarations": 0,
40+
41+
"no-invalid-regexp": 2,
42+
"no-irregular-whitespace": 2,
43+
"no-negated-in-lhs": 2,
44+
"no-obj-calls": 2,
45+
"no-regex-spaces": 2,
46+
"no-reserved-keys": 2, // Important for IE
47+
"no-sparse-arrays": 0,
48+
49+
// Optimizer and coverage will handle/highlight this and can be useful for debugging
50+
"no-unreachable": 1,
51+
52+
"use-isnan": 2,
53+
"valid-jsdoc": 0,
54+
"valid-typeof": 2,
55+
56+
57+
// Best Practices //
58+
//----------------//
59+
"block-scoped-var": 0,
60+
"complexity": 0,
61+
"consistent-return": 0,
62+
"curly": 2,
63+
"default-case": 1,
64+
"dot-notation": [2, {"allowKeywords": false}],
65+
"eqeqeq": 0,
66+
"guard-for-in": 1,
67+
"no-alert": 2,
68+
"no-caller": 2,
69+
"no-div-regex": 1,
70+
"no-else-return": 0,
71+
"no-empty-label": 2,
72+
"no-eq-null": 0,
73+
"no-eval": 2,
74+
"no-extend-native": 2,
75+
"no-extra-bind": 2,
76+
"no-fallthrough": 2,
77+
"no-floating-decimal": 2,
78+
"no-implied-eval": 2,
79+
"no-iterator": 2,
80+
"no-labels": 2,
81+
"no-lone-blocks": 2,
82+
"no-loop-func": 2,
83+
"no-multi-spaces": 2,
84+
"no-multi-str": 1,
85+
"no-native-reassign": 2,
86+
"no-new": 2,
87+
"no-new-func": 2,
88+
"no-new-wrappers": 2,
89+
"no-octal": 2,
90+
"no-octal-escape": 2,
91+
"no-param-reassign": 0,
92+
"no-process-env": 2,
93+
"no-proto": 2,
94+
"no-redeclare": 2,
95+
"no-return-assign": 2,
96+
"no-script-url": 2,
97+
"no-self-compare": 2,
98+
"no-sequences": 2,
99+
"no-throw-literal": 2,
100+
"no-unused-expressions": 2,
101+
"no-void": 0,
102+
"no-warning-comments": 1,
103+
"no-with": 2,
104+
"radix": 2,
105+
"vars-on-top": 0,
106+
"wrap-iife": 2,
107+
"yoda": 0,
108+
109+
110+
// Strict //
111+
//--------//
112+
"strict": 0,
113+
114+
115+
// Variables //
116+
//-----------//
117+
"no-catch-shadow": 2,
118+
"no-delete-var": 2,
119+
"no-label-var": 2,
120+
"no-shadow": 2,
121+
"no-shadow-restricted-names": 2,
122+
"no-undef": 2,
123+
"no-undef-init": 2,
124+
"no-undefined": 0,
125+
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
126+
"no-use-before-define": [2, "nofunc"],
127+
128+
129+
// Node.js //
130+
//---------//
131+
// Others left to environment defaults
132+
"no-mixed-requires": 0,
133+
134+
135+
// Stylistic //
136+
//-----------//
137+
"indent": 0,
138+
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
139+
"camelcase": 2,
140+
"comma-spacing": [2, {"before": false, "after": true}],
141+
"comma-style": [2, "last"],
142+
"consistent-this": [1, "self"],
143+
"eol-last": 2,
144+
"func-names": 0,
145+
"func-style": [2, "declaration"],
146+
"key-spacing": [2, {
147+
"beforeColon": false,
148+
"afterColon": true
149+
}],
150+
"max-nested-callbacks": 0,
151+
"new-cap": 2,
152+
"new-parens": 2,
153+
"newline-after-var": 0,
154+
"no-array-constructor": 2,
155+
"no-continue": 0,
156+
"no-inline-comments": 0,
157+
"no-lonely-if": 2,
158+
"no-mixed-spaces-and-tabs": 2,
159+
"no-multiple-empty-lines": 0,
160+
"no-nested-ternary": 1,
161+
"no-new-object": 2,
162+
"no-spaced-func": 2,
163+
"no-ternary": 0,
164+
"no-trailing-spaces": 2,
165+
"no-underscore-dangle": 0,
166+
"no-wrap-func": 2,
167+
"one-var": 0,
168+
"operator-assignment": 0,
169+
"padded-blocks": 0,
170+
"quote-props": 0,
171+
"quotes": [2, "single", "avoid-escape"],
172+
"semi": 2,
173+
"semi-spacing": [2, {"before": false, "after": true}],
174+
"sort-vars": 0,
175+
"space-after-keywords": [2, "always"],
176+
"space-before-blocks": [2, "always"],
177+
"space-before-function-paren": [2, {"anonymous": "never", "named": "never"}],
178+
"space-in-brackets": 0,
179+
"space-in-parens": [2, "never"],
180+
"space-infix-ops": 2,
181+
"space-return-throw-case": 2,
182+
"space-unary-ops": 2,
183+
"spaced-line-comment": 2,
184+
"wrap-regex": 1
185+
}
186+
}

Gruntfile.js

+62-37
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
var childProcess = require('child_process');
2-
1+
/*eslint-disable no-process-env */
32
module.exports = function(grunt) {
43

54
grunt.initConfig({
65
pkg: grunt.file.readJSON('package.json'),
76

8-
jshint: {
7+
eslint: {
98
options: {
10-
jshintrc: '.jshintrc'
119
},
1210
files: [
13-
'dist/cjs/**/!(*.min|parser).js'
11+
'*.js',
12+
'lib/**/!(*.min|parser).js',
13+
'spec/**/!(*.amd|json2|require).js'
1414
]
1515
},
1616

@@ -19,7 +19,7 @@ module.exports = function(grunt) {
1919
copy: {
2020
dist: {
2121
options: {
22-
processContent: function(content, path) {
22+
processContent: function(content) {
2323
return grunt.template.process('/*!\n\n <%= pkg.name %> v<%= pkg.version %>\n\n<%= grunt.file.read("LICENSE") %>\n@license\n*/\n')
2424
+ content;
2525
}
@@ -41,54 +41,78 @@ module.exports = function(grunt) {
4141
}
4242
},
4343

44-
packager: {
45-
global: {
46-
type: 'umd',
47-
export: 'Handlebars',
48-
files: [{
49-
cwd: 'lib/',
50-
expand: true,
51-
src: ['handlebars*.js'],
52-
dest: 'dist/'
53-
}]
44+
babel: {
45+
options: {
46+
loose: ['es6.modules']
5447
},
55-
5648
amd: {
57-
type: 'amd',
58-
anonymous: true,
49+
options: {
50+
modules: 'amd'
51+
},
5952
files: [{
6053
expand: true,
6154
cwd: 'lib/',
62-
src: '**/!(index).js',
55+
src: '**/!(index|precompiler).js',
6356
dest: 'dist/amd/'
6457
}]
6558
},
6659

6760
cjs: {
68-
type: 'cjs',
61+
options: {
62+
modules: 'common'
63+
},
6964
files: [{
70-
expand: true,
7165
cwd: 'lib/',
66+
expand: true,
7267
src: '**/!(index).js',
7368
dest: 'dist/cjs/'
7469
}]
7570
}
7671
},
72+
webpack: {
73+
options: {
74+
context: __dirname,
75+
module: {
76+
loaders: [
77+
// the optional 'runtime' transformer tells babel to require the runtime instead of inlining it.
78+
{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader?optional=runtime&loose=es6.modules' }
79+
]
80+
},
81+
output: {
82+
path: 'dist/',
83+
library: 'Handlebars',
84+
libraryType: 'umd'
85+
}
86+
},
87+
handlebars: {
88+
entry: './lib/handlebars.js',
89+
output: {
90+
filename: 'handlebars.js'
91+
}
92+
},
93+
runtime: {
94+
entry: './lib/handlebars.runtime.js',
95+
output: {
96+
filename: 'handlebars.runtime.js'
97+
}
98+
}
99+
},
100+
77101
requirejs: {
78102
options: {
79-
optimize: "none",
80-
baseUrl: "dist/amd/"
103+
optimize: 'none',
104+
baseUrl: 'dist/amd/'
81105
},
82106
dist: {
83107
options: {
84-
name: "handlebars",
85-
out: "dist/handlebars.amd.js"
108+
name: 'handlebars',
109+
out: 'dist/handlebars.amd.js'
86110
}
87111
},
88112
runtime: {
89113
options: {
90-
name: "handlebars.runtime",
91-
out: "dist/handlebars.runtime.amd.js"
114+
name: 'handlebars.runtime',
115+
out: 'dist/handlebars.runtime.amd.js'
92116
}
93117
}
94118
},
@@ -172,30 +196,31 @@ module.exports = function(grunt) {
172196
});
173197

174198
// Build a new version of the library
175-
this.registerTask('build', "Builds a distributable version of the current project", [
199+
this.registerTask('build', 'Builds a distributable version of the current project', [
200+
'eslint',
176201
'parser',
177202
'node',
178-
'globals',
179-
'jshint']);
203+
'globals']);
180204

181-
this.registerTask('amd', ['packager:amd', 'requirejs']);
182-
this.registerTask('node', ['packager:cjs']);
183-
this.registerTask('globals', ['packager:global']);
205+
this.registerTask('amd', ['babel:amd', 'requirejs']);
206+
this.registerTask('node', ['babel:cjs']);
207+
this.registerTask('globals', ['webpack']);
184208
this.registerTask('tests', ['concat:tests']);
185209

186-
this.registerTask('release', 'Build final packages', ['amd', 'jshint', 'uglify', 'copy:dist', 'copy:components', 'copy:cdnjs']);
210+
this.registerTask('release', 'Build final packages', ['eslint', 'amd', 'uglify', 'copy:dist', 'copy:components', 'copy:cdnjs']);
187211

188212
// Load tasks from npm
189213
grunt.loadNpmTasks('grunt-contrib-clean');
190214
grunt.loadNpmTasks('grunt-contrib-concat');
191215
grunt.loadNpmTasks('grunt-contrib-connect');
192216
grunt.loadNpmTasks('grunt-contrib-copy');
193217
grunt.loadNpmTasks('grunt-contrib-requirejs');
194-
grunt.loadNpmTasks('grunt-contrib-jshint');
195218
grunt.loadNpmTasks('grunt-contrib-uglify');
196219
grunt.loadNpmTasks('grunt-contrib-watch');
220+
grunt.loadNpmTasks('grunt-babel');
221+
grunt.loadNpmTasks('grunt-eslint');
197222
grunt.loadNpmTasks('grunt-saucelabs');
198-
grunt.loadNpmTasks('es6-module-packager');
223+
grunt.loadNpmTasks('grunt-webpack');
199224

200225
grunt.task.loadTasks('tasks');
201226

0 commit comments

Comments
 (0)