Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2fd0d57

Browse files
committed
Add ES5 check to syntax test
1 parent caade64 commit 2fd0d57

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tasks/test_syntax.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var falafel = require('falafel');
55
var glob = require('glob');
66
var madge = require('madge');
77
var readLastLines = require('read-last-lines');
8+
var eslint = require('eslint');
89

910
var constants = require('./util/constants');
1011
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
@@ -20,6 +21,7 @@ assertSrcContents();
2021
assertFileNames();
2122
assertTrailingNewLine();
2223
assertCircularDeps();
24+
assertES5();
2325

2426

2527
// check for for focus and exclude jasmine blocks
@@ -188,6 +190,45 @@ function assertCircularDeps() {
188190
});
189191
}
190192

193+
// Ensure no ES6 has snuck through into the build:
194+
function assertES5() {
195+
var CLIEngine = eslint.CLIEngine;
196+
197+
var cli = new CLIEngine({
198+
useEslintrc: false,
199+
ignore: false,
200+
parserOptions: {
201+
ecmaVersion: 5
202+
}
203+
});
204+
205+
// Filter out min and plotly-geo-assets.js since one is unnecessary
206+
// and the other is super slow:
207+
var files = fs.readdirSync(path.join(__dirname, '../dist'));
208+
var validFiles = [];
209+
for(var i = 0; i < files.length; i++) {
210+
var f = files[i];
211+
var isMin = !/[^(min)]\.js$/.test(f);
212+
var isGeo = /geo-assets/.test(f);
213+
if(!isMin && !isGeo) {
214+
validFiles.push(path.join(__dirname, '../dist', f));
215+
}
216+
}
217+
218+
var report = cli.executeOnFiles(validFiles);
219+
var formatter = cli.getFormatter();
220+
221+
if(report.errorCount > 0) {
222+
console.log(formatter(report.results));
223+
224+
// It doesn't work well to pass formatted logs into this,
225+
// so instead pass the empty string in a way that causes
226+
// the test to fail
227+
log('non-ES5 syntax found', ['']);
228+
}
229+
}
230+
231+
191232
function combineGlobs(arr) {
192233
return '{' + arr.join(',') + '}';
193234
}

0 commit comments

Comments
 (0)