Permalink
Browse files

Fix linting issues

  • Loading branch information...
josdejong committed Nov 20, 2018
1 parent 6baf6f0 commit 2630129c7262fa098c67338039058d40fe60f30c
Showing with 38 additions and 40 deletions.
  1. +15 −15 gulpfile.js
  2. +23 −25 tools/validateAsciiChars.js
@@ -160,24 +160,24 @@ gulp.task('validate', ['minify'], function (cb) {

// check whether any of the source files contains non-ascii characters
gulp.task('validate:ascii', function () {
const Reset = "\x1b[0m"
const BgRed = "\x1b[41m"
const Reset = '\x1b[0m'
const BgRed = '\x1b[41m'

validateAsciiChars.getAllFiles('./src')
.map(validateAsciiChars.validateChars)
.forEach(function (invalidChars) {
invalidChars.forEach(function (res) {
console.log(res.insideComment ? '' : BgRed,
'file:', res.filename,
'ln:' + res.ln,
'col:' + res.col,
'inside comment:', res.insideComment,
'code:', res.c,
'character:', String.fromCharCode(res.c),
Reset
)
})
.map(validateAsciiChars.validateChars)
.forEach(function (invalidChars) {
invalidChars.forEach(function (res) {
console.log(res.insideComment ? '' : BgRed,
'file:', res.filename,
'ln:' + res.ln,
'col:' + res.col,
'inside comment:', res.insideComment,
'code:', res.c,
'character:', String.fromCharCode(res.c),
Reset
)
})
})
})

gulp.task('docs', ['compile'], function () {
@@ -9,49 +9,47 @@ exports.validateChars = function validateChars (filename) {
const contents = fs.readFileSync(filename)
const lines = []
const invalidChars = []
const slashChar = '/'.charCodeAt(0)
const starChar = '*'.charCodeAt(0)
let inSingleLineComment = false
let inMultiLineComment = false

for (let i = 0; i < contents.length; i++) {
const c = contents[i]
const cChar = String.fromCharCode(c)
const cCharPrev = String.fromCharCode(contents[i - 1])
const cCharNext = String.fromCharCode(contents[i + 1])

if (cChar === '\n') {
lines.push(i)
lines.push(i)
}

if (!inSingleLineComment && !inMultiLineComment) {
if (cChar === '/' && cCharNext === '/') {
inSingleLineComment = true
}
if (cChar === '/' && cCharNext === '/') {
inSingleLineComment = true
}

if (cChar === '/' && cCharNext === '*') {
inMultiLineComment = true
}
if (cChar === '/' && cCharNext === '*') {
inMultiLineComment = true
}
}

if (inSingleLineComment && cChar === '\n') {
inSingleLineComment = false
inSingleLineComment = false
}

if (inMultiLineComment && cCharPrev === '*' && cChar === '/') {
inMultiLineComment = false
inMultiLineComment = false
}

if (c > 128) {
const ln = lines.length + 1
const col = i - (lines.length > 0 ? last(lines) : 0)
invalidChars.push({
filename,
ln,
col,
c,
insideComment: inSingleLineComment || inMultiLineComment
})
const ln = lines.length + 1
const col = i - (lines.length > 0 ? last(lines) : 0)
invalidChars.push({
filename,
ln,
col,
c,
insideComment: inSingleLineComment || inMultiLineComment
})
}
}

@@ -65,17 +63,17 @@ exports.validateChars = function validateChars (filename) {
* @param {string} dir Dir path string.
* @return {string[]} Array with all file names that are inside the directory.
*/
exports.getAllFiles = function getAllFiles(dir) {
exports.getAllFiles = function getAllFiles (dir) {
return fs.readdirSync(dir).reduce(function (files, file) {
const name = path.join(dir, file)
const isDirectory = fs.statSync(name).isDirectory()
return isDirectory
return isDirectory
? files.concat(getAllFiles(name))
: files.concat([name])
}, [])
}

// return the last item from an array
function last (array) {
return array[array.length - 1]
return array[array.length - 1]
}

0 comments on commit 2630129

Please sign in to comment.