How to use jshint - 10 common examples

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 sconover / knit-js / test / jshint.js View on Github external
_.each(files, function(file) {
  var result = JSHINT(fs.readFileSync(file, "utf8"), {
                      
                      asi:true,               // DRY statement termination, less code spam.  
                                              // http://aresemicolonsnecessaryinjavascript.com/
                      
                      node:true,              //we like node here
                      
                      evil:true,              //dsl function uses eval
                      
                      forin:true,             //while it's possible that we could be
                                              //considering unwanted prototype methods, mostly
                                              //we're doing this because the jsobjects are being
                                              //used as maps.  
                      
                      myGlobals:{knit:false}  //no lint/hint code spam, ty very much
                      
                    })
github makesites / jquery-three / build.js View on Github external
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);
			}
		});
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 rwaldron / mediagroup.js / Jakefile.js View on Github external
},

		dataProps = {
			unuseds: true,
			implieds: true,
			globals: true
		},
		props;

		jshint( src, hint );

		errors = jshint.errors;

		if ( hint.data ) {

			data = jshint.data();

			Object.keys( dataProps ).forEach(function( prop ) {
				if ( data[ prop ] ) {
					console.log( prop, data[ prop ] );
				}
			});
		}

		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() ) )
				) {
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 FGRibreau / check-build / src / interface / jshint.js View on Github external
return function (options, f) {
    options = options || {};

    options.config = jshintcli.loadConfig(p.resolve(process.cwd(), './.jshintrc'));
    options.args = grunt.file.expand(options.args);

    options.reporter = function (results, data, options) {
      // @todo implement fixmyfs
      // if (checkBuildOptions.checkbuild.enable.indexOf('fixmyjs') !== -1) {
      //   results.forEach(function (file) {
      //     console.log(fixmyjs.fix(shjs.cat(file.file), {}));
      //   });
      // }

      // use jshint-stylish by default
      var stylish = require('jshint-stylish').reporter(results, data, options);
      return stylish;
    };

    var hadErrors = !jshintcli.run(options);
github STRML / JSXHint / utils.js View on Github external
copyConfig: function copyConfig(dir, file){
    var filePath = path.resolve(dir, file);
    if (checkedSupportFiles[filePath]) return;
    // Indicate that this is copied already to prevent unnecessary file operations.
    checkedSupportFiles[filePath] = true;

    if (fs.existsSync(filePath)) {
      var destination = path.join(utils.tmpdir, utils.getCleanAbsolutePath(filePath));
      debug("Copying support file from %s to temp directory at %s.", filePath, destination);
      if (file === '.jshintrc') {
        try {
          var jshintrc = jshintcli.loadConfig(filePath);
          fs.writeJSONSync(destination, utils.ensureJshintrcOverrides(jshintrc));
        } catch(e) {
          console.error('Unable to parse .jshintrc file at %s. It must be valid JSON. Error: %s', filePath, e.message);
          return;
        }
      } else {
        fs.copySync(filePath, destination);
      }
    }
    // Not found, keep looking up the root.
    else {
      var parent = path.resolve(dir, '..');
      // Return null at the root, which is also when dir and its parent are the same.
      if (dir === parent) return;
      return copyConfig(parent, file);
    }
github FGRibreau / check-build / src / interface / jshint.js View on Github external
options.args = grunt.file.expand(options.args);

    options.reporter = function (results, data, options) {
      // @todo implement fixmyfs
      // if (checkBuildOptions.checkbuild.enable.indexOf('fixmyjs') !== -1) {
      //   results.forEach(function (file) {
      //     console.log(fixmyjs.fix(shjs.cat(file.file), {}));
      //   });
      // }

      // use jshint-stylish by default
      var stylish = require('jshint-stylish').reporter(results, data, options);
      return stylish;
    };

    var hadErrors = !jshintcli.run(options);
    f(hadErrors);
  };
};
github victorporof / Sublime-JSHint / scripts / run.js View on Github external
function doLint(data, options, globals, lineOffset, charOffset) {
    // Lint the code and write readable error output to the console.
    try {
      jshint(data, options, globals);
    } catch (e) {}

    jshint.errors
      .sort(function(first, second) {
        first = first || {};
        second = second || {};

        if (!first.line) {
          return 1;
        } else if (!second.line){
          return -1;
        } else if (first.line == second.line) {
          return +first.character < +second.character ? -1 : 1;
        } else {
          return +first.line < +second.line ? -1 : 1;
        }