You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2023/11/24 15:33:51 UTC
(myfaces-tobago) branch main updated: style(eslint): config
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/main by this push:
new 580e7eb983 style(eslint): config
580e7eb983 is described below
commit 580e7eb983ccc1d0015dd61aa334f60c02535557
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Nov 24 11:42:25 2023 +0100
style(eslint): config
* add rule "semi"
* no-irregular-whitespace: off
* no-explicit-any: off
* remove rules to match "recommended"
- array-type
- consistent-indexed-object-style
- consistent-type-assertions
- consistent-type-definitions
- prefer-for-of
- no-constant-condition
- no-inner-declarations
- prefer-const
- prefer-rest-params
* fix resulting eslint errors
* ignore tobago-polyfill.ts
* refactor Page to add a test for getNamingContainerId()
---
tobago-theme/.eslintignore | 1 +
tobago-theme/.eslintrc.js | 23 +++--------
.../tobago-theme-standard/src/main/ts/faces.d.ts | 4 +-
.../src/main/ts/tobago-behavior.ts | 3 +-
.../src/main/ts/tobago-dropdown.ts | 3 +-
.../src/main/ts/tobago-overlay.ts | 2 +-
.../src/main/ts/tobago-page-static.test.ts | 29 ++++++++++++++
.../src/main/ts/tobago-page-static.ts | 45 ++++++++++++++++++++++
.../src/main/ts/tobago-page.ts | 34 +---------------
.../src/main/ts/tobago-select-list-base.ts | 2 +-
.../src/main/ts/tobago-select-many-list.ts | 4 +-
.../src/main/ts/tobago-sheet.ts | 3 +-
.../src/main/ts/tobago-tree-select.ts | 2 +-
13 files changed, 91 insertions(+), 64 deletions(-)
diff --git a/tobago-theme/.eslintignore b/tobago-theme/.eslintignore
index 802362022d..de79e5cdc7 100644
--- a/tobago-theme/.eslintignore
+++ b/tobago-theme/.eslintignore
@@ -3,3 +3,4 @@ lib/
node_modules/
target/
*.js
+tobago-polyfill.ts
diff --git a/tobago-theme/.eslintrc.js b/tobago-theme/.eslintrc.js
index 882644522a..4894c329aa 100644
--- a/tobago-theme/.eslintrc.js
+++ b/tobago-theme/.eslintrc.js
@@ -29,24 +29,11 @@ module.exports = {
sourceType: 'module',
},
rules: {
- "@typescript-eslint/array-type": "warn",
- "@typescript-eslint/consistent-indexed-object-style": "warn",
- "@typescript-eslint/consistent-type-assertions": "warn",
- "@typescript-eslint/consistent-type-definitions": "warn",
- "@typescript-eslint/no-explicit-any": "warn",
+ "@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
- "@typescript-eslint/prefer-for-of": "warn",
- "max-len": [
- "error",
- {
- "code": 120
- }
- ],
- "no-constant-condition": "warn",
- "no-inner-declarations": "warn",
- "no-irregular-whitespace": "warn",
- "no-multiple-empty-lines": "error",
- "prefer-const": "warn",
- "prefer-rest-params": "warn"
+ "@typescript-eslint/semi": "error",
+ "max-len": ["error", {"code": 120}],
+ "no-irregular-whitespace": "off",
+ "no-multiple-empty-lines": "error"
}
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/faces.d.ts b/tobago-theme/tobago-theme-standard/src/main/ts/faces.d.ts
index 2de6a7d5e7..3f9f90c3a4 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/faces.d.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/faces.d.ts
@@ -17,9 +17,7 @@
// Faces JS declarations. It's the best of what I've found out - with no guaranty!
-declare type Context = {
- [key: string]: any;
-};
+type Context = Record<string, any>;
declare interface EventData {
type: string;
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
index 7b817be3a6..61ed7b1df6 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
@@ -81,8 +81,7 @@ class Behavior extends HTMLElement {
if (this.render) {
// prepare overlay for all by AJAX reloaded elements
const partialIds = this.render.split(" ");
- for (let i = 0; i < partialIds.length; i++) {
- const partialId = partialIds[i];
+ for (const partialId of partialIds) {
const partialElement = document.getElementById(partialId);
if (partialElement) {
let id: string;
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts
index 9bfcd32fe2..34b07a8af7 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts
@@ -287,8 +287,7 @@ class Dropdown extends HTMLElement {
private getFocusedDropdownItem(dropdownItems: DropdownItem[]): DropdownItem {
if (dropdownItems) {
- for (let i = 0; i < dropdownItems.length; i++) {
- const dropdownItem = dropdownItems[i];
+ for (const dropdownItem of dropdownItems) {
const focusedDropdownItem = this.getFocusedDropdownItem(dropdownItem.children);
if (focusedDropdownItem != null) {
return focusedDropdownItem;
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts
index 4b9b245718..0ba6cda1ba 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts
@@ -110,7 +110,7 @@ export class Overlay extends HTMLElement {
* wait, error, ajax, drop-zone
*/
get type(): string {
- let attribute = this.getAttribute("type");
+ const attribute = this.getAttribute("type");
if (attribute) {
return attribute;
} else {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page-static.test.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page-static.test.ts
new file mode 100644
index 0000000000..a11329c70b
--- /dev/null
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page-static.test.ts
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import {PageStatic} from "./tobago-page-static";
+
+test("getNamingContainerId", () => {
+ expect(PageStatic.getNamingContainerId("a:b")).toBe("a");
+ expect(PageStatic.getNamingContainerId("a:b:c")).toBe("a:b");
+ expect(PageStatic.getNamingContainerId("a")).toBe(null);
+ expect(PageStatic.getNamingContainerId(null)).toBe(null);
+ expect(PageStatic.getNamingContainerId("d:e::sub-component")).toBe("d");
+ expect(PageStatic.getNamingContainerId("a::sub-component:b")).toBe("a::sub-component");
+});
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page-static.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page-static.ts
new file mode 100644
index 0000000000..4cef2efee0
--- /dev/null
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page-static.ts
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export class PageStatic {
+ /**
+ * "a:b" -> "a"
+ * "a:b:c" -> "a:b"
+ * "a" -> null
+ * null -> null
+ * "a:b::sub-component" -> "a"
+ * "a::sub-component:b" -> "a::sub-component" // should currently not happen in Tobago
+ *
+ * @param clientId The clientId of a component.
+ * @return The clientId of the naming container.
+ */
+ static getNamingContainerId(clientId: string): string {
+ if (clientId == null || clientId.lastIndexOf(":") === -1) {
+ return null;
+ }
+
+ const strings = Array.from(clientId);
+ for (let i = strings.length - 2; i > 0; i--) {
+ if (strings[i - 1] !== ":" && strings[i] === ":" && strings[i + 1] !== ":") {
+ return clientId.substring(0, i);
+ }
+ }
+ return null;
+ }
+}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts
index d1f68c158b..643b15983f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts
@@ -18,6 +18,7 @@
import {Overlay} from "./tobago-overlay";
import {OverlayType} from "./tobago-overlay-type";
import {Key} from "./tobago-key";
+import {PageStatic} from "./tobago-page-static";
export class Page extends HTMLElement {
@@ -39,37 +40,6 @@ export class Page extends HTMLElement {
return null;
}
- /**
- * "a:b" -> "a"
- * "a:b:c" -> "a:b"
- * "a" -> null
- * null -> null
- * "a:b::sub-component" -> "a"
- * "a::sub-component:b" -> "a::sub-component" // should currently not happen in Tobago
- *
- * @param clientId The clientId of a component.
- * @return The clientId of the naming container.
- */
- static getNamingContainerId(clientId: string): string {
- if (clientId == null || clientId.lastIndexOf(":") === -1) {
- return null;
- }
-
- let id = clientId;
- while (true) {
- const sub = id.lastIndexOf("::");
- if (sub == -1) {
- break;
- }
- if (sub + 1 == id.lastIndexOf(":")) {
- id = id.substring(0, sub);
- } else {
- break;
- }
- }
- return id.substring(0, id.lastIndexOf(":"));
- }
-
constructor() {
super();
}
@@ -101,7 +71,7 @@ export class Page extends HTMLElement {
command.dispatchEvent(new MouseEvent("click"));
break;
}
- id = Page.getNamingContainerId(id);
+ id = PageStatic.getNamingContainerId(id);
}
return false;
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-list-base.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-list-base.ts
index 98c780804d..8f426e5007 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-list-base.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-list-base.ts
@@ -213,7 +213,7 @@ export abstract class SelectListBase extends HTMLElement {
}
private tbodyClickEvent(event: MouseEvent): void {
- const target = <HTMLElement>event.target;
+ const target = event.target as HTMLElement;
const row = target.closest("tr");
this.select(row);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-many-list.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-many-list.ts
index c89ddd4fd3..2c2ddd0245 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-many-list.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-many-list.ts
@@ -33,7 +33,7 @@ class SelectManyList extends SelectListBase {
// init badges
this.querySelectorAll("option:checked").forEach(
- option => this.sync(<HTMLOptionElement>option)
+ option => this.sync((option as HTMLOptionElement))
);
}
@@ -119,7 +119,7 @@ class SelectManyList extends SelectListBase {
}
private removeBadge(event: MouseEvent): void {
- const target = <HTMLElement>event.target;
+ const target = event.target as HTMLElement;
const group: HTMLElement = target.closest(".btn-group");
const itemValue = group.dataset.tobagoValue;
const option: HTMLOptionElement = this.hiddenSelect.querySelector(`[value="${itemValue}"]`);
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
index c5433a2cb0..c664914fc4 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
@@ -434,8 +434,7 @@ export class Sheet extends HTMLElement {
let updates: NodeListOf<Element>;
if (event.status === "complete") {
updates = event.responseXML.querySelectorAll("update");
- for (let i = 0; i < updates.length; i++) {
- const update = updates[i];
+ for (const update of updates) {
const id = update.getAttribute("id");
if (this.id === id) { // is a Faces element id, but not a technical id from the framework
console.debug(`[tobago-sheet][complete] Update after faces.ajax complete: #${id}`); // @DEV_ONLY
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-select.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-select.ts
index 35845d6002..89ebb4baa8 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-select.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-select.ts
@@ -52,7 +52,7 @@ export class TreeSelect extends HTMLElement {
}
}
- selectChildren(treeSelectChildren: NodeListOf<TreeSelect>, checked: boolean, treeNodeIds: Array<string>): void {
+ selectChildren(treeSelectChildren: NodeListOf<TreeSelect>, checked: boolean, treeNodeIds: string[]): void {
for (const treeSelect of treeSelectChildren) {
if (treeSelect.input.checked !== checked) {
treeSelect.input.checked = checked;