Skip to content

Commit 5e6a291

Browse files
committed
add trailing newline character syntax test
- run it on .json image test mocks and .glsl files - no need it to run it on .js files as eslint already takes care of that.
1 parent 1390288 commit 5e6a291

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"open": "0.0.5",
126126
"prepend-file": "^1.3.1",
127127
"prettysize": "0.0.3",
128+
"read-last-lines": "^1.1.0",
128129
"requirejs": "^2.3.1",
129130
"through2": "^2.0.3",
130131
"uglify-js": "^2.7.5",

tasks/test_syntax.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var fs = require('fs');
44
var falafel = require('falafel');
55
var glob = require('glob');
66
var madge = require('madge');
7+
var readLastLines = require('read-last-lines');
78

89
var constants = require('./util/constants');
910
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
@@ -17,6 +18,7 @@ var EXIT_CODE = 0;
1718
assertJasmineSuites();
1819
assertSrcContents();
1920
assertFileNames();
21+
assertTrailingNewLine();
2022
assertCircularDeps();
2123

2224

@@ -125,7 +127,39 @@ function assertFileNames() {
125127

126128
log('lower case only file names', logs);
127129
});
130+
}
131+
132+
// check that all files have a trailing new line character
133+
function assertTrailingNewLine() {
134+
var pattern = combineGlobs([
135+
path.join(constants.pathToSrc, '**/*.glsl'),
136+
path.join(constants.pathToRoot, 'test', 'image', 'mocks', '*')
137+
]);
138+
139+
var regex = /\r?\n$/;
140+
var promises = [];
141+
var logs = [];
142+
143+
glob(pattern, function(err, files) {
144+
files.forEach(function(file) {
145+
var promise = readLastLines.read(file, 1);
128146

147+
promises.push(promise);
148+
149+
promise.then(function(lines) {
150+
if(!regex.test(lines)) {
151+
logs.push([
152+
file, ':',
153+
'does not have a trailing new line character'
154+
].join(' '));
155+
}
156+
});
157+
});
158+
159+
Promise.all(promises).then(function() {
160+
log('trailing new line character', logs);
161+
});
162+
});
129163
}
130164

131165
// check circular dependencies

0 commit comments

Comments
 (0)