Skip to content

Commit

Permalink
Merge pull request #362 from funkensturm/improve-linting
Browse files Browse the repository at this point in the history
Improve Linting
  • Loading branch information
fsmanuel authored Sep 4, 2022
2 parents a713b7c + 8263618 commit ce5ee63
Show file tree
Hide file tree
Showing 65 changed files with 1,148 additions and 1,080 deletions.
12 changes: 2 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,18 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:ember/recommended',
// 'plugin:prettier/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true
browser: true,
},
rules: {
'ember/avoid-leaking-state-in-ember-objects': 'off',
'ember/no-actions-hash': 'off',
'ember/no-classic-classes': 'off',
'ember/no-classic-components': 'off',
'ember/no-component-lifecycle-hooks': 'off',
'ember/no-get': 'off',
'ember/no-jquery': 'off',
'ember/no-mixins': 'off',
'ember/no-new-mixins': 'off',
'ember/no-string-prototype-extensions': 'off',
'ember/require-tagless-components': 'off',
'ember/require-super-in-lifecycle-hooks': 'off',
'ember/use-ember-data-rfc-395-imports': 'off',
},
overrides: [
Expand Down Expand Up @@ -63,9 +57,7 @@ module.exports = {
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: {
'qunit/no-assert-equal-boolean': 'off',
'qunit/no-conditional-assertions': 'off',
'qunit/no-ok-equality': 'off',
},
},
],
Expand Down
17 changes: 1 addition & 16 deletions .template-lintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,5 @@

module.exports = {
extends: 'recommended',
rules: {
// TODO: Remove over time
'link-href-attributes': false,
'no-action': false,
'no-curly-component-invocation': false,
'no-implicit-this': false,
'no-inline-styles': false,
'no-invalid-interactive': false,
'no-link-to-positional-params': false,
'no-partial': false,
'no-unbalanced-curlies': false,
'require-button-type': false,
'require-iframe-title': false,
'require-input-label': false,
'require-valid-alt-text': false,
},
rules: {},
};
124 changes: 59 additions & 65 deletions addon/adapters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,75 @@ import { _buildKey } from '../helpers/storage';

const getKeys = Object.keys || keys;

const {
JSONAPIAdapter
} = DS;
const { JSONAPIAdapter } = DS;

// Ember data ships with ember-inflector
import { singularize, pluralize } from 'ember-inflector';

export default JSONAPIAdapter.extend(ImportExportMixin, {
_debug: false,
_indices: computed(function() { return {}; }),
_indices: computed(function () {
return {};
}),
coalesceFindRequests: false,

// TODO: v2.0 - What are the defaults now? What versions to support?
isNewSerializerAPI: true,

// TODO: v2.0 - Can we deprecate or remove that? What are the defaults now? What versions to support?
// Reload behavior
shouldReloadRecord() { return true; },
shouldReloadAll() { return true; },
shouldBackgroundReloadRecord() { return true; },
shouldBackgroundReloadAll() { return true; },
shouldReloadRecord() {
return true;
},
shouldReloadAll() {
return true;
},
shouldBackgroundReloadRecord() {
return true;
},
shouldBackgroundReloadAll() {
return true;
},

generateIdForRecord() {
return Math.random().toString(32).slice(2).substr(0, 8);
},

// Relationship sugar
createRecord(store, type, snapshot) {
snapshot.eachRelationship(function(name, relationship) {
const {
kind,
options
} = relationship;
snapshot.eachRelationship(function (name, relationship) {
const { kind, options } = relationship;

if (kind === 'belongsTo' && options.autoSave) {
snapshot.record.get(name)
.then(function(record) {
if (record) {
record.save();
}
});
snapshot.record.get(name).then(function (record) {
if (record) {
record.save();
}
});
}
});

return this._super.apply(this, arguments);
},

deleteRecord(store, type, snapshot) {
snapshot.eachRelationship(function(name, relationship) {
const {
kind,
options
} = relationship;
snapshot.eachRelationship(function (name, relationship) {
const { kind, options } = relationship;

if (kind === 'hasMany' && options.dependent === 'destroy') {
snapshot.record.get(name)
.then(function(records) {
records.forEach(function(record) {
record.destroyRecord();
});
snapshot.record.get(name).then(function (records) {
records.forEach(function (record) {
record.destroyRecord();
});
});
}

if (kind === 'belongsTo' && options.autoSave) {
snapshot.record.get(name)
.then(function(record) {
if (record) {
record.save();
}
});
snapshot.record.get(name).then(function (record) {
if (record) {
record.save();
}
});
}
});

Expand All @@ -100,10 +99,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
records = this.ajax(url, 'GET', { data: query });
}

return records
.then(function(result) {
return {data: result.data[0] || null};
});
return records.then(function (result) {
return { data: result.data[0] || null };
});
},

// TODO: v2.0 - What are the defaults now? What versions to support?
Expand All @@ -114,11 +112,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

// Delegate to _handleStorageRequest
makeRequest(request) {
return this._handleStorageRequest(
request.url,
request.method,
{ data: request.data }
);
return this._handleStorageRequest(request.url, request.method, {
data: request.data,
});
},

// Work arround ds-improved-ajax Feature Flag
Expand All @@ -141,13 +137,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
const handler = this[`_handle${type}Request`];
if (handler) {
const data = handler.call(this, url, options.data);
run(null, resolve, {data: data});
run(null, resolve, { data: data });
} else {
run(
null,
reject,
`There is nothing to handle _handle${type}Request`
);
run(null, reject, `There is nothing to handle _handle${type}Request`);
}
}, 'DS: LocalStorageAdapter#_handleStorageRequest ' + type + ' to ' + url);
},
Expand All @@ -159,16 +151,16 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

if (id) {
if (!storage[storageKey]) {
throw this.handleResponse(404, {}, "Not found", { url, method: 'GET' });
throw this.handleResponse(404, {}, 'Not found', { url, method: 'GET' });
}
return JSON.parse(storage[storageKey]);
}

const records = this._getIndex(type)
.filter(function(storageKey) {
.filter(function (storageKey) {
return storage[storageKey];
})
.map(function(storageKey) {
.map(function (storageKey) {
return JSON.parse(storage[storageKey]);
});

Expand Down Expand Up @@ -257,18 +249,21 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
} else if (queryType === 'array') {
// belongsTo
if (dataType === 'object') {
const queryMessage = query.map(function(item) {
return getKeys(item).map(function(key) {
return key + ': ' + item[key];
});
}).join(', ');
const queryMessage = query
.map(function (item) {
return getKeys(item).map(function (key) {
return key + ': ' + item[key];
});
})
.join(', ');

throw new Error(
'You can not provide an array with a belongsTo relation. ' +
'Query: ' + queryMessage
'Query: ' +
queryMessage
);

// hasMany
// hasMany
} else {
return query.every((queryValue) => {
return this._queryFilter(data, serializer, queryValue);
Expand All @@ -279,7 +274,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
if (dataType === 'object') {
return this._matches(data.id, query);

// hasMany
// hasMany
} else {
return data.some((record) => {
return this._queryFilter(record, serializer, query);
Expand Down Expand Up @@ -312,7 +307,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

return {
type: type,
id: id
id: id,
};
},

Expand All @@ -322,8 +317,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

// Should be overwriten
// Signature: _getIndex(type)
_getIndex() {
},
_getIndex() {},

_indexHasKey(type, id) {
return this._getIndex(type).indexOf(id) !== -1;
Expand All @@ -337,5 +331,5 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

_removeFromIndex(type, id) {
this._getIndex(type).removeObject(id);
}
},
});
6 changes: 2 additions & 4 deletions addon/adapters/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export default BaseAdapter.extend({
if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);

indices[type] = StorageArray
.extend({ _storageKey: storageKey })
.create();
indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
}

return indices[type];
}
},
});
6 changes: 2 additions & 4 deletions addon/adapters/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export default BaseAdapter.extend({
if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);

indices[type] = StorageArray
.extend({ _storageKey: storageKey })
.create();
indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
}

return indices[type];
}
},
});
Loading

0 comments on commit ce5ee63

Please sign in to comment.