Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Install prettier config into ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlafroscia committed Nov 27, 2017
1 parent 59a60e1 commit 24f91ec
Show file tree
Hide file tree
Showing 25 changed files with 319 additions and 287 deletions.
11 changes: 9 additions & 2 deletions .eslintrc.js
Expand Up @@ -4,15 +4,22 @@ module.exports = {
ecmaVersion: 2017,
sourceType: 'module'
},
plugins: ['ember'],
plugins: ['ember', 'prettier'],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
'plugin:ember/recommended',
'prettier'
],
env: {
'browser': true
},
rules: {
// Prettier config
'prettier/prettier': ['error', {
singleQuote: true,
printWidth: 100
}],

// Built-in Rule Config
'prefer-const': 'error'
},
Expand Down
1 change: 0 additions & 1 deletion addon/-private/promise.js
Expand Up @@ -10,7 +10,6 @@ import { Promise } from 'rsvp';
* @private
*/
export default class AJAXPromise extends Promise {

/**
* Overriding `.then` to add XHR to child promise
*
Expand Down
2 changes: 1 addition & 1 deletion addon/-private/utils/get-header.js
Expand Up @@ -15,7 +15,7 @@ export default function getHeader(headers, name) {
return; // ask for nothing, get nothing.
}

const matchedKey = A(Object.keys(headers)).find((key) => {
const matchedKey = A(Object.keys(headers)).find(key => {
return key.toLowerCase() === name.toLowerCase();
});

Expand Down
13 changes: 5 additions & 8 deletions addon/-private/utils/url-helpers.js
Expand Up @@ -10,9 +10,10 @@ const completeUrlRegex = /^(http|https)/;
* Borrowed from
* http://www.sitepoint.com/url-parsing-isomorphic-javascript/
*/
const isNode = typeof self === 'undefined'
&& typeof process !== 'undefined'
&& {}.toString.call(process) === '[object process]';
const isNode =
typeof self === 'undefined' &&
typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]';

const url = (function() {
if (isFastBoot) {
Expand Down Expand Up @@ -74,9 +75,5 @@ export function haveSameHost(a, b) {
a = parseURL(a);
b = parseURL(b);

return (
(a.protocol === b.protocol)
&& (a.hostname === b.hostname)
&& (a.port === b.port)
);
return a.protocol === b.protocol && a.hostname === b.hostname && a.port === b.port;
}
9 changes: 6 additions & 3 deletions addon/errors.js
Expand Up @@ -41,8 +41,11 @@ UnauthorizedError.prototype = Object.create(AjaxError.prototype);
* @extends AjaxError
*/
export function ForbiddenError(payload) {
AjaxError.call(this, payload,
'Request was rejected because user is not permitted to perform this operation.');
AjaxError.call(
this,
payload,
'Request was rejected because user is not permitted to perform this operation.'
);
}

ForbiddenError.prototype = Object.create(AjaxError.prototype);
Expand Down Expand Up @@ -284,5 +287,5 @@ export function isServerError(error) {
export function isSuccess(status) {
const s = parseInt(status, 10);

return s >= 200 && s < 300 || s === 304;
return (s >= 200 && s < 300) || s === 304;
}
37 changes: 17 additions & 20 deletions addon/mixins/ajax-request.js
Expand Up @@ -36,11 +36,7 @@ import { isFullURL, parseURL, haveSameHost } from 'ember-ajax/-private/utils/url
import isString from 'ember-ajax/-private/utils/is-string';
import AJAXPromise from 'ember-ajax/-private/promise';

const {
Logger,
Test,
testing
} = Ember;
const { Logger, Test, testing } = Ember;
const JSONContentType = /^application\/(?:vnd\.api\+)?json/i;

function isJSONContentType(header) {
Expand Down Expand Up @@ -105,7 +101,6 @@ if (testing) {
* @mixin
*/
export default Mixin.create({

/**
* The default value for the request `contentType`
*
Expand Down Expand Up @@ -209,9 +204,10 @@ export default Mixin.create({
const internalPromise = this._makeRequest(hash);

const ajaxPromise = new AJAXPromise((resolve, reject) => {
internalPromise.then(({ response }) => {
resolve(response);
})
internalPromise
.then(({ response }) => {
resolve(response);
})
.catch(({ response }) => {
reject(response);
});
Expand Down Expand Up @@ -275,7 +271,9 @@ export default Mixin.create({
})
.fail((jqXHR, textStatus, errorThrown) => {
runInDebug(function() {
const message = `The server returned an empty string for ${requestData.type} ${requestData.url}, which cannot be parsed into a valid JSON. Return either null or {}.`;
const message = `The server returned an empty string for ${requestData.type} ${
requestData.url
}, which cannot be parsed into a valid JSON. Return either null or {}.`;
const validJSONString = !(textStatus === 'parsererror' && jqXHR.responseText === '');

warn(message, validJSONString, {
Expand Down Expand Up @@ -391,7 +389,9 @@ export default Mixin.create({
*/
get(url) {
if (arguments.length > 1 || url.indexOf('/') !== -1) {
throw new EmberError('It seems you tried to use `.get` to make a request! Use the `.request` method instead.');
throw new EmberError(
'It seems you tried to use `.get` to make a request! Use the `.request` method instead.'
);
}
return this._super(...arguments);
},
Expand Down Expand Up @@ -438,7 +438,9 @@ export default Mixin.create({
options.url = this._buildURL(url, options);
options.type = options.type || 'GET';
options.dataType = options.dataType || 'json';
options.contentType = isEmpty(options.contentType) ? get(this, 'contentType') : options.contentType;
options.contentType = isEmpty(options.contentType)
? get(this, 'contentType')
: options.contentType;

if (this._shouldSendHeaders(options)) {
options.headers = this._getFullHeadersHash(options.headers);
Expand Down Expand Up @@ -545,12 +547,7 @@ export default Mixin.create({
} else if (this.isServerError(status, headers, payload)) {
error = new ServerError(payload);
} else {
const detailedMessage = this.generateDetailedMessage(
status,
headers,
payload,
requestData
);
const detailedMessage = this.generateDetailedMessage(status, headers, payload, requestData);

error = new AjaxError(payload, detailedMessage);
}
Expand Down Expand Up @@ -607,7 +604,7 @@ export default Mixin.create({
// Add headers on relative URLs
if (!isFullURL(url)) {
return true;
} else if (trustedHosts.find((matcher) => this._matchHosts(hostname, matcher))) {
} else if (trustedHosts.find(matcher => this._matchHosts(hostname, matcher))) {
return true;
}

Expand Down Expand Up @@ -791,7 +788,7 @@ export default Mixin.create({
parseErrorResponse(responseText) {
try {
return JSON.parse(responseText);
} catch(e) {
} catch (e) {
return responseText;
}
},
Expand Down
1 change: 0 additions & 1 deletion addon/mixins/ajax-support.js
Expand Up @@ -3,7 +3,6 @@ import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';

export default Mixin.create({

/**
* The AJAX service to send requests through
*
Expand Down
2 changes: 1 addition & 1 deletion addon/utils/ajax.js
Expand Up @@ -3,4 +3,4 @@ import $ from 'jquery';

import isFastBoot from 'ember-ajax/-private/utils/is-fastboot';

export default isFastBoot ? najax : $.ajax;
export default (isFastBoot ? najax : $.ajax);
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -48,8 +48,11 @@
"ember-resolver": "4.5.0",
"ember-source": "~2.16.0",
"eslint": "^4.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-ember": "^5.0.1",
"eslint-plugin-prettier": "^2.3.1",
"loader.js": "^4.4.0",
"prettier": "^1.8.2",
"testdouble": "3.2.6",
"testdouble-chai": "^0.5.0"
},
Expand Down
14 changes: 6 additions & 8 deletions tests/acceptance/ajax-get-test.js
@@ -1,9 +1,4 @@
import {
describe,
beforeEach,
afterEach,
it
} from 'mocha';
import { describe, beforeEach, afterEach, it } from 'mocha';
import { expect } from 'chai';

import destroyApp from 'dummy/tests/helpers/destroy-app';
Expand Down Expand Up @@ -58,8 +53,11 @@ describe('Acceptance | ajax-get component', function() {
click('button:contains(Load Data)');

andThen(function() {
expect(find('.ajax-get .error').text().trim()).to.equal(errorMessage);
expect(
find('.ajax-get .error')
.text()
.trim()
).to.equal(errorMessage);
});
});
});

16 changes: 7 additions & 9 deletions tests/acceptance/ember-data-integration-test.js
@@ -1,9 +1,4 @@
import {
describe,
beforeEach,
afterEach,
it
} from 'mocha';
import { describe, beforeEach, afterEach, it } from 'mocha';
import { assert } from 'chai';

const { equal } = assert;
Expand Down Expand Up @@ -48,9 +43,12 @@ describe('Acceptance | ember data integration', function() {
});

it('can set the namespace for all ajax requests', function() {
application.register('service:ajaxWithNs', AjaxService.extend({
namespace: 'api'
}));
application.register(
'service:ajaxWithNs',
AjaxService.extend({
namespace: 'api'
})
);
application.inject('adapter:application', 'ajaxService', 'service:ajaxWithNs');

server.get('/api/posts/1', function() {
Expand Down
7 changes: 4 additions & 3 deletions tests/dummy/app/components/ajax-get.js
Expand Up @@ -15,14 +15,15 @@ export default Component.extend({
load() {
const url = this.get('url');

return this.get('ajax').request(url)
.then((data) => {
return this.get('ajax')
.request(url)
.then(data => {
this.setProperties({
data,
isLoaded: true
});
})
.catch((error) => {
.catch(error => {
this.set('error', error.payload);
});
}
Expand Down
7 changes: 1 addition & 6 deletions tests/dummy/config/targets.js
@@ -1,9 +1,4 @@
/* eslint-env node */
module.exports = {
browsers: [
'ie 9',
'last 1 Chrome versions',
'last 1 Firefox versions',
'last 1 Safari versions'
]
browsers: ['ie 9', 'last 1 Chrome versions', 'last 1 Firefox versions', 'last 1 Safari versions']
};
6 changes: 1 addition & 5 deletions tests/helpers/json.js
@@ -1,9 +1,5 @@
export function jsonResponse(status = 200, payload = {}) {
return [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(payload)
];
return [status, { 'Content-Type': 'application/json' }, JSON.stringify(payload)];
}

export function jsonFactory(status, payload) {
Expand Down
7 changes: 1 addition & 6 deletions tests/integration/components/ajax-get-test.js
@@ -1,10 +1,5 @@
import { setupComponentTest } from 'ember-mocha';
import {
beforeEach,
afterEach,
it,
describe
} from 'mocha';
import { beforeEach, afterEach, it, describe } from 'mocha';
import { expect } from 'chai';

import Pretender from 'pretender';
Expand Down

0 comments on commit 24f91ec

Please sign in to comment.