Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function lint(path, callback) {
var buf = fs.readFileSync(path, 'utf-8');
// remove Byte Order Mark
buf = buf.replace(/^\uFEFF/, '');
jshint.JSHINT(buf);
var nErrors = jshint.JSHINT.errors.length;
if (nErrors) {
// ruff output of errors (for now)
console.log(jshint.JSHINT.errors);
console.log(' Found %j lint errors on %s, do you want to continue?', nErrors, path);
cli.choose(['no', 'yes'], function(i){
if (i) {
process.stdin.destroy();
if(callback) callback();
} else {
process.exit(0);
}
});
module.exports.validate = function(file, callback) {
var data = fs.readFileSync(file, 'utf-8')
, options = require("./jshint_config")
, validator = require("jshint").JSHINT
, nodebot = this
, report = [];
// Validate it
validator(data, options);
errors = validator.errors;
if (errors.length > 0) {
// Report errors
validator.errors.forEach(function(error){
if (error === null) return false;
error.type = "error";
return report.push(error);
});
generate_report(report);
var getTabStr = function(options) {
// Do something that's going to error.
jshint('\tx', options || {});
// If an error occurred, figure out what character JSHint reported and
// subtract one.
var character = jshint.errors && jshint.errors[0] && jshint.errors[0].character - 1;
// If character is actually a number, use it. Otherwise use 1.
var tabsize = isNaN(character) ? 1 : character;
// If tabsize > 1, return something that should be safe to use as a
// placeholder. \uFFFF repeated 2+ times.
return tabsize > 1 && grunt.util.repeat(tabsize, '\uFFFF');
};
function lintFiles(files) {
var errorsFound = 0,
i, j, len, len2, src, errors, e;
for (i = 0, len = files.length; i < len; i++) {
jshint.JSHINT(fs.readFileSync(files[i], 'utf8'), hintrc.config, hintrc.globals);
errors = jshint.JSHINT.errors;
for (j = 0, len2 = errors.length; j < len2; j++) {
e = errors[j];
console.log(files[i] + '\tline ' + e.line + '\tcol ' + e.character + '\t ' + e.reason);
}
errorsFound += len2;
}
return errorsFound;
}
return function () {
var content = fs.readFileSync(file).toString()
var fixed = ''
var fmjOptions = commander.indentPref
? fu.merge(config, { indentpref: commander.indentPref })
: config
try {
if (commander.legacy) {
jshint(content, config)
fixed = fixmyjs(jshint.data(), content, fmjOptions).run()
} else {
fixed = fixmyjs.fix(content, fmjOptions)
}
} catch (ex) {
ex.stack = 'File: ' + file + '\n' + ex.stack
throw ex
}
if (commander.silent) {
return true
} else if (commander.dryRun || commander.diff) {
printDiff(content, fixed)
} else if (commander.patch) {
createPatch(file, content, fixed)
} else {
return inputs.forEach(input => jshint.JSHINT(input));
}
function fix(source, options) {
try {
if (options.legacy) {
var jshint = require('jshint').JSHINT;
jshint(source, options);
return fixmyjs(jshint.data(), source, options).run();
}
return fixmyjs.fix(source, options);
} catch (e) {
grunt.log.error(e);
grunt.fail.warn('JavaScript fixification failed.');
}
}
};