Skip to content

Commit ee17de4

Browse files
authored
refactor: add more rules to ESLint config, fix warnings (#3148)
1 parent b8f2aad commit ee17de4

27 files changed

Lines changed: 122 additions & 87 deletions

‎.eslintrc.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@
4949
"@typescript-eslint/explicit-module-boundary-types": "off",
5050
"accessor-pairs": "error",
5151
"array-callback-return": "error",
52+
"default-case": ["error", { "commentPattern": "^no\\sdefault" }],
5253
"default-param-last": "error",
5354
"dot-notation": ["error", { "allowPattern": "^[a-zA-Z]+([_-][a-zA-Z]+)+$" }],
55+
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
56+
"grouped-accessor-pairs": ["error", "getBeforeSet"],
57+
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
5458
"max-classes-per-file": ["error", 3],
5559
"max-params": ["error", 4],
5660
"no-eval": "error",
@@ -65,7 +69,8 @@
6569
"prefer-exponentiation-operator": "error",
6670
"prefer-rest-params": "error",
6771
"prefer-spread": "error",
68-
"space-in-parens": ["error", "never"]
72+
"space-in-parens": ["error", "never"],
73+
"spaced-comment": ["error", "always"]
6974
},
7075
"overrides": [
7176
{

‎packages/app-layout/src/detect-ios-navbar.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
77

8-
export const _detectIosNavbar = function () {
8+
export function _detectIosNavbar() {
99
/* c8 ignore next 11 */
1010
if (isIOS) {
1111
const innerHeight = window.innerHeight;
@@ -18,7 +18,7 @@ export const _detectIosNavbar = function () {
1818
document.documentElement.style.setProperty('--vaadin-viewport-offset-bottom', '');
1919
}
2020
}
21-
};
21+
}
2222

2323
_detectIosNavbar();
2424
window.addEventListener('resize', _detectIosNavbar);

‎packages/board/src/vaadin-board-row.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class BoardRow extends ElementMixin(mixinBehaviors([IronResizableBehavior], Poly
9494
this.addEventListener('iron-resize', this._onIronResize, true);
9595
this.$.insertionPoint.addEventListener('slotchange', this.redraw.bind(this));
9696
afterNextRender(this, function () {
97-
//force this as an interested resizable of parent
97+
// force this as an interested resizable of parent
9898
this.dispatchEvent(
9999
new CustomEvent('iron-request-resize-notifications', {
100100
node: this,
@@ -245,7 +245,7 @@ class BoardRow extends ElementMixin(mixinBehaviors([IronResizableBehavior], Poly
245245
breakpoints.mediumSize != this._oldBreakpoints.mediumSize
246246
) {
247247
const nodes = this.$.insertionPoint.assignedNodes({ flatten: true });
248-
const isElementNode = function (node) {
248+
const isElementNode = (node) => {
249249
return !(node.nodeType === node.TEXT_NODE || node instanceof DomRepeat || node instanceof DomIf);
250250
};
251251
const filteredNodes = nodes.filter(isElementNode);

‎packages/charts/src/vaadin-chart.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
3030
import { ChartSeries } from './vaadin-chart-series.js';
3131

3232
/** @private */
33-
export const deepMerge = function deepMerge(target, source) {
33+
export function deepMerge(target, source) {
3434
const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
3535

3636
if (isObject(source) && isObject(target)) {
@@ -48,7 +48,7 @@ export const deepMerge = function deepMerge(target, source) {
4848
}
4949

5050
return target;
51-
};
51+
}
5252

5353
['exportChart', 'exportChartLocal', 'getSVG'].forEach((methodName) => {
5454
Highcharts.wrap(Highcharts.Chart.prototype, methodName, function (proceed, ...args) {
@@ -1700,6 +1700,8 @@ class Chart extends ElementMixin(ThemableMixin(PolymerElement)) {
17001700
case 3:
17011701
axes = this.configuration.colorAxis;
17021702
break;
1703+
default:
1704+
break;
17031705
}
17041706
if (axes && axes[axisIndex]) {
17051707
const axis = axes[axisIndex];

‎packages/component-base/src/debounce.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class Debouncer {
1717
this._callback = null;
1818
this._timer = null;
1919
}
20+
2021
/**
2122
* Sets the scheduler; that is, a module with the Async interface,
2223
* a callback and optional arguments to be passed to the run function
@@ -35,6 +36,7 @@ export class Debouncer {
3536
this._callback();
3637
});
3738
}
39+
3840
/**
3941
* Cancels an active debouncer and returns a reference to itself.
4042
*
@@ -50,6 +52,7 @@ export class Debouncer {
5052
debouncerQueue.delete(this);
5153
}
5254
}
55+
5356
/**
5457
* Cancels a debouncer's async callback.
5558
*
@@ -61,6 +64,7 @@ export class Debouncer {
6164
this._timer = null;
6265
}
6366
}
67+
6468
/**
6569
* Flushes an active debouncer and returns a reference to itself.
6670
*
@@ -72,6 +76,7 @@ export class Debouncer {
7276
this._callback();
7377
}
7478
}
79+
7580
/**
7681
* Returns true if the debouncer is active.
7782
*
@@ -80,6 +85,7 @@ export class Debouncer {
8085
isActive() {
8186
return this._timer != null;
8287
}
88+
8389
/**
8490
* Creates a debouncer if no debouncer is passed as a parameter
8591
* or it cancels an active debouncer otherwise. The following
@@ -135,16 +141,16 @@ let debouncerQueue = new Set();
135141
* @param {!Debouncer} debouncer Debouncer to enqueue
136142
* @return {void}
137143
*/
138-
export const enqueueDebouncer = function (debouncer) {
144+
export function enqueueDebouncer(debouncer) {
139145
debouncerQueue.add(debouncer);
140-
};
146+
}
141147

142148
/**
143149
* Flushes any enqueued debouncers
144150
*
145151
* @return {boolean} Returns whether any debouncers were flushed
146152
*/
147-
export const flushDebouncers = function () {
153+
export function flushDebouncers() {
148154
const didFlush = Boolean(debouncerQueue.size);
149155
// If new debouncers are added while flushing, Set.forEach will ensure
150156
// newly added ones are also flushed
@@ -158,7 +164,7 @@ export const flushDebouncers = function () {
158164
}
159165
});
160166
return didFlush;
161-
};
167+
}
162168

163169
export const flush = () => {
164170
let debouncers;

‎packages/component-base/src/dir-helper.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ class DirHelper {
5757
return element.scrollWidth - element.clientWidth + scrollLeft;
5858
case 'reverse':
5959
return element.scrollWidth - element.clientWidth - scrollLeft;
60+
default:
61+
return scrollLeft;
6062
}
61-
return scrollLeft;
6263
}
6364

6465
/**

‎packages/component-base/src/dir-mixin.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ import { DirHelper } from './dir-helper.js';
99
* Array of Vaadin custom element classes that have been subscribed to the dir changes.
1010
*/
1111
const directionSubscribers = [];
12-
const directionUpdater = function () {
12+
function directionUpdater() {
1313
const documentDir = getDocumentDir();
1414
directionSubscribers.forEach((element) => {
1515
alignDirs(element, documentDir);
1616
});
17-
};
17+
}
1818

1919
let scrollType;
2020

2121
const directionObserver = new MutationObserver(directionUpdater);
2222
directionObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['dir'] });
2323

24-
const alignDirs = function (element, documentDir, elementDir = element.getAttribute('dir')) {
24+
function alignDirs(element, documentDir, elementDir = element.getAttribute('dir')) {
2525
if (documentDir) {
2626
element.setAttribute('dir', documentDir);
2727
} else if (elementDir != null) {
2828
element.removeAttribute('dir');
2929
}
30-
};
30+
}
3131

32-
const getDocumentDir = function () {
32+
function getDocumentDir() {
3333
return document.documentElement.getAttribute('dir');
34-
};
34+
}
3535

3636
/**
3737
* A mixin to handle `dir` attribute based on the one set on the `<html>` element.

‎packages/component-base/src/gestures.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function matchingLabels(el) {
163163
// but this breaks `<input>` focus and link clicks
164164
// disable mouse handlers for MOUSE_TIMEOUT ms after
165165
// a touchend to ignore synthetic mouse events
166-
let mouseCanceller = function (mouseEvent) {
166+
function mouseCanceller(mouseEvent) {
167167
// Check for sourceCapabilities, used to distinguish synthetic events
168168
// if mouseEvent did not come from a device that fires touch events,
169169
// it was made by a real mouse and should be counted
@@ -202,7 +202,7 @@ let mouseCanceller = function (mouseEvent) {
202202
mouseEvent.preventDefault();
203203
mouseEvent.stopPropagation();
204204
}
205-
};
205+
}
206206

207207
/**
208208
* @param {boolean=} setup True to add, false to remove.
@@ -229,7 +229,7 @@ function ignoreMouse(e) {
229229
if (!POINTERSTATE.mouse.mouseIgnoreJob) {
230230
setupTeardownMouseCanceller(true);
231231
}
232-
let unset = function () {
232+
let unset = () => {
233233
setupTeardownMouseCanceller();
234234
POINTERSTATE.mouse.target = null;
235235
POINTERSTATE.mouse.mouseIgnoreJob = null;
@@ -743,13 +743,13 @@ register({
743743
let t = _findOriginalTarget(e);
744744
// eslint-disable-next-line @typescript-eslint/no-this-alias
745745
let self = this;
746-
let movefn = function movefn(e) {
746+
let movefn = (e) => {
747747
if (!hasLeftMouseButton(e)) {
748748
downupFire('up', t, e);
749749
untrackDocument(self.info);
750750
}
751751
};
752-
let upfn = function upfn(e) {
752+
let upfn = (e) => {
753753
if (hasLeftMouseButton(e)) {
754754
downupFire('up', t, e);
755755
}
@@ -854,7 +854,7 @@ register({
854854
let t = _findOriginalTarget(e);
855855
// eslint-disable-next-line @typescript-eslint/no-this-alias
856856
let self = this;
857-
let movefn = function movefn(e) {
857+
let movefn = (e) => {
858858
let x = e.clientX,
859859
y = e.clientY;
860860
if (trackHasMovedEnough(self.info, x, y)) {
@@ -876,7 +876,7 @@ register({
876876
self.info.started = true;
877877
}
878878
};
879-
let upfn = function upfn(e) {
879+
let upfn = (e) => {
880880
if (self.info.started) {
881881
movefn(e);
882882
}

‎packages/component-base/src/iron-list-core.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ export const ironList = {
186186
return Math.max(0, virtualCount - this._physicalCount);
187187
},
188188

189+
get _virtualStart() {
190+
return this._virtualStartVal || 0;
191+
},
192+
189193
set _virtualStart(val) {
190194
val = this._clamp(val, 0, this._maxVirtualStart);
191195
if (this.grid) {
@@ -194,8 +198,8 @@ export const ironList = {
194198
this._virtualStartVal = val;
195199
},
196200

197-
get _virtualStart() {
198-
return this._virtualStartVal || 0;
201+
get _physicalStart() {
202+
return this._physicalStartVal || 0;
199203
},
200204

201205
/**
@@ -212,25 +216,21 @@ export const ironList = {
212216
this._physicalStartVal = val;
213217
},
214218

215-
get _physicalStart() {
216-
return this._physicalStartVal || 0;
217-
},
218-
219219
/**
220220
* The k-th tile that is at the bottom of the scrolling list.
221221
*/
222222
get _physicalEnd() {
223223
return (this._physicalStart + this._physicalCount - 1) % this._physicalCount;
224224
},
225225

226-
set _physicalCount(val) {
227-
this._physicalCountVal = val;
228-
},
229-
230226
get _physicalCount() {
231227
return this._physicalCountVal || 0;
232228
},
233229

230+
set _physicalCount(val) {
231+
this._physicalCountVal = val;
232+
},
233+
234234
/**
235235
* An optimal physical size such that we will have enough physical items
236236
* to fill up the viewport and recycle when the user scrolls.

‎packages/component-base/src/virtualizer-iron-list-adapter.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export class IronListAdapter {
155155
return element ? this.scrollTarget.getBoundingClientRect().top - element.getBoundingClientRect().top : undefined;
156156
}
157157

158+
get size() {
159+
return this.__size;
160+
}
161+
158162
set size(size) {
159163
if (size === this.size) {
160164
return;
@@ -204,10 +208,6 @@ export class IronListAdapter {
204208
flush();
205209
}
206210

207-
get size() {
208-
return this.__size;
209-
}
210-
211211
/** @private */
212212
get _scrollTop() {
213213
return this.scrollTarget.scrollTop;

0 commit comments

Comments
 (0)