Skip to content

Commit f121b53

Browse files
authored
Features/eslint (#2037)
Fixes #1913 * Drops node 4 * update node engine to >=6 (#2035) * syncs changes to spacing across different editorconfigs * adds eslint with minimally invasive configuration- basically moving from 4 to 2 spaces.
1 parent 2c8c4ea commit f121b53

12 files changed

+7370
-302
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ root = true
77
[*]
88
charset = utf-8
99
end_of_line = lf
10-
indent_size = 4
10+
indent_size = 2
1111
indent_style = space
1212
insert_final_newline = true
1313
trim_trailing_whitespace = true

.eslintrc.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es6": true,
5+
"mocha": true
6+
},
7+
"plugins": ["mocha"],
8+
"extends": "eslint:recommended",
9+
"parserOptions": {
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
"indent": [
14+
"error",
15+
2
16+
],
17+
"quotes": [
18+
"error",
19+
"single"
20+
],
21+
"semi": [
22+
"error",
23+
"always"
24+
]
25+
}
26+
};

.jshintrc

-32
This file was deleted.

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ git:
2525
language: node_js
2626

2727
node_js:
28-
- 4
2928
- 6
3029
- 8
3130
- 9

dist/.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44

55
[*]
66
charset = utf-8
7-
indent_size = 4
7+
indent_size = 2
88
indent_style = space
99
insert_final_newline = true
1010
trim_trailing_whitespace = true

dist/js/plugins.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
// Avoid `console` errors in browsers that lack a console.
22
(function() {
3-
var method;
4-
var noop = function () {};
5-
var methods = [
6-
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
7-
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
8-
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
9-
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
10-
];
11-
var length = methods.length;
12-
var console = (window.console = window.console || {});
3+
var method;
4+
var noop = function () {};
5+
var methods = [
6+
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
7+
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
8+
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
9+
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
10+
];
11+
var length = methods.length;
12+
var console = (window.console = window.console || {});
1313

14-
while (length--) {
15-
method = methods[length];
14+
while (length--) {
15+
method = methods[length];
1616

17-
// Only stub undefined methods.
18-
if (!console[method]) {
19-
console[method] = noop;
20-
}
17+
// Only stub undefined methods.
18+
if (!console[method]) {
19+
console[method] = noop;
2120
}
21+
}
2222
}());
2323

2424
// Place any jQuery/helper plugins in here.

gulpfile.babel.js

+96-97
Original file line numberDiff line numberDiff line change
@@ -28,149 +28,148 @@ const dirs = pkg['h5bp-configs'].directories;
2828
// ---------------------------------------------------------------------
2929

3030
gulp.task('archive:create_archive_dir', () => {
31-
fs.mkdirSync(path.resolve(dirs.archive), '0755');
31+
fs.mkdirSync(path.resolve(dirs.archive), '0755');
3232
});
3333

3434
gulp.task('archive:zip', (done) => {
3535

36-
const archiveName = path.resolve(dirs.archive, `${pkg.name}_v${pkg.version}.zip`);
37-
const zip = archiver('zip');
38-
const files = glob.sync('**/*.*', {
39-
'cwd': dirs.dist,
40-
'dot': true // include hidden files
41-
});
42-
const output = fs.createWriteStream(archiveName);
43-
44-
zip.on('error', (error) => {
45-
done();
46-
throw error;
47-
});
36+
const archiveName = path.resolve(dirs.archive, `${pkg.name}_v${pkg.version}.zip`);
37+
const zip = archiver('zip');
38+
const files = glob.sync('**/*.*', {
39+
'cwd': dirs.dist,
40+
'dot': true // include hidden files
41+
});
42+
const output = fs.createWriteStream(archiveName);
4843

49-
output.on('close', done);
44+
zip.on('error', (error) => {
45+
done();
46+
throw error;
47+
});
5048

51-
files.forEach( (file) => {
49+
output.on('close', done);
5250

53-
const filePath = path.resolve(dirs.dist, file);
51+
files.forEach((file) => {
5452

55-
// `zip.bulk` does not maintain the file
56-
// permissions, so we need to add files individually
57-
zip.append(fs.createReadStream(filePath), {
58-
'name': file,
59-
'mode': fs.statSync(filePath).mode
60-
});
53+
const filePath = path.resolve(dirs.dist, file);
6154

55+
// `zip.bulk` does not maintain the file
56+
// permissions, so we need to add files individually
57+
zip.append(fs.createReadStream(filePath), {
58+
'name': file,
59+
'mode': fs.statSync(filePath).mode
6260
});
6361

64-
zip.pipe(output);
65-
zip.finalize();
62+
});
63+
64+
zip.pipe(output);
65+
zip.finalize();
6666

6767
});
6868

6969
gulp.task('clean', (done) => {
70-
del([
71-
dirs.archive,
72-
dirs.dist
73-
]).then( () => {
74-
done();
75-
});
70+
del([
71+
dirs.archive,
72+
dirs.dist
73+
]).then(() => {
74+
done();
75+
});
7676
});
7777

7878
gulp.task('copy', [
79-
'copy:.htaccess',
80-
'copy:index.html',
81-
'copy:jquery',
82-
'copy:license',
83-
'copy:main.css',
84-
'copy:misc',
85-
'copy:normalize'
79+
'copy:.htaccess',
80+
'copy:index.html',
81+
'copy:jquery',
82+
'copy:license',
83+
'copy:main.css',
84+
'copy:misc',
85+
'copy:normalize'
8686
]);
8787

8888
gulp.task('copy:.htaccess', () =>
89-
gulp.src('node_modules/apache-server-configs/dist/.htaccess')
90-
.pipe(plugins().replace(/# ErrorDocument/g, 'ErrorDocument'))
91-
.pipe(gulp.dest(dirs.dist))
89+
gulp.src('node_modules/apache-server-configs/dist/.htaccess')
90+
.pipe(plugins().replace(/# ErrorDocument/g, 'ErrorDocument'))
91+
.pipe(gulp.dest(dirs.dist))
9292
);
9393

9494
gulp.task('copy:index.html', () => {
95-
const hash = ssri.fromData(
96-
fs.readFileSync('node_modules/jquery/dist/jquery.min.js'),
97-
{ algorithms: ['sha256'] }
98-
);
99-
let version = pkg.devDependencies.jquery;
100-
let modernizrVersion = pkg.devDependencies.modernizr;
101-
102-
gulp.src(`${dirs.src}/index.html`)
103-
.pipe(plugins().replace(/{{JQUERY_VERSION}}/g, version))
104-
.pipe(plugins().replace(/{{MODERNIZR_VERSION}}/g, modernizrVersion))
105-
.pipe(plugins().replace(/{{JQUERY_SRI_HASH}}/g, hash.toString()))
106-
.pipe(gulp.dest(dirs.dist));
95+
const hash = ssri.fromData(
96+
fs.readFileSync('node_modules/jquery/dist/jquery.min.js'),
97+
{algorithms: ['sha256']}
98+
);
99+
let version = pkg.devDependencies.jquery;
100+
let modernizrVersion = pkg.devDependencies.modernizr;
101+
102+
gulp.src(`${dirs.src}/index.html`)
103+
.pipe(plugins().replace(/{{JQUERY_VERSION}}/g, version))
104+
.pipe(plugins().replace(/{{MODERNIZR_VERSION}}/g, modernizrVersion))
105+
.pipe(plugins().replace(/{{JQUERY_SRI_HASH}}/g, hash.toString()))
106+
.pipe(gulp.dest(dirs.dist));
107107
});
108108

109109
gulp.task('copy:jquery', () =>
110-
gulp.src(['node_modules/jquery/dist/jquery.min.js'])
111-
.pipe(plugins().rename(`jquery-${pkg.devDependencies.jquery}.min.js`))
112-
.pipe(gulp.dest(`${dirs.dist}/js/vendor`))
110+
gulp.src(['node_modules/jquery/dist/jquery.min.js'])
111+
.pipe(plugins().rename(`jquery-${pkg.devDependencies.jquery}.min.js`))
112+
.pipe(gulp.dest(`${dirs.dist}/js/vendor`))
113113
);
114114

115115
gulp.task('copy:license', () =>
116-
gulp.src('LICENSE.txt')
117-
.pipe(gulp.dest(dirs.dist))
116+
gulp.src('LICENSE.txt')
117+
.pipe(gulp.dest(dirs.dist))
118118
);
119119

120120
gulp.task('copy:main.css', () => {
121121

122-
const banner = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n\n`;
122+
const banner = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n\n`;
123123

124-
gulp.src(`${dirs.src}/css/main.css`)
125-
.pipe(plugins().header(banner))
126-
.pipe(plugins().autoprefixer({
127-
browsers: ['last 2 versions', 'ie >= 9', '> 1%'],
128-
cascade: false
129-
}))
130-
.pipe(gulp.dest(`${dirs.dist}/css`));
124+
gulp.src(`${dirs.src}/css/main.css`)
125+
.pipe(plugins().header(banner))
126+
.pipe(plugins().autoprefixer({
127+
browsers: ['last 2 versions', 'ie >= 9', '> 1%'],
128+
cascade: false
129+
}))
130+
.pipe(gulp.dest(`${dirs.dist}/css`));
131131
});
132132

133133
gulp.task('copy:misc', () =>
134-
gulp.src([
134+
gulp.src([
135135

136-
// Copy all files
137-
`${dirs.src}/**/*`,
136+
// Copy all files
137+
`${dirs.src}/**/*`,
138138

139-
// Exclude the following files
140-
// (other tasks will handle the copying of these files)
141-
`!${dirs.src}/css/main.css`,
142-
`!${dirs.src}/index.html`
139+
// Exclude the following files
140+
// (other tasks will handle the copying of these files)
141+
`!${dirs.src}/css/main.css`,
142+
`!${dirs.src}/index.html`
143143

144-
], {
144+
], {
145145

146-
// Include hidden files by default
147-
dot: true
146+
// Include hidden files by default
147+
dot: true
148148

149-
}).pipe(gulp.dest(dirs.dist))
149+
}).pipe(gulp.dest(dirs.dist))
150150
);
151151

152152
gulp.task('copy:normalize', () =>
153-
gulp.src('node_modules/normalize.css/normalize.css')
154-
.pipe(gulp.dest(`${dirs.dist}/css`))
153+
gulp.src('node_modules/normalize.css/normalize.css')
154+
.pipe(gulp.dest(`${dirs.dist}/css`))
155155
);
156156

157-
gulp.task( 'modernizr', (done) =>{
157+
gulp.task('modernizr', (done) =>{
158158

159-
modernizr.build(modernizrConfig, (code) => {
160-
fs.writeFile(`${dirs.dist}/js/vendor/modernizr-${pkg.devDependencies.modernizr}.min.js`, code, done);
161-
});
159+
modernizr.build(modernizrConfig, (code) => {
160+
fs.writeFile(`${dirs.dist}/js/vendor/modernizr-${pkg.devDependencies.modernizr}.min.js`, code, done);
161+
});
162162

163163
});
164164

165165
gulp.task('lint:js', () =>
166-
gulp.src([
167-
'gulpfile.js',
168-
`${dirs.src}/js/*.js`,
169-
`${dirs.test}/*.js`
170-
]).pipe(plugins().jscs())
171-
.pipe(plugins().jshint())
172-
.pipe(plugins().jshint.reporter('jshint-stylish'))
173-
.pipe(plugins().jshint.reporter('fail'))
166+
gulp.src([
167+
'gulpfile.js',
168+
`${dirs.src}/js/*.js`,
169+
`${dirs.test}/*.js`
170+
]).pipe(plugins().jscs())
171+
.pipe(plugins().eslint())
172+
.pipe(plugins().eslint.failOnError())
174173
);
175174

176175

@@ -179,17 +178,17 @@ gulp.task('lint:js', () =>
179178
// ---------------------------------------------------------------------
180179

181180
gulp.task('archive', (done) => {
182-
runSequence(
183-
'build',
184-
'archive:create_archive_dir',
185-
'archive:zip',
181+
runSequence(
182+
'build',
183+
'archive:create_archive_dir',
184+
'archive:zip',
186185
done);
187186
});
188187

189188
gulp.task('build', (done) => {
190-
runSequence(
191-
['clean', 'lint:js'],
192-
'copy', 'modernizr',
189+
runSequence(
190+
['clean', 'lint:js'],
191+
'copy', 'modernizr',
193192
done);
194193
});
195194

0 commit comments

Comments
 (0)