From bf349a5e84b08987763d4fc87a132d5285da1614 Mon Sep 17 00:00:00 2001 From: Erisu Date: Wed, 27 Nov 2019 12:02:52 +0900 Subject: [PATCH 1/2] refactor: eslint setup --- .eslintrc.yml | 39 ++++++++++++++++++++---- Gruntfile.js | 12 ++++---- build-tools/build.js | 2 +- package.json | 12 ++------ src/.eslintrc.yml | 12 -------- src/common/argscheck.js | 12 ++++---- src/common/builder.js | 4 +-- src/cordova.js | 4 +-- test/.eslintrc.yml | 7 ----- test/test-platform-modules/.eslintrc.yml | 4 --- test/test.channel.js | 4 +-- test/test.pluginloader.js | 4 +-- 12 files changed, 57 insertions(+), 59 deletions(-) delete mode 100644 src/.eslintrc.yml delete mode 100644 test/.eslintrc.yml delete mode 100644 test/test-platform-modules/.eslintrc.yml diff --git a/.eslintrc.yml b/.eslintrc.yml index 14c1daff9..d09a864a3 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,7 +1,34 @@ +# 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' + globals: + cordova: false + + - files: [src/**/*.js, test/test-platform-modules/**/**.js] + extends: + - '@cordova/eslint-config/browser' + - plugin:es5/no-es2015 + - plugin:es5/no-es2016 + globals: + define: false + PLATFORM_VERSION_BUILD_LABEL: false diff --git a/Gruntfile.js b/Gruntfile.js index 4984ad436..bcfb46ae3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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'] }); diff --git a/build-tools/build.js b/build-tools/build.js index 0b6fc8797..3b55d128f 100644 --- a/build-tools/build.js +++ b/build-tools/build.js @@ -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); }); diff --git a/package.json b/package.json index ea0dcf232..38e344390 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", diff --git a/src/.eslintrc.yml b/src/.eslintrc.yml deleted file mode 100644 index 11dfeda49..000000000 --- a/src/.eslintrc.yml +++ /dev/null @@ -1,12 +0,0 @@ -extends: - - plugin:es5/no-es2015 - - plugin:es5/no-es2016 - -env: - node: false - commonjs: true - browser: true - -globals: - define: false - PLATFORM_VERSION_BUILD_LABEL: false diff --git a/src/common/argscheck.js b/src/common/argscheck.js index c94c5ec89..74ac7e349 100644 --- a/src/common/argscheck.js +++ b/src/common/argscheck.js @@ -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) { diff --git a/src/common/builder.js b/src/common/builder.js index 7b6dc408c..e61ff83b0 100644 --- a/src/common/builder.js +++ b/src/common/builder.js @@ -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]); } } @@ -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]); diff --git a/src/cordova.js b/src/cordova.js index c88e2f982..28df37590 100644 --- a/src/cordova.js +++ b/src/cordova.js @@ -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]; } } @@ -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; } }, diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml deleted file mode 100644 index bcbaf1e26..000000000 --- a/test/.eslintrc.yml +++ /dev/null @@ -1,7 +0,0 @@ -env: - node: false - browser: true - jasmine: true - -globals: - cordova: false diff --git a/test/test-platform-modules/.eslintrc.yml b/test/test-platform-modules/.eslintrc.yml deleted file mode 100644 index e3d49d8a0..000000000 --- a/test/test-platform-modules/.eslintrc.yml +++ /dev/null @@ -1,4 +0,0 @@ -env: - node: false - commonjs: true - browser: true diff --git a/test/test.channel.js b/test/test.channel.js index 667c70bdf..5588e4c2d 100644 --- a/test/test.channel.js +++ b/test/test.channel.js @@ -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; @@ -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); }); diff --git a/test/test.pluginloader.js b/test/test.pluginloader.js index ed5c9f926..72c37876e 100644 --- a/test/test.pluginloader.js +++ b/test/test.pluginloader.js @@ -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) { @@ -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) { From e77c823dd3edb21b54a8b595752c12d94739d603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Wed, 27 Nov 2019 12:12:17 +0100 Subject: [PATCH 2/2] Fix root .eslintrc --- .eslintrc.yml | 13 +++++++------ test/test-platform-modules/exec.js | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index d09a864a3..0e94bb6af 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -21,14 +21,15 @@ extends: '@cordova/eslint-config/node' overrides: - files: [test/**/*.js] extends: '@cordova/eslint-config/browser-tests' - globals: - cordova: false - - files: [src/**/*.js, test/test-platform-modules/**/**.js] + - 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 + - '@cordova/eslint-config/browser' + - plugin:es5/no-es2015 + - plugin:es5/no-es2016 globals: define: false PLATFORM_VERSION_BUILD_LABEL: false diff --git a/test/test-platform-modules/exec.js b/test/test-platform-modules/exec.js index 48123485d..a5ea8e8a2 100644 --- a/test/test-platform-modules/exec.js +++ b/test/test-platform-modules/exec.js @@ -19,5 +19,4 @@ * */ -/* eslint-env jasmine */ module.exports = jasmine.createSpy();