Skip to content

Commit

Permalink
Add Ember ESLint plugin (#8134)
Browse files Browse the repository at this point in the history
This is extracted from #8094, where I have run into some snags. Since
these ESLint fixes aren’t actually connected to the Ember 3.16 update
but involve changes to many files, we might as well address them
separately. Where possible I fixed the problems but in cases where
a fix seemed too involved, I added per-line or -file exceptions.
  • Loading branch information
backspace authored Jun 9, 2020
1 parent a7291fc commit 11d80ae
Show file tree
Hide file tree
Showing 73 changed files with 314 additions and 194 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .circleci/config/jobs/test-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ steps:
- checkout
- restore_cache:
keys:
- v1-deps-{{ checksum "ui/yarn.lock" }}
- v1-deps-
- v2-deps-{{ checksum "ui/yarn.lock" }}
- v2-deps-
- run:
name: yarn install
command: cd ui && yarn install
- save_cache:
key: v1-deps-{{ checksum "ui/yarn.lock" }}
key: v2-deps-{{ checksum "ui/yarn.lock" }}
paths:
- ./ui/node_modules
- run:
Expand Down
8 changes: 7 additions & 1 deletion ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ module.exports = {
browser: true,
es6: true,
},
extends: 'eslint:recommended',
extends: [
'eslint:recommended',
'plugin:ember/recommended',
],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: [
'ember'
],
rules: {
indent: ['error', 2, { SwitchCase: 1 }],
'linebreak-style': ['error', 'unix'],
Expand Down
2 changes: 2 additions & 0 deletions ui/app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default RESTAdapter.extend({
'X-Nomad-Token': token,
};
}

return;
}),

handleResponse(status, headers, payload) {
Expand Down
4 changes: 2 additions & 2 deletions ui/app/adapters/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import addToPath from 'nomad-ui/utils/add-to-path';
import WithNamespaceIDs from 'nomad-ui/mixins/with-namespace-ids';

export default Watchable.extend(WithNamespaceIDs, {
relationshipFallbackLinks: {
relationshipFallbackLinks: Object.freeze({
summary: '/summary',
},
}),

fetchRawDefinition(job) {
const url = this.urlForFindRecord(job.get('id'), 'job');
Expand Down
4 changes: 2 additions & 2 deletions ui/app/adapters/plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Watchable from './watchable';

export default Watchable.extend({
queryParamsToAttrs: {
queryParamsToAttrs: Object.freeze({
type: 'type',
},
}),
});
4 changes: 2 additions & 2 deletions ui/app/adapters/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Watchable from './watchable';
import WithNamespaceIDs from 'nomad-ui/mixins/with-namespace-ids';

export default Watchable.extend(WithNamespaceIDs, {
queryParamsToAttrs: {
queryParamsToAttrs: Object.freeze({
type: 'type',
plugin_id: 'plugin.id',
},
}),
});
16 changes: 7 additions & 9 deletions ui/app/components/allocation-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default Component.extend({
if (metric === 'cpu' || metric === 'memory') {
return this[this.metric];
}

return;
}),

formattedStat: computed('metric', 'stat.used', function() {
Expand All @@ -32,13 +34,9 @@ export default Component.extend({
return this.stat.used;
}),

formattedReserved: computed(
'metric',
'statsTracker.reservedMemory',
'statsTracker.reservedCPU',
function() {
if (this.metric === 'memory') return `${this.statsTracker.reservedMemory} MiB`;
if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`;
}
),
formattedReserved: computed('metric', 'statsTracker.{reservedMemory,reservedCPU}', function() {
if (this.metric === 'memory') return `${this.statsTracker.reservedMemory} MiB`;
if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`;
return;
}),
});
1 change: 1 addition & 0 deletions ui/app/components/distribution-bar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/no-observers */
import Component from '@ember/component';
import { computed, observer, set } from '@ember/object';
import { run } from '@ember/runloop';
Expand Down
18 changes: 10 additions & 8 deletions ui/app/components/drain-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ export default Component.extend({
durationIsCustom: equal('selectedDurationQuickOption.value', 'custom'),
customDuration: '',

durationQuickOptions: computed(() => [
{ label: '1 Hour', value: '1h' },
{ label: '4 Hours', value: '4h' },
{ label: '8 Hours', value: '8h' },
{ label: '12 Hours', value: '12h' },
{ label: '1 Day', value: '1d' },
{ label: 'Custom', value: 'custom' },
]),
durationQuickOptions: computed(function() {
return [
{ label: '1 Hour', value: '1h' },
{ label: '4 Hours', value: '4h' },
{ label: '8 Hours', value: '8h' },
{ label: '12 Hours', value: '12h' },
{ label: '1 Day', value: '1d' },
{ label: 'Custom', value: 'custom' },
];
}),

deadline: computed(
'deadlineEnabled',
Expand Down
3 changes: 2 additions & 1 deletion ui/app/components/fs/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default Component.extend({
if (this.model.allocation) {
return this.model;
}

return;
}),

type: computed('taskState', function() {
Expand Down Expand Up @@ -53,5 +55,4 @@ export default Component.extend({
}
}
),

});
18 changes: 7 additions & 11 deletions ui/app/components/fs/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,15 @@ export default Component.extend({
} else if (this.mode === 'head' || this.mode === 'tail') {
return 'readat';
}

return;
}),

fileUrl: computed(
'allocation.id',
'allocation.node.httpAddr',
'fetchMode',
'useServer',
function() {
const address = this.get('allocation.node.httpAddr');
const url = `/v1/client/fs/${this.fetchMode}/${this.allocation.id}`;
return this.useServer ? url : `//${address}${url}`;
}
),
fileUrl: computed('allocation.{id,node.httpAddr}', 'fetchMode', 'useServer', function() {
const address = this.get('allocation.node.httpAddr');
const url = `/v1/client/fs/${this.fetchMode}/${this.allocation.id}`;
return this.useServer ? url : `//${address}${url}`;
}),

fileParams: computed('taskState.name', 'file', 'mode', function() {
// The Log class handles encoding query params
Expand Down
4 changes: 4 additions & 0 deletions ui/app/components/lifecycle-chart-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ export default Component.extend({
if (this.taskState && this.taskState.state === 'running') {
return 'is-active';
}

return;
}),

finishedClass: computed('taskState.finishedAt', function() {
if (this.taskState && this.taskState.finishedAt) {
return 'is-finished';
}

return;
}),
});
1 change: 1 addition & 0 deletions ui/app/components/line-chart.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/no-observers */
import Component from '@ember/component';
import { computed, observer } from '@ember/object';
import { computed as overridable } from 'ember-overridable-computed';
Expand Down
1 change: 1 addition & 0 deletions ui/app/components/list-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default Component.extend({
};
});

// eslint-disable-next-line ember/no-side-effects
this.set('stateCache', decoratedSource);
return decoratedSource;
}),
Expand Down
8 changes: 5 additions & 3 deletions ui/app/components/multi-select-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ export default Component.extend({
didReceiveAttrs() {
const dropdown = this.dropdown;
if (this.isOpen && dropdown) {
run.scheduleOnce('afterRender', () => {
dropdown.actions.reposition();
});
run.scheduleOnce('afterRender', this, this.repositionDropdown);
}
},

repositionDropdown() {
this.dropdown.actions.reposition();
},

actions: {
toggle({ key }) {
const newSelection = this.selection.slice();
Expand Down
10 changes: 6 additions & 4 deletions ui/app/components/popover-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const FOCUSABLE = [
].join(', ');

export default Component.extend({
classnames: ['popover'],
classNames: ['popover'],

triggerClass: '',
isOpen: false,
Expand All @@ -31,12 +31,14 @@ export default Component.extend({
didReceiveAttrs() {
const dropdown = this.dropdown;
if (this.isOpen && dropdown) {
run.scheduleOnce('afterRender', () => {
dropdown.actions.reposition();
});
run.scheduleOnce('afterRender', this, this.repositionDropdown);
}
},

repositionDropdown() {
this.dropdown.actions.reposition();
},

actions: {
openOnArrowDown(dropdown, e) {
if (!this.isOpen && e.keyCode === ARROW_DOWN) {
Expand Down
53 changes: 27 additions & 26 deletions ui/app/components/streaming-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ export default Component.extend(WindowResizable, {
return;
}

run.scheduleOnce('actions', () => {
switch (this.mode) {
case 'head':
this.head.perform();
break;
case 'tail':
this.tail.perform();
break;
case 'streaming':
if (this.isStreaming) {
this.stream.perform();
} else {
this.logger.stop();
}
break;
}
});
run.scheduleOnce('actions', this, this.performTask);
},

performTask() {
switch (this.mode) {
case 'head':
this.head.perform();
break;
case 'tail':
this.tail.perform();
break;
case 'streaming':
if (this.isStreaming) {
this.stream.perform();
} else {
this.logger.stop();
}
break;
}
},

didInsertElement() {
Expand All @@ -54,17 +56,16 @@ export default Component.extend(WindowResizable, {

head: task(function*() {
yield this.get('logger.gotoHead').perform();
run.scheduleOnce('afterRender', () => {
this.element.scrollTop = 0;
});
run.scheduleOnce('afterRender', this, this.scrollToTop);
}),

scrollToTop() {
this.element.scrollTop = 0;
},

tail: task(function*() {
yield this.get('logger.gotoTail').perform();
run.scheduleOnce('afterRender', () => {
const cliWindow = this.element;
cliWindow.scrollTop = cliWindow.scrollHeight;
});
run.scheduleOnce('afterRender', this, this.synchronizeScrollPosition, [true]);
}),

synchronizeScrollPosition(force = false) {
Expand All @@ -78,7 +79,7 @@ export default Component.extend(WindowResizable, {
stream: task(function*() {
// Force the scroll position to the bottom of the window when starting streaming
this.logger.one('tick', () => {
run.scheduleOnce('afterRender', () => this.synchronizeScrollPosition(true));
run.scheduleOnce('afterRender', this, this.synchronizeScrollPosition, [true]);
});

// Follow the log if the scroll position is near the bottom of the cli window
Expand All @@ -89,7 +90,7 @@ export default Component.extend(WindowResizable, {
}),

scheduleScrollSynchronization() {
run.scheduleOnce('afterRender', () => this.synchronizeScrollPosition());
run.scheduleOnce('afterRender', this, this.synchronizeScrollPosition);
},

willDestroy() {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/task-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default Component.extend({

mode: 'stdout',

logUrl: computed('allocation.id', 'allocation.node.httpAddr', 'useServer', function() {
logUrl: computed('allocation.{id,node.httpAddr}', 'useServer', function() {
const address = this.get('allocation.node.httpAddr');
const allocation = this.get('allocation.id');

Expand Down
4 changes: 3 additions & 1 deletion ui/app/components/task-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default Component.extend({
// Internal state
statsError: false,

enablePolling: computed(() => !Ember.testing),
enablePolling: computed(function() {
return !Ember.testing;
}),

// Since all tasks for an allocation share the same tracker, use the registry
stats: computed('task', 'task.isRunning', function() {
Expand Down
1 change: 1 addition & 0 deletions ui/app/controllers/allocations/allocation/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/no-observers */
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { computed, observer } from '@ember/object';
Expand Down
2 changes: 1 addition & 1 deletion ui/app/controllers/allocations/allocation/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default Controller.extend({
}),

network: alias('model.resources.networks.firstObject'),
ports: computed('network.reservedPorts.[]', 'network.dynamicPorts.[]', function() {
ports: computed('network.{reservedPorts.[],dynamicPorts.[]}', function() {
return (this.get('network.reservedPorts') || [])
.map(port => ({
name: port.Label,
Expand Down
1 change: 1 addition & 0 deletions ui/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/no-observers */
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import { run } from '@ember/runloop';
Expand Down
Loading

0 comments on commit 11d80ae

Please sign in to comment.