Skip to content

Commit

Permalink
refactor: eslint setup
Browse files Browse the repository at this point in the history
* replace eslint dependencies with @cordova/eslint-config
* update eslint config
* eslint corrections
* combine testing and core configs
  • Loading branch information
erisu committed Nov 19, 2019
1 parent 11ce340 commit ad2f896
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 64 deletions.
31 changes: 22 additions & 9 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions spec/.eslintrc.yaml

This file was deleted.

14 changes: 6 additions & 8 deletions spec/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,37 @@ describe('cordova cli', () => {

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 });
});
});
});
Expand Down Expand Up @@ -342,7 +342,6 @@ describe('cordova cli', () => {
});

describe('platform', () => {

beforeEach(() => {
spyOn(cordova, 'platform').and.returnValue(Promise.resolve());
});
Expand Down Expand Up @@ -471,7 +470,6 @@ describe('cordova cli', () => {
expect(logger.results).toHaveBeenCalledWith(expectedOutput);
});
});

});

describe('requirements', () => {
Expand Down
66 changes: 30 additions & 36 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,41 @@ const NODE_VERSION_REQUIREMENT = '>=8';
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 () {
Expand Down Expand Up @@ -219,7 +219,6 @@ function printHelp (command) {
}

function handleTelemetryCmd (subcommand, isOptedIn) {

if (subcommand !== 'on' && subcommand !== 'off') {
logger.subscribe(events);
printHelp('telemetry');
Expand Down Expand Up @@ -258,7 +257,6 @@ function handleTelemetryCmd (subcommand, isOptedIn) {
}

function cli (inputArgs) {

checkForUpdates();

var args = nopt(knownOpts, shortHands, inputArgs);
Expand Down Expand Up @@ -344,7 +342,7 @@ function cli (inputArgs) {
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);
Expand All @@ -361,7 +359,6 @@ function cli (inputArgs) {

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);

Expand All @@ -372,14 +369,12 @@ function cli (inputArgs) {
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];
Expand Down Expand Up @@ -488,7 +483,6 @@ function create ([_, dir, id, name], args) {
template: 'template' in args,
link: 'link-to' in args
};

}
return cordovaCreate(dir, id, name, cfg, events || undefined);
}
2 changes: 2 additions & 0 deletions src/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ var Insight = require('insight');
*/
class RelentlessInsight extends Insight {
get optOut () { return false; }

set optOut (value) { super.optOut = value; }

get realOptOut () { return super.optOut; }
}

Expand Down

0 comments on commit ad2f896

Please sign in to comment.