Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: eslint setup #221

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
extends: '@cordova/eslint-config/node'

overrides:
- files: [test/**/*.js]
extends: '@cordova/eslint-config/browser-tests'

- files: [test/test-platform-modules/**/*.js]
extends: '@cordova/eslint-config/browser'

- files: [src/**/*.js]
extends:
- '@cordova/eslint-config/browser'
- plugin:es5/no-es2015
- plugin:es5/no-es2016
globals:
define: false
PLATFORM_VERSION_BUILD_LABEL: false
12 changes: 6 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compile: {
'android': {},
'ios': {},
'osx': {},
'windows': { useWindowsLineEndings: true },
'browser': {},
'electron': {}
android: {},
ios: {},
osx: {},
windows: { useWindowsLineEndings: true },
browser: {},
electron: {}
},
clean: ['pkg']
});
Expand Down
2 changes: 1 addition & 1 deletion build-tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function build (userConfig) {
modules(config),
getCommitId()
])
.then(([ scripts, modules, commitId ]) => {
.then(([scripts, modules, commitId]) => {
Object.assign(config, { commitId });
return bundle(scripts, modules, config);
});
Expand Down
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"url": "https://issues.apache.org/jira/browse/CB"
},
"scripts": {
"eslint": "eslint --ignore-path .gitignore .",
"lint": "eslint --ignore-path .gitignore .",
"pretest": "npm run build:test",
"test": "npm run eslint && karma start",
"test": "npm run lint && karma start",
"build": "grunt compile",
"build:test": "node build-tools/test-build pkg/cordova.test.js"
},
Expand Down Expand Up @@ -74,16 +74,10 @@
"globby": "^9.2.0"
},
"devDependencies": {
"@cordova/eslint-config": "^2.0.0",
"cordova-android": "^8.0.0",
"cordova-ios": "^5.0.0",
"eslint": "^5.16.0",
"eslint-config-semistandard": "^13.0.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-es5": "^1.4.1",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"grunt": "^1.0.4",
"grunt-contrib-clean": "^2.0.0",
"jasmine-core": "^3.3.0",
Expand Down
12 changes: 0 additions & 12 deletions src/.eslintrc.yml

This file was deleted.

12 changes: 6 additions & 6 deletions src/common/argscheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ var utils = require('cordova/utils');
var moduleExports = module.exports;

var typeMap = {
'A': 'Array',
'D': 'Date',
'N': 'Number',
'S': 'String',
'F': 'Function',
'O': 'Object'
A: 'Array',
D: 'Date',
N: 'Number',
S: 'String',
F: 'Function',
O: 'Object'
};

function extractParamName (callee, argIndex) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var utils = require('cordova/utils');

function each (objects, func, context) {
for (var prop in objects) {
if (objects.hasOwnProperty(prop)) {
if (Object.prototype.hasOwnProperty.call(objects, prop)) {
func.apply(context, [objects[prop], prop]);
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ function include (parent, objects, clobber, merge) {
*/
function recursiveMerge (target, src) {
for (var prop in src) {
if (src.hasOwnProperty(prop)) {
if (Object.prototype.hasOwnProperty.call(src, prop)) {
if (target.prototype && target.prototype.constructor === target) {
// If the target object is a constructor override off prototype.
clobber(target.prototype, prop, src[prop]);
Expand Down
4 changes: 2 additions & 2 deletions src/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function createEvent (type, data) {
event.initEvent(type, false, false);
if (data) {
for (var i in data) {
if (data.hasOwnProperty(i)) {
if (Object.prototype.hasOwnProperty.call(data, i)) {
event[i] = data[i];
}
}
Expand Down Expand Up @@ -234,7 +234,7 @@ var cordova = {
}
} catch (err) {
var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err;
cordova.fireWindowEvent('cordovacallbackerror', { 'message': msg, 'error': err });
cordova.fireWindowEvent('cordovacallbackerror', { message: msg, error: err });
throw err;
}
},
Expand Down
7 changes: 0 additions & 7 deletions test/.eslintrc.yml

This file was deleted.

4 changes: 0 additions & 4 deletions test/test-platform-modules/.eslintrc.yml

This file was deleted.

1 change: 0 additions & 1 deletion test/test-platform-modules/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
*
*/

/* eslint-env jasmine */
module.exports = jasmine.createSpy();
4 changes: 2 additions & 2 deletions test/test.channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('channel', function () {

testChannel.subscribe(handler);
testChannel.fire(1, 2, 3);
expect(handler.calls.argsFor(0)).toEqual([ 1, 2, 3 ]);
expect(handler.calls.argsFor(0)).toEqual([1, 2, 3]);
});
it('Test#013 : should not fire a handler that was unsubscribed', function () {
var testChannel = multi ? multiChannel : stickyChannel;
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('channel', function () {

expectCallCount(before, 1);
expectCallCount(after, 1);
expect(after.calls.argsFor(0)).toEqual([ 1, 2, 3 ]);
expect(after.calls.argsFor(0)).toEqual([1, 2, 3]);
});
it('Test#018 : should instantly trigger the callback if the event is currently being fired.', function () {
var handler1 = jasmine.createSpy().and.callFake(function () { stickyChannel.subscribe(handler2); });
Expand Down
4 changes: 2 additions & 2 deletions test/test.pluginloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('pluginloader', function () {
it('Test#003 : should inject plugin scripts when they are not already there', function (done) {
define('cordova/plugin_list', function (require, exports, module) {
module.exports = [
{ 'file': 'some/path.js', 'id': 'some.id' }
{ file: 'some/path.js', id: 'some.id' }
];
});
injectScript.and.callFake(function (url, onload, onerror) {
Expand All @@ -94,7 +94,7 @@ describe('pluginloader', function () {
it('Test#004 : should not inject plugin scripts when they are already there', function (done) {
define('cordova/plugin_list', function (require, exports, module) {
module.exports = [
{ 'file': 'some/path.js', 'id': 'some.id' }
{ file: 'some/path.js', id: 'some.id' }
];
});
define('some.id', function (require, exports, module) {
Expand Down