Skip to content

Commit

Permalink
Various lint fixes (#2316)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner committed Feb 4, 2023
1 parent 0dae081 commit 7e68f7f
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 57 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = {
'ember/no-jquery': 'error',

// Temporarily turn these off
'ember/avoid-leaking-state-in-ember-objects': 'off',
'ember/classic-decorator-hooks': 'off',
'ember/classic-decorator-no-classic-methods': 'off',
'ember/no-classic-classes': 'off',
Expand Down
4 changes: 2 additions & 2 deletions app/components/object-inspector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Component from '@glimmer/component';
import { action, get } from '@ember/object';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

Expand Down Expand Up @@ -49,7 +49,7 @@ export default class ObjectInspector extends Component {
}
@action sendObjectToConsole(obj) {
let objectId = get(obj, 'objectId');
let objectId = obj.objectId;
this.port.send('objectInspector:sendToConsole', {
objectId,
});
Expand Down
65 changes: 31 additions & 34 deletions app/components/render-item.js → app/components/render-item.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,40 @@
import { tagName } from '@ember-decorators/component';
import { computed, get } from '@ember/object';
import { gt } from '@ember/object/computed';
import Component from '@ember/component';
import { isNone, isEmpty } from '@ember/utils';
import Component from '@glimmer/component';
import { isEmpty } from '@ember/utils';
import { htmlSafe } from '@ember/template';
import escapeRegExp from 'ember-inspector/utils/escape-reg-exp';

@tagName('')
export default class RenderItem extends Component {
@computed('model.name', 'name', 'search')
get searchMatch() {
let search = this.search;
if (isEmpty(search)) {
return true;
}
let name = get(this, 'model.name');
let regExp = new RegExp(escapeRegExp(search.toLowerCase()));
return !!name.toLowerCase().match(regExp);
}
interface RenderItemArgs {
list: any;
model: any;
search: string;
target: { level: number };
}

@computed('searchMatch')
get nodeStyle() {
let style = '';
if (!this.searchMatch) {
style = 'opacity: 0.5;';
}
return htmlSafe(style);
export default class RenderItem extends Component<RenderItemArgs> {
get hasChildren() {
return Number(this.args.model?.children?.length) > 0;
}

@computed('target.level')
get level() {
let parentLevel = get(this, 'target.level');
if (isNone(parentLevel)) {
parentLevel = -1;
}
let parentLevel = this.args.target?.level ?? -1;

return parentLevel + 1;
}

@computed('level')
get nameStyle() {
return htmlSafe(`padding-left: ${+this.level * 20 + 5}px;`);
}

@gt('model.children.length', 0)
hasChildren;
get nodeStyle() {
let style = '';
if (!this.searchMatch) {
style = 'opacity: 0.5;';
}
return htmlSafe(style);
}

@computed('model.timestamp')
get readableTime() {
let d = new Date(get(this, 'model.timestamp'));
let d = new Date(this.args.model?.timestamp);
let ms = d.getMilliseconds();
let seconds = d.getSeconds();
let minutes =
Expand All @@ -59,4 +46,14 @@ export default class RenderItem extends Component {

return `${hours}:${minutes}:${seconds}:${ms}`;
}

get searchMatch() {
let search = this.args.search;
if (isEmpty(search)) {
return true;
}
let name = this.args.model?.name;
let regExp = new RegExp(escapeRegExp(search.toLowerCase()) as string);
return !!name.toLowerCase().match(regExp);
}
}
4 changes: 2 additions & 2 deletions app/controllers/model-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Controller from '@ember/controller';
import { action, get, computed } from '@ember/object';
import { action, computed } from '@ember/object';
import { sort } from '@ember/object/computed';
import { inject as service } from '@ember/service';

Expand Down Expand Up @@ -47,7 +47,7 @@ export default class ModelTypesController extends Controller {
let hideEmptyModels = this.hideEmptyModelTypes;

if (hideEmptyModels) {
return !!get(item, 'count');
return !!item.count;
} else {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class RecordsController extends Controller {
filterValue = null;

recordToString(record) {
return (get(record, 'searchKeywords') || []).join(' ').toLowerCase();
return (record.searchKeywords || []).join(' ').toLowerCase();
}

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class RecordsController extends Controller {
@action
inspectModel([record]) {
this.set('selection', record);
this.port.send('data:inspectModel', { objectId: get(record, 'objectId') });
this.port.send('data:inspectModel', { objectId: record.objectId });
}

@action
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/render-tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, computed, get } from '@ember/object';
import { action, computed } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { isEmpty } from '@ember/utils';
import Controller from '@ember/controller';
Expand Down Expand Up @@ -63,16 +63,16 @@ export default class RenderTreeController extends Controller {
@computed('model.isHighlightSupported')
get isHighlightEnabled() {
return get(this.model, 'isHighlightSupported');
return this.model.isHighlightSupported;
}
@computed('escapedSearch', 'model.profiles.@each.name', 'search')
get filtered() {
if (isEmpty(this.escapedSearch)) {
return get(this.model, 'profiles');
return this.model.profiles;
}
return get(this.model, 'profiles').filter((item) => {
return this.model.profiles.filter((item) => {
const regExp = new RegExp(this.escapedSearch);
return recursiveMatch(item, regExp);
});
Expand Down Expand Up @@ -100,11 +100,11 @@ export default class RenderTreeController extends Controller {

function recursiveMatch(item, regExp) {
let children, child;
let name = get(item, 'name');
let name = item.name;
if (name.toLowerCase().match(regExp)) {
return true;
}
children = get(item, 'children');
children = item.children;
for (let i = 0; i < children.length; i++) {
child = children[i];
if (recursiveMatch(child, regExp)) {
Expand Down
6 changes: 3 additions & 3 deletions app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject as service } from '@ember/service';
import { set, get, action } from '@ember/object';
import { action, set } from '@ember/object';
import Route from '@ember/routing/route';
import Ember from 'ember';
const { NativeArray } = Ember;
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class ApplicationRoute extends Route {
const detail = this.get('controller.mixinDetails.mixins').objectAt(
options.mixinIndex
);
let property = get(detail, 'properties').findBy('name', options.property);
let property = detail.properties.findBy('name', options.property);
if (!property) return;
set(property, 'value', options.value);
if (options.dependentKeys) {
Expand All @@ -91,7 +91,7 @@ export default class ApplicationRoute extends Route {
updateErrors(options) {
let mixinDetails = this.get('controller.mixinDetails');
if (mixinDetails) {
if (get(mixinDetails, 'objectId') === options.objectId) {
if (mixinDetails.objectId === options.objectId) {
set(mixinDetails, 'errors', options.errors);
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/routes/container-type.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject as service } from '@ember/service';
import { Promise } from 'rsvp';
import { get, action } from '@ember/object';
import { action } from '@ember/object';
import TabRoute from 'ember-inspector/routes/tab';

export default class ContainerTypeRoute extends TabRoute {
Expand Down Expand Up @@ -41,7 +41,7 @@ export default class ContainerTypeRoute extends TabRoute {
@action
sendInstanceToConsole(obj) {
this.port.send('container:sendInstanceToConsole', {
name: get(obj, 'fullName'),
name: obj.fullName,
});
}
}
3 changes: 1 addition & 2 deletions app/routes/model-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { get } from '@ember/object';
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import { Promise } from 'rsvp';
Expand Down Expand Up @@ -32,6 +31,6 @@ export default class ModelTypeRoute extends Route {
}

serialize(model) {
return { type_id: get(model, 'name') };
return { type_id: model.name };
}
}
4 changes: 2 additions & 2 deletions app/utils/escape-reg-exp.js → app/utils/escape-reg-exp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint no-useless-escape: 0 */
export default function (str) {
/* eslint-disable no-useless-escape */
export default function (str: string) {
if (typeof str === 'string') {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}
Expand Down
3 changes: 3 additions & 0 deletions ember_debug/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module.exports = {
rules: {
'no-useless-escape': 'off',

'ember/avoid-leaking-state-in-ember-objects': 'off',
'ember/no-get': 'off',

// TODO: turn this back on when we figure out switching from window.Ember to imports
'ember/new-module-imports': 'off',
},
Expand Down
2 changes: 1 addition & 1 deletion tests/ember_debug/object-inspector-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable ember/no-new-mixins */
/* eslint-disable ember/avoid-leaking-state-in-ember-objects, ember/no-new-mixins */
import { find, visit } from '@ember/test-helpers';
import Mixin from '@ember/object/mixin';
import Component from '@ember/component';
Expand Down
1 change: 1 addition & 0 deletions tests/ember_debug/promise-debug-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/avoid-leaking-state-in-ember-objects */
import { run, later } from '@ember/runloop';
import { A as emberA } from '@ember/array';
import RSVP from 'rsvp';
Expand Down

0 comments on commit 7e68f7f

Please sign in to comment.