How to use the jshint.JSHINT.errors function in jshint

To help you get started, we’ve selected a few jshint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DeloitteDigitalAPAC / eslint-config-deloitte / kits / jakefile-kit / Jakefile.js View on Github external
// warning.reason
			"Expected an identifier and instead saw 'undefined' (a reserved word).": true,
			"Use '===' to compare with 'null'.": true,
			"Use '!==' to compare with 'null'.": true,
			"Expected an assignment or function call and instead saw an expression.": true,
			"Expected a 'break' statement before 'case'.": true,
			"'e' is already defined.": true,

			// warning.raw
			"Expected an identifier and instead saw \'{a}\' (a reserved word).": true
		},
		found = 0, errors, warning;

		jshint( src, hint );

		errors = jshint.errors;


		for ( var i = 0; i < errors.length; i++ ) {
			warning = errors[i];

			// If a warning exists for this error
			if ( warning &&
					// If the warning has evidence and the evidence is NOT a single line comment
					( warning.evidence && !/^\/\//.test( warning.evidence.trim() ) )
				) {

				//console.dir( warning );

				if ( !ok[ warning.reason ] && !ok[ warning.raw ] ) {
					found++;
github matrix-io / matrix-cli / lib / helpers.js View on Github external
function checkAppCode(path, cb) {
  debug("Checking app code...");
  var appFile = fs.readFileSync(path + '/app.js').toString();

  // run JSHINT on the application
  var jshConfig = JSON.parse(fs.readFileSync(__dirname + '/../.jshintrc'));
  JSHINT(appFile, jshConfig);
  if (JSHINT.errors.length > 0) {
    Matrix.loader.stop();
    console.log(t('matrix.deploy.cancel_deploy').red)
    _.each(JSHINT.errors, function (e) {
      if (_.isNull(e)) {
        return;
      }
      var a = [];
      if (e.hasOwnProperty('evidence')) {
        a[e.character - 1] = '^';
        // regular error
      }
      e.evidence = e.evidence || '';
      console.log('\n' + '(error)'.red, e.reason, '[app.js]', e.line + ':' + e.character, '\n' + e.evidence.grey, '\n' + a.join(' ').grey);
    });
    cb(new Error('JSHINT found ' + JSHINT.errors.length + ' errors!'));
  } else {
    cb();
  }
}
github OpenF2 / F2 / build / build.js View on Github external
function jsHint() {
	console.log('Running JSHint on all core source files...');
	var jshintrc = JSON.parse(fs.readFileSync('./.jshintrc', ENCODING)),
		hintStatus,
		hintTotalStatus = true,
		jshintGlobals = jshintrc.globals;
	delete jshintrc.globals; // jshint will complain if this is passed in

	for (var i = 0; i < CORE_FILES.length; i++) {
		hintStatus = jshint(fs.readFileSync(CORE_FILES[i].src, ENCODING), jshintrc, jshintGlobals);
		console.log('\t%s... %s', CORE_FILES[i].src, (hintStatus ? 'PASS' : 'FAIL'));
		if (!hintStatus) {
			for (var e = 0; e < jshint.errors.length; e++) {
				console.log('\t\tline %s, col %s, %s', jshint.errors[e].line, jshint.errors[e].character, jshint.errors[e].reason);
			}
			hintTotalStatus = false;
		}
	}
	if (!hintTotalStatus) {
		die('JS Hint failed, please fix errors listed above and try again.');
	} else {
		console.log('COMPLETE');
	}
}
github codenothing / Nlint / lib / linters / jshint.js View on Github external
render: function( path, contents, settings, callback ) {
		var errors = [];

		// Run jshint
		if ( ! JSHint( contents, settings || {} ) ) {
			// When jshint is unable to continue, it pushes a null entry
			if ( JSHint.errors[ JSHint.errors.length - 1 ] === null ) {
				JSHint.errors.pop();
			}

			// Transfer errors to nlint format
			JSHint.errors.forEach(function( e ) {
				errors.push({
					path: path,
					message: e.reason,
					line: e.line,
					character: e.character,
					evidence: e.evidence
				});
			});
		}

		// callback( Actual error, lint errors, lint warnings )
github LiamKarlMitchell / InfiniteSky / vmscript.js View on Github external
console.log('module '+sandbox.module.name+' loaded');

                  }
                }
                console.log(file);
              }
              //console.log('Loaded '+file);
            }
            catch (ex) {
              console.error('\x1b[31;1mFailed to load script: ' + file+'\x1b[0m');
              console.error('\x1b[33;1mReason: ' + ex.message+'\x1b[0m');
              console.error(ex);

              if (!jshint(data.toString())) {
                for (var i=0;i
github jackmoore / sticky-position / build.js View on Github external
function lint(full) {
	jshint(full.toString(), {
		browser: true,
		undef: true,
		unused: true,
		immed: true,
		eqeqeq: true,
		eqnull: true,
		noarg: true,
		predef: ['define', 'module', 'exports']
	});

	if (jshint.errors.length) {
		jshint.errors.forEach(function (err) {
			console.log(err.line+':'+err.character+' '+err.reason);
		});
	} else {
		console.log('linted')
	}

	return true;
}
github jilieryuyi / wing-binlog / web / lang / en / vendors / autosize / build.js View on Github external
function lint(full) {
	jshint(full.toString(), {
		browser: true,
		undef: true,
		unused: true,
		immed: true,
		eqeqeq: true,
		eqnull: true,
		noarg: true,
		predef: ['define', 'module', 'exports', 'Set']
	});

	if (jshint.errors.length) {
		jshint.errors.forEach(function (err) {
			console.log(err.line+':'+err.character+' '+err.reason);
		});
	} else {
		console.log('linted')
	}

	return true;
}
github jackmoore / sticky-position / build.js View on Github external
function lint(full) {
	jshint(full.toString(), {
		browser: true,
		undef: true,
		unused: true,
		immed: true,
		eqeqeq: true,
		eqnull: true,
		noarg: true,
		predef: ['define', 'module', 'exports']
	});

	if (jshint.errors.length) {
		jshint.errors.forEach(function (err) {
			console.log(err.line+':'+err.character+' '+err.reason);
		});
	} else {
		console.log('linted')
	}

	return true;
}
github jilieryuyi / wing-binlog / web / lang / en / vendors / autosize / build.js View on Github external
function lint(full) {
	jshint(full.toString(), {
		browser: true,
		undef: true,
		unused: true,
		immed: true,
		eqeqeq: true,
		eqnull: true,
		noarg: true,
		predef: ['define', 'module', 'exports', 'Set']
	});

	if (jshint.errors.length) {
		jshint.errors.forEach(function (err) {
			console.log(err.line+':'+err.character+' '+err.reason);
		});
	} else {
		console.log('linted')
	}

	return true;
}
github yui / yogi / lib / cmds / lint.js View on Github external
fs.readFile(file, 'utf8', function(err, data) {
            if (path.dirname(file).indexOf('meta') > -1 && path.extname(file) === '.js') {
                log.info('tweaking meta test js file for lint');
                data = '(\n' + data + ')();';
            }
            linter(data, options);
            callback(linter.errors.length ? linter.errors : null);
        });
    },