Skip to content

Commit

Permalink
Use prettier to format JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Oct 21, 2021
1 parent 1fc03d2 commit f821bc1
Show file tree
Hide file tree
Showing 68 changed files with 1,379 additions and 1,152 deletions.
39 changes: 15 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
legacyDecorators: true,
},
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
env: {
browser: true
browser: true,
},
rules: {},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.prettierrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'index.js',
Expand All @@ -36,7 +32,7 @@ module.exports = {
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js',
'lib/**/*'
'lib/**/*',
],
excludedFiles: [
'addon/**',
Expand All @@ -45,31 +41,26 @@ module.exports = {
'tests/dummy/app/**',
],
parserOptions: {
sourceType: 'script'
sourceType: 'script',
},
env: {
browser: false,
node: true
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended']
extends: ['plugin:node/recommended'],
},
{
files: [
'node-tests/**/*',
],
excludedFiles: [
'testem.multiple-test-page.js'
],
files: ['node-tests/**/*'],
excludedFiles: ['testem.multiple-test-page.js'],
parserOptions: {
ecmaVersion: 2018,
},
env: {
node: true,
mocha: true,
},
rules: {
}
}
]
rules: {},
},
],
};
25 changes: 25 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache
.lint-todo/

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
singleQuote: true,
};
2 changes: 1 addition & 1 deletion .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'recommended'
extends: 'recommended',
};
16 changes: 6 additions & 10 deletions addon-test-support/-private/async-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export default class AsyncIterator {
* @return {String} the stringified value of the iterator.
*/
toString() {
return `<AsyncIterator (request: ${this._request} response: ${
this._response
})>`;
return `<AsyncIterator (request: ${this._request} response: ${this._response})>`;
}

/**
Expand Down Expand Up @@ -113,16 +111,14 @@ export default class AsyncIterator {

if (this._emberExamExitOnError) {
let err = new Error(
`EmberExam: Promise timed out after ${
this._timeout
} s while waiting for response for ${this._request}`
`EmberExam: Promise timed out after ${this._timeout} s while waiting for response for ${this._request}`
);
reject(err);
} else {
// eslint-disable-next-line no-console
console.error(`EmberExam: Promise timed out after ${
this._timeout
} s while waiting for response for ${this._request}. Closing browser to exit gracefully.`);
console.error(
`EmberExam: Promise timed out after ${this._timeout} s while waiting for response for ${this._request}. Closing browser to exit gracefully.`
);
resolve(iteratorCompleteResponse);
}
}, this._timeout * 1000);
Expand Down Expand Up @@ -153,7 +149,7 @@ export default class AsyncIterator {
this._current = {
resolve,
reject,
promise
promise,
};

this._makeNextRequest();
Expand Down
4 changes: 2 additions & 2 deletions addon-test-support/-private/ember-exam-mocha-test-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getUrlParams from './get-url-params';
import splitTestModules from './split-test-modules';
import { filterTestModules} from './filter-test-modules';
import { filterTestModules } from './filter-test-modules';
import { TestLoader } from 'ember-mocha/test-loader';

/**
Expand Down Expand Up @@ -28,7 +28,7 @@ export default class EmberExamMochaTestLoader extends TestLoader {
* @method load
*/
static load() {
throw new Error('`EmberExamMochaTestLoader` doesn\'t support `load()`.');
throw new Error("`EmberExamMochaTestLoader` doesn't support `load()`.");
}

/**
Expand Down
11 changes: 8 additions & 3 deletions addon-test-support/-private/ember-exam-qunit-test-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class EmberExamQUnitTestLoader extends TestLoader {
* @method load
*/
static load() {
throw new Error('`EmberExamQUnitTestLoader` doesn\'t support `load()`.');
throw new Error("`EmberExamQUnitTestLoader` doesn't support `load()`.");
}

/**
Expand Down Expand Up @@ -178,8 +178,13 @@ export default class EmberExamQUnitTestLoader extends TestLoader {
return nextModuleHandler();
}
}
}).catch(e => {
if (typeof e === 'object' && e !== null && typeof e.message === 'string') {
})
.catch((e) => {
if (
typeof e === 'object' &&
e !== null &&
typeof e.message === 'string'
) {
e.message = `EmberExam: Failed to get next test module: ${e.message}`;
}
throw new Error(`EmberExam: Failed to get next test module: ${e}`);
Expand Down
44 changes: 31 additions & 13 deletions addon-test-support/-private/filter-test-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const TEST_PATH_REGEX = /\/tests\/(.*?)$/;
* @param {*} modulePath
*/
function getRegexFilter(modulePath) {
return MODULE_PATH_REGEXP.exec( modulePath );
return MODULE_PATH_REGEXP.exec(modulePath);
}

/**
Expand All @@ -23,7 +23,11 @@ function getRegexFilter(modulePath) {
*/
function wildcardFilter(module, moduleFilter) {
// Generate a regular expression to handle wildcard from path filter
const moduleFilterRule = ['^.*', moduleFilter.split('*').join('.*'), '$'].join('');
const moduleFilterRule = [
'^.*',
moduleFilter.split('*').join('.*'),
'$',
].join('');
return new RegExp(moduleFilterRule).test(module);
}

Expand All @@ -35,7 +39,10 @@ function wildcardFilter(module, moduleFilter) {
* @param {string} moduleFilter
*/
function stringFilter(modules, moduleFilter) {
return modules.filter( module => module.includes(moduleFilter) || wildcardFilter(module, moduleFilter) );
return modules.filter(
(module) =>
module.includes(moduleFilter) || wildcardFilter(module, moduleFilter)
);
}

/**
Expand All @@ -49,7 +56,9 @@ function regexFilter(modules, modulePathRegexFilter) {
const re = new RegExp(modulePathRegexFilter[2], modulePathRegexFilter[3]);
const exclude = modulePathRegexFilter[1];

return modules.filter( module => !exclude && re.test(module) || exclude && !re.test(module) );
return modules.filter(
(module) => (!exclude && re.test(module)) || (exclude && !re.test(module))
);
}

/**
Expand All @@ -60,7 +69,7 @@ function regexFilter(modules, modulePathRegexFilter) {
*/
function convertFilePathToModulePath(filePath) {
const filePathWithNoExtension = filePath.replace(/\.[^/.]+$/, '');
const testFilePathMatch = TEST_PATH_REGEX.exec( filePathWithNoExtension );
const testFilePathMatch = TEST_PATH_REGEX.exec(filePathWithNoExtension);
if (typeof filePath !== 'undefined' && testFilePathMatch !== null) {
return testFilePathMatch[0];
}
Expand All @@ -78,26 +87,35 @@ function convertFilePathToModulePath(filePath) {
*/
function filterTestModules(modules, modulePath, filePath) {
// Generates an array with module filter value seperated by comma (,).
const moduleFilters = (filePath || modulePath).split(',').map( value => value.trim());
const moduleFilters = (filePath || modulePath)
.split(',')
.map((value) => value.trim());

const filteredTestModules = moduleFilters.reduce((result, moduleFilter) => {
const modulePath = convertFilePathToModulePath(moduleFilter);
const modulePathRegex = getRegexFilter(modulePath);

if (modulePathRegex) {
return result.concat(regexFilter(modules, modulePathRegex).filter( module => result.indexOf(module) === -1 ));
return result.concat(
regexFilter(modules, modulePathRegex).filter(
(module) => result.indexOf(module) === -1
)
);
} else {
return result.concat(stringFilter(modules, modulePath).filter( module => result.indexOf(module) === -1 ));
return result.concat(
stringFilter(modules, modulePath).filter(
(module) => result.indexOf(module) === -1
)
);
}
}, []);

if (filteredTestModules.length === 0) {
throw new Error(`No tests matched with the filter: ${modulePath || filePath}.`);
throw new Error(
`No tests matched with the filter: ${modulePath || filePath}.`
);
}
return filteredTestModules;
}

export {
convertFilePathToModulePath,
filterTestModules
}
export { convertFilePathToModulePath, filterTestModules };
18 changes: 13 additions & 5 deletions addon-test-support/-private/get-test-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { dependencySatisfies, macroCondition, importSync } from '@embroider/macros';
import {
dependencySatisfies,
macroCondition,
importSync,
} from '@embroider/macros';

/**
* Returns ember-exam-qunit-test-loader or ember-exam-mocha-test-loader
Expand All @@ -8,11 +12,15 @@ import { dependencySatisfies, macroCondition, importSync } from '@embroider/macr
* @return {Object}
*/
export default function getTestLoader() {
if (macroCondition(dependencySatisfies('ember-qunit', '*'))){
const EmberExamQUnitTestLoader = importSync('./ember-exam-qunit-test-loader');
if (macroCondition(dependencySatisfies('ember-qunit', '*'))) {
const EmberExamQUnitTestLoader = importSync(
'./ember-exam-qunit-test-loader'
);
return EmberExamQUnitTestLoader['default'];
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))){
const EmberExamMochaTestLoader = importSync('./ember-exam-mocha-test-loader');
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
const EmberExamMochaTestLoader = importSync(
'./ember-exam-mocha-test-loader'
);
return EmberExamMochaTestLoader['default'];
}

Expand Down
4 changes: 2 additions & 2 deletions addon-test-support/-private/split-test-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export default function splitTestModules(modules, split, partitions) {
const partition = parseInt(partitions[i], 10);
if (isNaN(partition)) {
throw new Error(
'You must specify numbers for partition (you specified \'' +
"You must specify numbers for partition (you specified '" +
partitions +
'\')'
"')"
);
}

Expand Down
2 changes: 1 addition & 1 deletion addon-test-support/-private/weight-test-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const TEST_TYPE_WEIGHT = {
eslint: 1,
unit: 10,
integration: 20,
acceptance: 150
acceptance: 150,
};
const WEIGHT_REGEX = /\/(eslint|unit|integration|acceptance)\//;
const DEFAULT_WEIGHT = 50;
Expand Down
8 changes: 6 additions & 2 deletions addon-test-support/start.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import loadEmberExam from 'ember-exam/test-support/load';
import { dependencySatisfies, macroCondition, importSync } from '@embroider/macros';
import {
dependencySatisfies,
macroCondition,
importSync,
} from '@embroider/macros';

/**
* Equivalent to ember-qunit or ember-mocha's loadTest() except this does not create a new TestLoader instance
Expand Down Expand Up @@ -32,7 +36,7 @@ export default function start(qunitOptions) {
loadTests(testLoader);

let emberTestFramework;
if (macroCondition(dependencySatisfies('ember-qunit', '*'))){
if (macroCondition(dependencySatisfies('ember-qunit', '*'))) {
emberTestFramework = importSync('ember-qunit');
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
emberTestFramework = importSync('ember-mocha');
Expand Down
4 changes: 2 additions & 2 deletions config/deploy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-env node */
'use strict';

module.exports = function(deployTarget) {
module.exports = function (deployTarget) {
let ENV = {
build: {}
build: {},
// include other plugin configuration that applies to all deploy targets here
};

Expand Down
Loading

0 comments on commit f821bc1

Please sign in to comment.