Skip to content

Commit

Permalink
refactor: add more rules to ESLint config, fix warnings (#3152)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Dec 3, 2021
1 parent 191badc commit e2b36f2
Show file tree
Hide file tree
Showing 45 changed files with 268 additions and 305 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"max-classes-per-file": ["error", 3],
"max-params": ["error", 4],
"no-else-return": "error",
"no-eval": "error",
"no-implicit-coercion": ["error", { "allow": ["!!"] }],
"no-promise-executor-return": "error",
Expand All @@ -66,7 +67,9 @@
"no-sync": "off",
"no-throw-literal": "error",
"no-useless-return": "error",
"prefer-const": ["error", { "ignoreReadBeforeAssign": true }],
"prefer-exponentiation-operator": "error",
"prefer-object-spread": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"space-in-parens": ["error", "never"],
Expand Down
4 changes: 2 additions & 2 deletions packages/board/src/vaadin-board-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class BoardRow extends ElementMixin(mixinBehaviors([IronResizableBehavior], Poly
_removeExtraNodesFromDOM(boardCols, nodes) {
let isErrorReported = false;
let spaceLeft = 4;
let returnNodes = [];
const returnNodes = [];
nodes.forEach((node, i) => {
spaceLeft = spaceLeft - boardCols[i];
if (spaceLeft < 0) {
Expand Down Expand Up @@ -253,7 +253,7 @@ class BoardRow extends ElementMixin(mixinBehaviors([IronResizableBehavior], Poly
const boardCols = this._parseBoardCols(filteredNodes);
const colsInRow = boardCols.reduce((a, b) => a + b, 0);
this._removeExtraNodesFromDOM(boardCols, filteredNodes).forEach((e, i) => {
let newFlexBasis = this._calculateFlexBasis(boardCols[i], width, colsInRow, breakpoints);
const newFlexBasis = this._calculateFlexBasis(boardCols[i], width, colsInRow, breakpoints);
if (forceResize || !this._oldFlexBasis[i] || this._oldFlexBasis[i] != newFlexBasis) {
this._oldFlexBasis[i] = newFlexBasis;
e.style.flexBasis = newFlexBasis;
Expand Down
2 changes: 1 addition & 1 deletion packages/charts/src/vaadin-chart-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class ChartSeries extends PolymerElement {
if (parent && parent instanceof Chart) {
if (unit && !parent.__getAxis(unit)) {
const title = { title: { text: unit } };
parent.__addAxis(Object.assign({ id: unit, axisGenerated: true }, title));
parent.__addAxis({ id: unit, axisGenerated: true, ...title });
}
series.update({ yAxis: unit || 0 });

Expand Down
19 changes: 9 additions & 10 deletions packages/charts/src/vaadin-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class Chart extends ElementMixin(ThemableMixin(PolymerElement)) {
return;
}

const options = Object.assign({}, this.options, this._jsonConfigurationBuffer);
const options = { ...this.options, ...this._jsonConfigurationBuffer };
this._jsonConfigurationBuffer = null;
this.__initChart(options);
this.__addChildObserver();
Expand All @@ -540,7 +540,7 @@ class Chart extends ElementMixin(ThemableMixin(PolymerElement)) {
* @return {!Options}
*/
get options() {
const options = Object.assign({}, this._baseConfig);
const options = { ...this._baseConfig };
deepMerge(options, this.additionalOptions);

if (this.type) {
Expand Down Expand Up @@ -635,7 +635,7 @@ class Chart extends ElementMixin(ThemableMixin(PolymerElement)) {
if (this.chart3d) {
options.chart = options.chart || {};

options.chart.options3d = Object.assign({}, this._baseChart3d, options.chart.options3d);
options.chart.options3d = { ...this._baseChart3d, ...options.chart.options3d };
}

return options;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ class Chart extends ElementMixin(ThemableMixin(PolymerElement)) {
}

if (resetConfiguration) {
const initialOptions = Object.assign({}, this.options, this._jsonConfigurationBuffer);
const initialOptions = { ...this.options, ...this._jsonConfigurationBuffer };

this.__initChart(initialOptions);

Expand Down Expand Up @@ -1610,12 +1610,11 @@ class Chart extends ElementMixin(ThemableMixin(PolymerElement)) {
if (chart3d) {
config.update({
chart: {
options3d: Object.assign(
{},
this._baseChart3d,
this.additionalOptions && this.additionalOptions.chart && this.additionalOptions.chart.options3d,
{ enabled: true }
)
options3d: {
...this._baseChart3d,
...(this.additionalOptions && this.additionalOptions.chart && this.additionalOptions.chart.options3d),
enabled: true
}
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ export const ComboBoxDataProviderMixin = (superClass) =>
const loadedItem = this.filteredItems[page * this.pageSize];
if (loadedItem !== undefined) {
return loadedItem instanceof ComboBoxPlaceholder;
} else {
return this.size === undefined;
}
return this.size === undefined;
}

/** @private */
Expand Down
3 changes: 1 addition & 2 deletions packages/combo-box/src/vaadin-combo-box-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ThemableMixi
checkValidity() {
if (this.inputElement.validate) {
return this.inputElement.validate();
} else {
return super.checkValidity();
}
return super.checkValidity();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/combo-box/src/vaadin-combo-box-scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ export class ComboBoxScroller extends PolymerElement {
return false;
} else if (itemIdPath && item !== undefined && selectedItem !== undefined) {
return this.get(itemIdPath, item) === this.get(itemIdPath, selectedItem);
} else {
return item === selectedItem;
}
return item === selectedItem;
}

/** @private */
Expand Down
2 changes: 1 addition & 1 deletion packages/combo-box/test/combo-box-light.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('custom buttons', () => {
const y = Math.ceil(rect.top);
// Get the element which would be targeted, when the user
// tries to click on this position
let target = elementFromPointDeep(x, y, elem.ownerDocument);
const target = elementFromPointDeep(x, y, elem.ownerDocument);
if (!target) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/component-base/src/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
// Microtask implemented using Mutation Observer
let microtaskCurrHandle = 0;
let microtaskLastHandle = 0;
let microtaskCallbacks = [];
const microtaskCallbacks = [];
let microtaskNodeContent = 0;
let microtaskScheduled = false;
let microtaskNode = document.createTextNode('');
const microtaskNode = document.createTextNode('');
new window.MutationObserver(microtaskFlush).observe(microtaskNode, { characterData: true });

function microtaskFlush() {
microtaskScheduled = false;
const len = microtaskCallbacks.length;
for (let i = 0; i < len; i++) {
let cb = microtaskCallbacks[i];
const cb = microtaskCallbacks[i];
if (cb) {
try {
cb();
Expand Down
2 changes: 1 addition & 1 deletion packages/component-base/src/focus-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function isElementFocused(element) {
* @return {HTMLElement[]}
*/
export function getFocusableElements(element) {
let focusableElements = [];
const focusableElements = [];
const needsSortByTabIndex = collectFocusableNodes(element, focusableElements);
// If there is at least one element with tabindex > 0, we need to sort
// the final array by tabindex.≈
Expand Down
Loading

0 comments on commit e2b36f2

Please sign in to comment.