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 #822

Merged
merged 2 commits into from
Nov 15, 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
10 changes: 2 additions & 8 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
root: true
extends: semistandard
extends: '@cordova/eslint-config/node'

rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
linebreak-style:
- error
- unix
Expand Down
6 changes: 2 additions & 4 deletions integration-tests/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
env:
jasmine: true
rules:
prefer-promise-reject-errors: off
root: true
extends: '@cordova/eslint-config/node-tests'
2 changes: 1 addition & 1 deletion integration-tests/HooksRunner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe('HooksRunner', function () {

const expectedContext = toPlainObject({
cordova: {
platforms: [ 'android' ],
platforms: ['android'],
plugins: [testPlugin],
version: require('../package').version
},
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const TIMEOUT = 60 * 1000;
var plugins_dir = path.join(__dirname, '..', 'spec', 'plugman', 'plugins');

var plugins = {
'Test1': path.join(plugins_dir, 'dependencies', 'Test1'),
'Test2': path.join(plugins_dir, 'dependencies', 'Test2'),
'Test3': path.join(plugins_dir, 'dependencies', 'Test3'),
'Test4': path.join(plugins_dir, 'dependencies', 'Test4')
Test1: path.join(plugins_dir, 'dependencies', 'Test1'),
Test2: path.join(plugins_dir, 'dependencies', 'Test2'),
Test3: path.join(plugins_dir, 'dependencies', 'Test3'),
Test4: path.join(plugins_dir, 'dependencies', 'Test4')
};

describe('end-to-end plugin dependency tests', function () {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('end-to-end plugin dependency tests', function () {
})
.then(function () {
expect(path.join(pluginsDir, 'cordova-plugin-file')).toExist();
return cordova.plugin('add', plugins['Test1'], { 'force': true });
return cordova.plugin('add', plugins['Test1'], { force: true });
})
.then(function () {
expect(path.join(pluginsDir, 'Test1')).toExist();
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/pkgJson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ describe('pkgJson', function () {
const PLATFORM = 'ios';
const PLUGIN = 'cordova-plugin-splashscreen';

setPkgJson('cordova.platforms', [ PLATFORM ]);
setPkgJson('cordova.platforms', [PLATFORM]);
setPkgJson('dependencies', {
[PLUGIN]: '^3.2.2',
[`cordova-${PLATFORM}`]: '^4.5.4'
Expand All @@ -424,7 +424,7 @@ describe('pkgJson', function () {

return cordova.platform('add', PLATFORM, { save: true }).then(function () {
// No change to pkg.json platforms or spec for ios.
expect(getPkgJson('cordova.platforms')).toEqual([ PLATFORM ]);
expect(getPkgJson('cordova.platforms')).toEqual([PLATFORM]);
// Config.xml and ios/cordova/version check.
const version = platformVersion(PLATFORM);
// Check that pkg.json and ios/cordova/version versions "satisfy" each other.
Expand Down Expand Up @@ -476,7 +476,7 @@ describe('pkgJson', function () {
const PLATFORM = 'ios';
const PLUGIN = 'cordova-plugin-splashscreen';

setPkgJson('cordova.platforms', [ PLATFORM ]);
setPkgJson('cordova.platforms', [PLATFORM]);
setPkgJson('dependencies', {
[`cordova-${PLATFORM}`]: '^4.2.1',
[PLUGIN]: '^3.2.2'
Expand All @@ -490,7 +490,7 @@ describe('pkgJson', function () {

return cordova.platform('add', `${PLATFORM}@4.5.4`, { save: true }).then(function () {
// Pkg.json has ios.
expect(getPkgJson('cordova.platforms')).toEqual([ PLATFORM ]);
expect(getPkgJson('cordova.platforms')).toEqual([PLATFORM]);
}).then(function () {
return cordova.plugin('add', `${PLUGIN}@4.0.0`, { save: true });
}).then(function () {
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/platform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ describe('cordova/platform end-to-end', () => {
expect(testPlatformDir).not.toExist();
expect(installedPlatforms()).toEqual([]);
});

});

it('Test 002 : should install plugins correctly while adding platform', () => {
Expand Down Expand Up @@ -128,7 +127,7 @@ describe('cordova/platform end-to-end', () => {
it('Test 007 : should add and remove platform from node_modules directory', () => {
return Promise.resolve()
.then(() => {
return cordova.platform('add', 'browser', { 'save': true });
return cordova.platform('add', 'browser', { save: true });
})
.then(() => {
expect(path.join(nodeModulesDir, 'cordova-browser')).toExist();
Expand Down
1 change: 0 additions & 1 deletion integration-tests/plugman_fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ describe('fetch', function () {
});

describe('fetch recursive error CB-8809', function () {

var srcDir = path.join(plugins_dir, 'recursivePlug');
var appDir = path.join(plugins_dir, 'recursivePlug', 'demo');
fetch.__set__('fetch', function (pluginDir) {
Expand Down
12 changes: 4 additions & 8 deletions integration-tests/plugman_uninstall.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const plugins_install_dir = path.join(project, 'cordova/plugins');
const plugins_dir = path.join(__dirname, '../spec/plugman/plugins');
const plugins = {
'org.test.plugins.dummyplugin': path.join(plugins_dir, 'org.test.plugins.dummyplugin'),
'A': path.join(plugins_dir, 'dependencies', 'A'),
'C': path.join(plugins_dir, 'dependencies', 'C')
A: path.join(plugins_dir, 'dependencies', 'A'),
C: path.join(plugins_dir, 'dependencies', 'C')
};

function setupProject (name) {
Expand Down Expand Up @@ -97,7 +97,6 @@ describe('plugman/uninstall', () => {
});

describe('success', function () {

it('Test 002 : should get PlatformApi instance for platform and invoke its\' removePlugin method', function () {
const platformApi = { removePlugin: jasmine.createSpy('removePlugin').and.returnValue(Promise.resolve()) };
const getPlatformApi = spyOn(platforms, 'getPlatformApi').and.returnValue(platformApi);
Expand Down Expand Up @@ -139,9 +138,9 @@ describe('plugman/uninstall', () => {
}, Promise.resolve());
}

return validateReturnedResultFor([ true, {}, [], 'foo', function () {} ], true)
return validateReturnedResultFor([true, {}, [], 'foo', function () {}], true)
.then(function () {
return validateReturnedResultFor([ false, null, undefined, '' ], false);
return validateReturnedResultFor([false, null, undefined, ''], false);
});
});

Expand Down Expand Up @@ -175,9 +174,7 @@ describe('plugman/uninstall', () => {
});

describe('uninstallPlugin', function () {

describe('with dependencies', function () {

it('Test 006 : should delete all dependent plugins', function () {
setupProject('uninstall.test');

Expand Down Expand Up @@ -242,7 +239,6 @@ describe('plugman/uninstall', () => {
});

describe('uninstall', function () {

beforeEach(() => {
setupProject('uninstall.test');
});
Expand Down
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,18 @@
"semver": "^6.3.0"
},
"devDependencies": {
"@cordova/eslint-config": "^2.0.0",
"codecov": "^3.2.0",
"cordova-android": "^8.1.0",
"delay": "^4.1.0",
"eslint": "^5.15.1",
"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",
"jasmine": "^3.5.0",
"jasmine-spec-reporter": "^4.2.1",
"nyc": "^14.1.1",
"rewire": "^4.0.1"
},
"scripts": {
"test": "npm run eslint && npm run unit-tests && npm run e2e-tests",
"eslint": "eslint .",
"test": "npm run lint && npm run unit-tests && npm run e2e-tests",
"lint": "eslint .",
"unit-tests": "jasmine \"spec/**/*.spec.js\"",
"cover": "nyc -x spec/ -x integration-tests/ npm test",
"report-coverage": "nyc report -r text-lcov > coverage.lcov && codecov",
Expand Down
6 changes: 2 additions & 4 deletions spec/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
env:
jasmine: true
rules:
prefer-promise-reject-errors: off
root: true
extends: '@cordova/eslint-config/node-tests'
4 changes: 2 additions & 2 deletions spec/cordova/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('build command', function () {
describe('success', function () {
it('Test 003 : should run inside a Cordova-based project with at least one added platform and call both prepare and compile', function () {
return cordovaBuild(['android', 'ios']).then(function () {
var opts = Object({ platforms: [ 'android', 'ios' ], verbose: false, options: Object({ }) });
var opts = Object({ platforms: ['android', 'ios'], verbose: false, options: Object({ }) });
expect(cordovaPrepare).toHaveBeenCalledWith(opts);
expect(cordovaCompile).toHaveBeenCalledWith(opts);
});
Expand All @@ -93,7 +93,7 @@ describe('build command', function () {
it('Test 007 : should fire after hooks through the hooker module', function () {
return cordovaBuild('android').then(function () {
expect(HooksRunner.prototype.fire.calls.argsFor(1))
.toEqual([ 'after_build', { platforms: [ 'android' ], verbose: false, options: {} } ]);
.toEqual(['after_build', { platforms: ['android'], verbose: false, options: {} }]);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/emulate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('emulate command', function () {
const expectedBuildOptions = Object.assign({ couldBeModified: 'insideBuild' }, baseOptions);
return cordovaEmulate({ platforms: ['blackberry10'], options: { password: '1q1q' } })
.then(function () {
expect(cordovaPrepare).toHaveBeenCalledWith({ platforms: [ 'blackberry10' ], options: expectedBuildOptions, verbose: false });
expect(cordovaPrepare).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: expectedBuildOptions, verbose: false });
expect(platformApi.build).toHaveBeenCalledWith(expectedBuildOptions);
expect(platformApi.run).toHaveBeenCalledWith(expectedRunOptions);
});
Expand Down
14 changes: 6 additions & 8 deletions spec/cordova/platform/addHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('cordova/platform/addHelper', function () {

beforeEach(function () {
fake_platform = {
'platform': 'atari'
platform: 'atari'
};
package_json_mock = {
cordova: {},
Expand Down Expand Up @@ -185,7 +185,6 @@ describe('cordova/platform/addHelper', function () {
});

describe('platform api invocation', function () {

it('should invoke the createPlatform platform API method when adding a platform, providing destination location, parsed config file and platform detail options as arguments', function () {
return platform_addHelper('add', hooks_mock, projectRoot, ['ios'], { save: true, restoring: true }).then(function (result) {
expect(platform_api_mock.createPlatform).toHaveBeenCalled();
Expand All @@ -202,12 +201,11 @@ describe('cordova/platform/addHelper', function () {
});

describe('after platform api invocation', function () {

describe('when the restoring option is not provided', function () {
it('should invoke preparePlatforms twice (?!?), once before installPluginsForNewPlatforms and once after... ?!', function () {
const preparePlatforms = platform_addHelper.__get__('preparePlatforms');
return platform_addHelper('add', hooks_mock, projectRoot, ['atari'], { save: true }).then(function (result) {
expect(preparePlatforms).toHaveBeenCalledWith([ 'atari' ], '/some/path', { searchpath: undefined });
expect(preparePlatforms).toHaveBeenCalledWith(['atari'], '/some/path', { searchpath: undefined });
});
});
});
Expand All @@ -228,7 +226,7 @@ describe('cordova/platform/addHelper', function () {
return false;
}
});
package_json_mock.cordova = { 'platforms': ['ios'] };
package_json_mock.cordova = { platforms: ['ios'] };
cordova_util.requireNoCache.and.returnValue(package_json_mock);
return platform_addHelper('add', hooks_mock, projectRoot, ['android'], { save: true, restoring: true }).then(function (result) {
expect(fs.writeFileSync).toHaveBeenCalled();
Expand All @@ -237,7 +235,7 @@ describe('cordova/platform/addHelper', function () {

it('should use pkgJson version devDependencies, if dependencies are undefined', function () {
package_json_mock.dependencies = undefined;
package_json_mock.cordova = { 'platforms': ['ios'] };
package_json_mock.cordova = { platforms: ['ios'] };
package_json_mock.devDependencies['ios'] = {};
cordova_util.requireNoCache.and.returnValue(package_json_mock);
fs.existsSync.and.callFake(function (filePath) {
Expand All @@ -251,7 +249,7 @@ describe('cordova/platform/addHelper', function () {
});

it('should only write the package.json file if it was modified', function () {
package_json_mock.cordova = { 'platforms': ['ios'] };
package_json_mock.cordova = { platforms: ['ios'] };
cordova_util.requireNoCache.and.returnValue(package_json_mock);
return platform_addHelper('add', hooks_mock, projectRoot, ['ios'], { save: true, restoring: true }).then(function (result) {
expect(fs.writeFileSync).not.toHaveBeenCalled();
Expand All @@ -272,7 +270,7 @@ describe('cordova/platform/addHelper', function () {
});
describe('errors', function () {
it('should reject the promise should fetch fail', function () {
fetch_mock.and.returnValue(Promise.reject('fetch has failed, rejecting promise'));
fetch_mock.and.returnValue(Promise.reject(new Error('fetch has failed, rejecting promise')));
return platform_addHelper.downloadPlatform(projectRoot, 'android', '67').then(function () {
fail('success handler unexpectedly invoked');
}, function (e) {
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/platform/remove.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('cordova/platform/remove', function () {
});

it('should remove from package.json', function () {
package_json_mock.cordova = { 'platforms': ['atari'] };
package_json_mock.cordova = { platforms: ['atari'] };
cordova_util.requireNoCache.and.returnValue(package_json_mock);
spyOn(fs, 'readFileSync').and.returnValue('file');
fs.existsSync.and.callFake(function (filePath) {
Expand Down
Loading