Skip to content

Commit

Permalink
CB-12895 : removed jshint and added eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyso committed Jul 14, 2017
1 parent 26beb94 commit 83435d5
Show file tree
Hide file tree
Showing 51 changed files with 2,827 additions and 2,867 deletions.
2 changes: 1 addition & 1 deletion .jshintignore → .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bin/node_modules/*
bin/templates/project/*
tests/spec/unit/fixtures/*
tests/spec/unit/fixtures/*
10 changes: 10 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tmp
xcuserdata
console.log
node_modules/jshint
node_modules/eslint
node_modules/jasmine-node
node_modules/rewire
node_modules/istanbul
Expand Down
12 changes: 0 additions & 12 deletions .jshintrc

This file was deleted.

12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ install:
- npm install ios-deploy
- npm install -g codecov
script:
- npm run jshint
- npm run unit-tests
- npm run e2e-tests
- open -b com.apple.iphonesimulator
- npm run objc-tests
- npm run cover
- npm run unit-tests
- npm run e2e-tests
- open -b com.apple.iphonesimulator
- npm run objc-tests
- npm run cover
- npm run eslint
after_script: codecov
2 changes: 0 additions & 2 deletions CordovaLib/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
var PLATFORM_VERSION_BUILD_LABEL = '4.5.0-dev';
// file: src/scripts/require.js

/*jshint -W079 */
/*jshint -W020 */

var require,
define;
Expand Down
6 changes: 4 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ install:
- ps: Install-Product node $env:nodejs_version
# Lines below required due to uncrustify installation failure on Windows
- npm install --prod
- npm install jshint jasmine rewire
- npm install eslint eslint-config-semistandard jasmine rewire
- npm install eslint-config-standard eslint-plugin-import eslint-plugin-node
- npm install eslint-plugin-promise eslint-plugin-standard

build: off

test_script:
- node --version
- npm --version
- npm run jshint
- npm run unit-tests
- npm run eslint
127 changes: 62 additions & 65 deletions bin/lib/create.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions bin/templates/project/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
*/
var app = {
// Application Constructor
initialize: function() {
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
onDeviceReady: function () {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
receivedEvent: function (id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
Expand All @@ -48,4 +48,4 @@ var app = {
}
};

app.initialize();
app.initialize();
116 changes: 57 additions & 59 deletions bin/templates/scripts/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
under the License.
*/

/*jslint node: true */
/* jslint node: true */

var fs = require('fs');
var path = require('path');
Expand All @@ -31,7 +31,7 @@ var PluginManager = require('cordova-common').PluginManager;
var Q = require('q');
var util = require('util');

function setupEvents(externalEventEmitter) {
function setupEvents (externalEventEmitter) {
if (externalEventEmitter) {
// This will make the platform internal events visible outside
events.forwardEventsTo(externalEventEmitter);
Expand All @@ -53,7 +53,7 @@ function setupEvents(externalEventEmitter) {
* logging purposes. If no EventEmitter provided, all events will be logged to
* console
*/
function Api(platform, platformRootDir, events) {
function Api (platform, platformRootDir, events) {
// 'platform' property is required as per PlatformApi spec
this.platform = platform || 'ios';
this.root = platformRootDir || path.resolve(__dirname, '..');
Expand All @@ -64,15 +64,15 @@ function Api(platform, platformRootDir, events) {
var xcodeCordovaProj;

try {
xcodeProjDir = fs.readdirSync(this.root).filter( function(e) { return e.match(/\.xcodeproj$/i); })[0];
xcodeProjDir = fs.readdirSync(this.root).filter(function (e) { return e.match(/\.xcodeproj$/i); })[0];
if (!xcodeProjDir) {
throw new CordovaError('The provided path "' + this.root + '" is not a Cordova iOS project.');
}

var cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep)+1, xcodeProjDir.indexOf('.xcodeproj'));
var cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep) + 1, xcodeProjDir.indexOf('.xcodeproj'));
xcodeCordovaProj = path.join(this.root, cordovaProjName);
} catch(e) {
throw new CordovaError('The provided path "'+this.root+'" is not a Cordova iOS project.');
} catch (e) {
throw new CordovaError('The provided path "' + this.root + '" is not a Cordova iOS project.');
}

this.locations = {
Expand Down Expand Up @@ -119,17 +119,16 @@ Api.createPlatform = function (destination, config, options, events) {
var result;
try {
result = require('../../../lib/create')
.createProject(destination, config.packageName(), name, options)
.then(function () {
// after platform is created we return Api instance based on new Api.js location
// This is required to correctly resolve paths in the future api calls
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
return new PlatformApi('ios', destination, events);
});
}
catch(e) {
events.emit('error','createPlatform is not callable from the iOS project API.');
throw(e);
.createProject(destination, config.packageName(), name, options)
.then(function () {
// after platform is created we return Api instance based on new Api.js location
// This is required to correctly resolve paths in the future api calls
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
return new PlatformApi('ios', destination, events);
});
} catch (e) {
events.emit('error', 'createPlatform is not callable from the iOS project API.');
throw (e);
}
return result;
};
Expand All @@ -156,15 +155,14 @@ Api.updatePlatform = function (destination, options, events) {
var result;
try {
result = require('../../../lib/create')
.updateProject(destination, options)
.then(function () {
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
return new PlatformApi('ios', destination, events);
});
}
catch (e) {
events.emit('error','updatePlatform is not callable from the iOS project API, you will need to do this manually.');
throw(e);
.updateProject(destination, options)
.then(function () {
var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
return new PlatformApi('ios', destination, events);
});
} catch (e) {
events.emit('error', 'updatePlatform is not callable from the iOS project API, you will need to do this manually.');
throw (e);
}
return result;
};
Expand Down Expand Up @@ -234,15 +232,15 @@ Api.prototype.addPlugin = function (plugin, installOptions) {

return PluginManager.get(self.platform, self.locations, xcodeproj)
.addPlugin(plugin, installOptions)
.then(function(){
.then(function () {
var frameworkTags = plugin.getFrameworks(self.platform);
var frameworkPods = frameworkTags.filter(function(obj){
return (obj.type == 'podspec');
var frameworkPods = frameworkTags.filter(function (obj) {
return (obj.type === 'podspec');
});

return Q.resolve(frameworkPods);
})
.then(function(frameworkPods) {
.then(function (frameworkPods) {
if (!(frameworkPods.length)) {
return Q.resolve();
}
Expand All @@ -256,19 +254,19 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type="podspec"');

var podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME));
var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name);
var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name);

frameworkPods.forEach(function(obj) {
frameworkPods.forEach(function (obj) {
var podJson = {
name: obj.src,
type: obj.type,
spec: obj.spec
};

var val = podsjsonFile.get(podJson.name);
if (val) { // found
if (val) { // found
if (podJson.spec !== val.spec) { // exists, different spec, print warning
events.emit('warn', plugin.id + ' depends on ' + podJson.name + '@' + podJson.spec + ', which conflicts with another plugin. ' + podJson.name + '@' + val.spec + ' is already installed and was not overwritten.');
events.emit('warn', plugin.id + ' depends on ' + podJson.name + '@' + podJson.spec + ', which conflicts with another plugin. ' + podJson.name + '@' + val.spec + ' is already installed and was not overwritten.');
}
// increment count, but don't add in Podfile because it already exists
podsjsonFile.increment(podJson.name);
Expand Down Expand Up @@ -317,15 +315,15 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {

return PluginManager.get(self.platform, self.locations, xcodeproj)
.removePlugin(plugin, uninstallOptions)
.then(function(){
.then(function () {
var frameworkTags = plugin.getFrameworks(self.platform);
var frameworkPods = frameworkTags.filter(function(obj){
return (obj.type == 'podspec');
var frameworkPods = frameworkTags.filter(function (obj) {
return (obj.type === 'podspec');
});

return Q.resolve(frameworkPods);
})
.then(function(frameworkPods) {
.then(function (frameworkPods) {
if (!(frameworkPods.length)) {
return Q.resolve();
}
Expand All @@ -336,12 +334,12 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
var Podfile = require('./lib/Podfile').Podfile;
var PodsJson = require('./lib/PodsJson').PodsJson;

events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type=\"podspec\"');
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */

var podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME));
var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name);
frameworkPods.forEach(function(obj) {
var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name);

frameworkPods.forEach(function (obj) {
var podJson = {
name: obj.src,
type: obj.type,
Expand All @@ -352,7 +350,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
if (val) { // found, decrement count
podsjsonFile.decrement(podJson.name);
} else { // not found (perhaps a sync error)
var message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name);
var message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */
events.emit('verbose', message);
}

Expand Down Expand Up @@ -412,9 +410,9 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
Api.prototype.build = function (buildOptions) {
var self = this;
return check_reqs.run()
.then(function () {
return require('./lib/build').run.call(self, buildOptions);
});
.then(function () {
return require('./lib/build').run.call(self, buildOptions);
});
};

/**
Expand All @@ -429,12 +427,12 @@ Api.prototype.build = function (buildOptions) {
* @return {Promise} A promise either fulfilled if package was built and ran
* successfully, or rejected with CordovaError.
*/
Api.prototype.run = function(runOptions) {
Api.prototype.run = function (runOptions) {
var self = this;
return check_reqs.run()
.then(function () {
return require('./lib/run').run.call(self, runOptions);
});
.then(function () {
return require('./lib/run').run.call(self, runOptions);
});
};

/**
Expand All @@ -443,15 +441,15 @@ Api.prototype.run = function(runOptions) {
* @return {Promise} Return a promise either fulfilled, or rejected with
* CordovaError.
*/
Api.prototype.clean = function(cleanOptions) {
Api.prototype.clean = function (cleanOptions) {
var self = this;
return check_reqs.run()
.then(function () {
return require('./lib/clean').run.call(self, cleanOptions);
})
.then(function () {
return require('./lib/prepare').clean.call(self, cleanOptions);
});
.then(function () {
return require('./lib/clean').run.call(self, cleanOptions);
})
.then(function () {
return require('./lib/prepare').clean.call(self, cleanOptions);
});
};

/**
Expand All @@ -462,7 +460,7 @@ Api.prototype.clean = function(cleanOptions) {
* @return {Promise<Requirement[]>} Promise, resolved with set of Requirement
* objects for current platform.
*/
Api.prototype.requirements = function() {
Api.prototype.requirements = function () {
return check_reqs.check_all();
};

Expand Down
Loading

0 comments on commit 83435d5

Please sign in to comment.