refactor: eslint setup (#493)
* replace eslint dependencies with @cordova/eslint-config
* update eslint config
* eslint corrections
* combine testing and core configs
diff --git a/.eslintrc.yml b/.eslintrc.yml
index f6aae32..5e6a880 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -1,10 +1,23 @@
+# 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
- padded-blocks: off
- operator-linebreak: off
- no-throw-literal: off
+extends: '@cordova/eslint-config/node'
+
+overrides:
+ - files: [spec/**/*.js]
+ extends: '@cordova/eslint-config/node-tests'
diff --git a/package.json b/package.json
index 6d8d4d1..65ce423 100644
--- a/package.json
+++ b/package.json
@@ -11,8 +11,8 @@
"cordova": "./bin/cordova"
},
"scripts": {
- "test": "npm run eslint && npm run cover",
- "eslint": "eslint . bin/cordova",
+ "test": "npm run lint && npm run cover",
+ "lint": "eslint . bin/cordova",
"cover": "nyc jasmine"
},
"repository": {
@@ -41,13 +41,7 @@
"update-notifier": "^2.5.0"
},
"devDependencies": {
- "eslint": "^5.15.2",
- "eslint-config-semistandard": "^13.0.0",
- "eslint-config-standard": "^12.0.0",
- "eslint-plugin-import": "^2.16.0",
- "eslint-plugin-node": "^8.0.1",
- "eslint-plugin-promise": "^4.0.1",
- "eslint-plugin-standard": "^4.0.0",
+ "@cordova/eslint-config": "^2.0.0",
"jasmine": "^3.5.0",
"mock-stdin": "^0.3.1",
"nyc": "^14.1.1",
diff --git a/spec/.eslintrc.yaml b/spec/.eslintrc.yaml
deleted file mode 100644
index 6afba65..0000000
--- a/spec/.eslintrc.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-env:
- jasmine: true
\ No newline at end of file
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index 700240b..66530f5 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -80,37 +80,37 @@
it('Test#005 : will call command with all arguments passed through', () => {
return cli(['node', 'cordova', 'build', 'blackberry10', '--', '-k', 'abcd1234']).then(() => {
- expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { argv: ['-k', 'abcd1234'] }, verbose: false, silent: false, nohooks: [ ], searchpath: undefined });
+ expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { argv: ['-k', 'abcd1234'] }, verbose: false, silent: false, nohooks: [], searchpath: undefined });
});
}, 60000);
it('Test#006 : will consume the first instance of -d', () => {
return cli(['node', 'cordova', '-d', 'build', 'blackberry10', '--', '-k', 'abcd1234', '-d']).then(() => {
- expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false, nohooks: [ ], searchpath: undefined });
+ expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false, nohooks: [], searchpath: undefined });
});
});
it('Test#007 : will consume the first instance of --verbose', () => {
return cli(['node', 'cordova', '--verbose', 'build', 'blackberry10', '--', '-k', 'abcd1234', '--verbose']).then(() => {
- expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent: false, nohooks: [ ], searchpath: undefined });
+ expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent: false, nohooks: [], searchpath: undefined });
});
});
it('Test#008 : will consume the first instance of either --verbose or -d', () => {
return cli(['node', 'cordova', '--verbose', 'build', 'blackberry10', '--', '-k', 'abcd1234', '-d']).then(() => {
- expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false, nohooks: [ ], searchpath: undefined });
+ expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false, nohooks: [], searchpath: undefined });
});
});
it('Test#009 : will consume the first instance of either --verbose or -d', () => {
return cli(['node', 'cordova', '-d', 'build', 'blackberry10', '--', '-k', 'abcd1234', '--verbose']).then(() => {
- expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent: false, nohooks: [ ], searchpath: undefined });
+ expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent: false, nohooks: [], searchpath: undefined });
});
});
it('Test#010 : will consume the first instance of --silent', () => {
return cli(['node', 'cordova', '--silent', 'build', 'blackberry10', '--', '-k', 'abcd1234', '--silent']).then(() => {
- expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { silent: true, argv: ['-k', 'abcd1234', '--silent'] }, verbose: false, silent: true, nohooks: [ ], searchpath: undefined });
+ expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { silent: true, argv: ['-k', 'abcd1234', '--silent'] }, verbose: false, silent: true, nohooks: [], searchpath: undefined });
});
});
});
@@ -342,7 +342,6 @@
});
describe('platform', () => {
-
beforeEach(() => {
spyOn(cordova, 'platform').and.returnValue(Promise.resolve());
});
@@ -471,7 +470,6 @@
expect(logger.results).toHaveBeenCalledWith(expectedOutput);
});
});
-
});
describe('requirements', () => {
diff --git a/src/cli.js b/src/cli.js
index 93d9208..7288d22 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -40,41 +40,41 @@
const NODE_VERSION_DEPRECATING_RANGE = '<10';
var knownOpts = {
- 'verbose': Boolean,
- 'version': Boolean,
- 'help': Boolean,
- 'silent': Boolean,
- 'experimental': Boolean,
- 'noregistry': Boolean,
- 'nohooks': Array,
- 'shrinkwrap': Boolean,
+ verbose: Boolean,
+ version: Boolean,
+ help: Boolean,
+ silent: Boolean,
+ experimental: Boolean,
+ noregistry: Boolean,
+ nohooks: Array,
+ shrinkwrap: Boolean,
'link-to': path,
- 'searchpath': String,
- 'variable': Array,
- 'link': Boolean,
- 'force': Boolean,
+ searchpath: String,
+ variable: Array,
+ link: Boolean,
+ force: Boolean,
'save-exact': Boolean,
// Flags to be passed to `cordova build/run/emulate`
- 'debug': Boolean,
- 'release': Boolean,
- 'archs': String,
- 'device': Boolean,
- 'emulator': Boolean,
- 'target': String,
- 'noprepare': Boolean,
- 'nobuild': Boolean,
- 'list': Boolean,
- 'buildConfig': String,
- 'template': String,
- 'production': Boolean,
- 'noprod': Boolean
+ debug: Boolean,
+ release: Boolean,
+ archs: String,
+ device: Boolean,
+ emulator: Boolean,
+ target: String,
+ noprepare: Boolean,
+ nobuild: Boolean,
+ list: Boolean,
+ buildConfig: String,
+ template: String,
+ production: Boolean,
+ noprod: Boolean
};
var shortHands = {
- 'd': '--verbose',
- 'v': '--version',
- 'h': '--help',
- 't': '--template'
+ d: '--verbose',
+ v: '--version',
+ h: '--help',
+ t: '--template'
};
function checkForUpdates () {
@@ -219,7 +219,6 @@
}
function handleTelemetryCmd (subcommand, isOptedIn) {
-
if (subcommand !== 'on' && subcommand !== 'off') {
logger.subscribe(events);
printHelp('telemetry');
@@ -258,7 +257,6 @@
}
function cli (inputArgs) {
-
checkForUpdates();
var args = nopt(knownOpts, shortHands, inputArgs);
@@ -344,7 +342,7 @@
return printHelp(remain);
}
- if (!cordova.hasOwnProperty(cmd)) {
+ if (!Object.prototype.hasOwnProperty.call(cordova, cmd)) {
var msg2 = 'Cordova does not know ' + cmd + '; try `' + cordova_lib.binname +
' help` for a list of all the available commands.';
throw new CordovaError(msg2);
@@ -361,7 +359,6 @@
var platformCommands = ['emulate', 'build', 'prepare', 'compile', 'run', 'clean'];
if (platformCommands.indexOf(cmd) !== -1) {
-
// All options without dashes are assumed to be platform names
opts.platforms = undashed.slice(1);
@@ -372,14 +369,12 @@
return cordova.targets.call(null, opts);
}
return cordova[cmd].call(null, opts);
-
} else if (cmd === 'requirements') {
// All options without dashes are assumed to be platform names
opts.platforms = undashed.slice(1);
return cordova[cmd].call(null, opts.platforms)
.then(function (platformChecks) {
-
var someChecksFailed = Object.keys(platformChecks).map(function (platformName) {
events.emit('log', '\nRequirements check results for ' + platformName + ':');
var platformCheck = platformChecks[platformName];
@@ -488,7 +483,6 @@
template: 'template' in args,
link: 'link-to' in args
};
-
}
return cordovaCreate(dir, id, name, cfg, events || undefined);
}
diff --git a/src/telemetry.js b/src/telemetry.js
index f307e67..a509930 100644
--- a/src/telemetry.js
+++ b/src/telemetry.js
@@ -30,7 +30,9 @@
*/
class RelentlessInsight extends Insight {
get optOut () { return false; }
+
set optOut (value) { super.optOut = value; }
+
get realOptOut () { return super.optOut; }
}