.jshintrc file is not readable

I am using Ionic framework JSHint

to overlay code ES6

on a project. I need to set up a list to use ES6. it seems that when I start linter using a small script it doesn't read the config file .jshintrc

. I got a bunch of these errors:

'arrow function syntax (=>)' is only available in ES6 (use esnext option). ->     $ionicPlatform.ready(() => {

      

my.jshintrc file:

{
  "asi": false,
  "boss": true,
  "curly": true,
  "eqeqeq": false,
  "eqnull": true,
  "esnext": true,
  "expr": true,
  "forin": true,
  "immed": true,
  "laxbreak": true,
  "newcap": false,
  "noarg": true,
  "node": true,
  "nonew": true,
  "plusplus": true,
  "quotmark": "single",
  "strict": false,
  "undef": true,
  "unused": true
}

      

I am running JSHint with this script contained in Hooks / before_prepare

#!/usr/bin/env node

var fs = require('fs');
var path = require('path');
var jshint = require('jshint').JSHINT;
var async = require('async');

var foldersToProcess = [
    'js6/',
    'js6/controllers',
    'js6/controllers/schedule',
];

foldersToProcess.forEach(function(folder) {
    processFiles("www/" + folder);
});

function processFiles(dir, callback) {
    var errorCount = 0;
    fs.readdir(dir, function(err, list) {
        if (err) {
            console.log('processFiles err: ' + err);
            return;
        }
        async.eachSeries(list, function(file, innercallback) {
            file = dir + '/' + file;
            fs.stat(file, function(err, stat) {
                if(!stat.isDirectory()) {
                    if(path.extname(file) === ".js") {
                        lintFile(file, function(hasError) {
                            if(hasError) {
                                errorCount++;
                            }
                            innercallback();
                        });
                    } else {
                        innercallback();
                    }
                } else {
                    innercallback();
                }
            });
        }, function(error) {
            if(errorCount > 0) {
                process.exit(1);
            }
        });
    });
}

function lintFile(file, callback) {
    console.log("Linting " + file);
    fs.readFile(file, function(err, data) {
        if(err) {
            console.log('Error: ' + err);
            return;
        }
        if(jshint(data.toString())) {
            console.log('File ' + file + ' has no errors.');
            console.log('-----------------------------------------');
            callback(false);
        } else {
            console.log('Errors in file ' + file);
            var out = jshint.data(),
            errors = out.errors;
            for(var j = 0; j < errors.length; j++) {
                console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' +
errors[j].evidence);
            }
            console.log('-----------------------------------------');
            callback(true);
        }
    });
}

      

file structure is typical cordova project structure, I have www folder with js6 folder inside www -> js6 -> controllers -> schedule

+3


source to share


1 answer


change

if(jshint(data.toString())) {

      

to



if(jshint(data.toString(), {esnext:true}})) {

      

or you can read the contents of the .jshintrc file first and set the jshint config to that location. see also https://github.com/jetma/cordova-hooks/blob/master/before_prepare/02_jshint.js/ .

-1


source







All Articles