Skip to content

Commit

Permalink
Updates .eslint to forbid for of loops | Fixes liferay#1031
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Castelain committed Jun 25, 2018
1 parent 27df309 commit 364985e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
10 changes: 8 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"env": {
"browser": true,
"browser": true,
"node": true,
"es6": true,
"jest": true
},
"extends": "liferay"
"extends": "liferay",
"plugins": [
"no-for-of-loops"
],
"rules": {
"no-for-of-loops/no-for-of-loops": 2
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"cross-env": "^5.1.3",
"eslint": "^4.10.0",
"eslint-config-liferay": "^2.0.8",
"eslint-plugin-no-for-of-loops": "1.0.0",
"eslint-plugin-react": "^7.4.0",
"http-server": "^0.9.0",
"husky": "^0.14.2",
Expand Down
38 changes: 28 additions & 10 deletions packages/clay-dataset-display/src/ClayDatasetDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class ClayDatasetDisplay extends ClayComponent {
let totalItems = 0;

if (this.items) {
for (let item of this.items) {
for (let i = 0, l = this.items.length; i < l; i++) {
const item = this.items[i];
if (item.items) {
totalItems += item.items.length;

for (let childrenItem of item.items) {
for (let j = 0, k = item.items.length; j < k; j++) {
const childrenItem = item.items[j];
if (childrenItem.selected) {
selectedItems.push(childrenItem);
}
Expand All @@ -55,7 +57,8 @@ class ClayDatasetDisplay extends ClayComponent {
* @private
*/
_deselectAllItems() {
for (let item of this._selectedItems) {
for (let i = 0, l = this._selectedItems.length; i < l; i++) {
const item = this._selectedItems[i];
item.selected = false;
}

Expand Down Expand Up @@ -151,7 +154,12 @@ class ClayDatasetDisplay extends ClayComponent {
let itemId = event.target.getAttribute('value');

if (!checkedStatus) {
for (let [index, item] of this._selectedItems.entries()) {
const entries = Object.entries(this._selectedItems);

for (let i = 0, l = entries.length; i < l; i++) {
const entry = entries[i];
const index = entry[0];
let item = entry[1];
if (
item[
this.views[this.selectedView].schema.inputValueField
Expand All @@ -166,9 +174,11 @@ class ClayDatasetDisplay extends ClayComponent {
let found = false;

if (this.items) {
for (let item of this.items) {
for (let i = 0, l = this.items.length; i < l; i++) {
const item = this.items[i];
if (item.items) {
for (let childrenItem of item.items) {
for (let j = 0, k = item.items.length; j < k; j++) {
const childrenItem = item.items[j];
if (
childrenItem[
this.views[this.selectedView].schema
Expand Down Expand Up @@ -247,9 +257,15 @@ class ClayDatasetDisplay extends ClayComponent {
_handleViewTypeItemClicked(item) {
this.views[this.selectedView].active = false;

for (let [index, view] of this.views.entries()) {
const entries = this.views.entries();

for (let i = 0, l = entries.length; i < l; i++) {
const entry = entries[i];
const index = entry[0];
const view = entry[1];

if (view === item) {
this.views[index].active = true;
this.view[index].active = true;
this.selectedView = index;
break;
}
Expand All @@ -264,9 +280,11 @@ class ClayDatasetDisplay extends ClayComponent {
_selectAllItems() {
let selectedItems = [];

for (let item of this.items) {
for (let i = 0, l = this.items.length; i < l; i++) {
const item = this.items[i];
if (item.items) {
for (let childrenItem of item.items) {
for (let j = 0, k = item.items.length; j < k; j++) {
const childrenItem = item.items[j];
childrenItem.selected = true;

selectedItems.push(childrenItem);
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4412,6 +4412,10 @@ eslint-plugin-liferayportal@^1.0.0:
dependencies:
requireindex "~1.1.0"

eslint-plugin-no-for-of-loops@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-no-for-of-loops/-/eslint-plugin-no-for-of-loops-1.0.0.tgz#a13d91a8f1922f7fefedeab351dc0055994601f6"

eslint-plugin-react@^7.4.0:
version "7.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.7.0.tgz#f606c719dbd8a1a2b3d25c16299813878cca0160"
Expand Down

0 comments on commit 364985e

Please sign in to comment.