Skip to content

Commit

Permalink
Enable jshint validation, cleanup jshint errors
Browse files Browse the repository at this point in the history
Previously the Gruntfile had jshint settings encoded in it instead of using the more standard .jshintrc. Many editors pick up on jshintrc and will warn you when you have errors, which mine does. I made jshintrc pretty much consistent with Quepid and cleaned up associated errors.
  • Loading branch information
softwaredoug committed Sep 23, 2015
1 parent 6937cc4 commit b6896f1
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 121 deletions.
7 changes: 5 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": "nofunc",
"newcap": true,
"noarg": true,
Expand All @@ -18,7 +17,11 @@
"strict": true,
"trailing": true,
"smarttabs": true,
"validthis": true,
"globals": {
"angular": false
"angular": false,
"inject": false,
"Promise": false,
"URI": false
}
}
46 changes: 9 additions & 37 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,14 @@ module.exports = function(grunt) {
*/
grunt.initConfig({
jshint: {
options: {
//force: true,
globalstrict: true,
//sub: true,
node: true,
loopfunc: true,
browser: true,
devel: true,
globals: {
angular: true,
$: true,
moment: false,
Pikaday: false,
module: false,
forge: false
}
},
beforeconcat: {
options: {
force: false,
ignores: ['**.min.js']
},
files: {
src: ['services/*.js', 'factories/*.js', 'values/*.js']
}
},
//quick version - will not fail entire grunt process if there are lint errors
beforeconcatQ: {
options: {
force: true,
ignores: ['**.min.js']
},
files: {
src: ['module.js, services/*.js', 'factories/*.js', 'values/*.js']
}
}
options: {
force: true,
ignores: ['**.min.js'],
jshintrc: '.jshintrc'
},
all: {
src: ['module.js', 'services/*.js', 'factories/*.js', 'values/*.js']
}
},
concat: {
dist: {
Expand Down Expand Up @@ -105,7 +77,7 @@ module.exports = function(grunt) {
@toc 6.
*/
// Default task(s).
grunt.registerTask('default', ['jshint:beforeconcatQ', 'karma:unit', 'concat:dist']);
grunt.registerTask('default', ['jshint', 'karma:unit', 'concat:dist']);

}
init({}); //initialize here for defaults (init may be called again later within a task)
Expand Down
6 changes: 3 additions & 3 deletions factories/esDocFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
/*jslint validthis:true*/
var self = this;

if (self.doc.hasOwnProperty("highlight")) {
if (self.doc.hasOwnProperty('highlight')) {
var docHls = self.doc.highlight;
if (docHls.hasOwnProperty(fieldName)) {
return docHls[fieldName];
Expand Down Expand Up @@ -87,9 +87,9 @@
angular.forEach(fieldValue, function (value) {
// Doing the naive thing and assuming that the highlight tags
// were not overridden in the query DSL.
var preRegex = new RegExp("<em>", 'g');
var preRegex = new RegExp('<em>', 'g');
var hlPre = value.replace(preRegex, preText);
var postRegex = new RegExp("</em>", 'g');
var postRegex = new RegExp('</em>', 'g');

newValue.push(hlPre.replace(postRegex, postText));
});
Expand Down
10 changes: 5 additions & 5 deletions factories/settingsValidatorFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
var args = { };
var fields = '*';

if ( self.searchEngine == 'solr' ) {
if ( self.searchEngine === 'solr' ) {
args = { q: ['*:*'] };
} else if ( self.searchEngine == 'es' ) {
} else if ( self.searchEngine === 'es' ) {
fields = null;
}

Expand All @@ -51,16 +51,16 @@
// the entire list of fields possible.
// This is not perfect as the top 10 results might not include
// a comprehensive list, but it's the best we can do.
if ( self.searchEngine == 'solr' ) {
if ( self.searchEngine === 'solr' ) {
angular.forEach(self.searcher.docs, function(doc) {
var attributes = Object.keys(doc.doc);

self.fields = self.fields.concat(attributes.filter(function (attribute) {
return self.fields.indexOf(attribute) < 0;
}));
});
} else if ( self.searchEngine == 'es' ) {
self.fields.push("_id");
} else if ( self.searchEngine === 'es' ) {
self.fields.push('_id');

angular.forEach(self.searcher.docs, function(doc) {
var attributes = Object.keys(doc.doc._source);
Expand Down
2 changes: 1 addition & 1 deletion services/esSearcherPreprocessorSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular.module('o19s.splainer-search')

var replaceQuery = function(args, queryText) {
if (queryText) {
queryText = queryText.replace(/\\/g, "\\\\");;
queryText = queryText.replace(/\\/g, '\\\\');
queryText = queryText.replace(/"/g, '\\\"');
}

Expand Down
6 changes: 3 additions & 3 deletions services/esUrlSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ angular.module('o19s.splainer-search')
self.password = a.password();

self.parsed = true;
};
}

/**
*
Expand Down Expand Up @@ -116,7 +116,7 @@ angular.module('o19s.splainer-search')

var url = self.protocol + '://' + self.host;

return url
return url;
}

function setParams (params) {
Expand All @@ -126,7 +126,7 @@ angular.module('o19s.splainer-search')

function UrlNotParseException() {
var self = this;
self.message = "URL not parsed. Must call the parse() function first.";
self.message = 'URL not parsed. Must call the parse() function first.';
self.toString = function() {
return self.message;
};
Expand Down
8 changes: 4 additions & 4 deletions services/fieldSpecSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
angular.module('o19s.splainer-search')
.service('fieldSpecSvc', function fieldSpecSvc() {
// AngularJS will instantiate a singleton by calling 'new' on this function

var addFieldOfType = function(fieldSpec, fieldType, fieldName) {
if (fieldType === 'sub') {
if (!fieldSpec.hasOwnProperty('subs')) {
fieldSpec.subs = [];
}
if (fieldSpec.subs !== '*') {
fieldSpec.subs.push(fieldName);
}
}
if (fieldName === '*') {
fieldSpec.subs = '*';
}
Expand Down Expand Up @@ -47,8 +47,8 @@ angular.module('o19s.splainer-search')
}
});
};


var FieldSpec = function(fieldSpecStr) {
this.fields = [];
this.fieldSpecStr = fieldSpecStr;
Expand Down
8 changes: 4 additions & 4 deletions services/simExplainSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ angular.module('o19s.splainer-search')
});

this.formulaStr = function() {
return 'TF=' + this.fieldWeight.tf().contribution() +
return 'TF=' + this.fieldWeight.tf().contribution() +
' * IDF=' + this.fieldWeight.idf().contribution();
};
};
Expand All @@ -44,7 +44,7 @@ angular.module('o19s.splainer-search')
explain.tf = function() {
return tfExpl;
};

explain.idf = function() {
return idfExpl;
};
Expand All @@ -62,7 +62,7 @@ angular.module('o19s.splainer-search')
/*this.fieldNorm = function() {
};*/
};

this.QueryWeightExplain = function() {
this.realExplanation = 'Query Weight';
tfIdfable(this);
Expand All @@ -87,7 +87,7 @@ angular.module('o19s.splainer-search')

// For default similarity, IDF of the term being searched
// in the case of phrase queries, this is a sum of
// all the members of the phrase.
// all the members of the phrase.
//
// TODO -- the underlying idf for each member of a phrase
// does not identify the term corresponding to that idf,
Expand Down
17 changes: 0 additions & 17 deletions services/solrUrlSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,6 @@ angular.module('o19s.splainer-search')
* */
this.removeUnsupported = function(solrArgs) {
var warnings = {};
var deleteThenWarn = function(arg, warning) {
if (solrArgs.hasOwnProperty(arg)) {
warnings[arg] = warning;
delete solrArgs[arg];
}
};

var deleteThenWarnPrefix = function(argPrefix, warning) {
var argsCpy = angular.copy(solrArgs);
angular.forEach(argsCpy, function(value, key) {
if (key.startsWith(argPrefix)) {
deleteThenWarn(key, warning);
}
});
};

// Stuff I think we can safely remove without warning the user
delete solrArgs['json.wrf'];
delete solrArgs.facet;
Expand All @@ -175,7 +159,6 @@ angular.module('o19s.splainer-search')
delete solrArgs.debug;

// Unsupported stuff to remove and provide a friendly warning
// deleteThenWarnPrefix('group', 'Group queries/field collapsing not supported');
return warnings;
};

Expand Down
4 changes: 2 additions & 2 deletions services/stringPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if (typeof String.prototype.startsWith !== 'function') {
// see below for better implementation!
String.prototype.startsWith = function (str){
String.prototype.startsWith = function (str) {
return this.indexOf(str) === 0;
};
}
Expand All @@ -15,6 +15,6 @@ if (typeof String.prototype.hasSubstr !== 'function') {

if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}
3 changes: 1 addition & 2 deletions services/vectorSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ angular.module('o19s.splainer-search')
rVal.set(key, value * scalar);
});
return rVal;
};

};
});
Loading

0 comments on commit b6896f1

Please sign in to comment.