Skip to content

Commit c2e901f

Browse files
authored
fix(eslint-config): add more formatting rules (#2441)
* fix(eslint-config): add more formatting rules * style: lint typescript/javascript files
1 parent ed747e9 commit c2e901f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+107
-93
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@patternfly/eslint-config-elements": patch
3+
---
4+
Added more formatting rules (infix spacing and type annotation spacing).

core/pfe-core/controllers/cascade-controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { debounce } from '../functions/debounce.js';
55
import { Logger } from './logger.js';
66

77
export interface Options<E extends ReactiveElement> {
8-
properties: Partial<Record<keyof E, string|string[]>>;
8+
properties: Partial<Record<keyof E, string | string[]>>;
99
prefix?: string;
1010
}
1111

@@ -49,7 +49,7 @@ export class CascadeController<E extends ReactiveElement> implements ReactiveCon
4949
* Handles the cascading of properties to nested components when new elements are added
5050
* Attribute updates/additions are handled by the attribute callback
5151
*/
52-
cascadeProperties(nodeList: HTMLCollection|NodeList = this.host.children) {
52+
cascadeProperties(nodeList: HTMLCollection | NodeList = this.host.children) {
5353
if (this.host.isConnected) {
5454
const selectors = this.cache.keys();
5555

@@ -84,7 +84,7 @@ export class CascadeController<E extends ReactiveElement> implements ReactiveCon
8484
* falling back to the lowercased property name, and caches the attribute name
8585
* with it's designated child selectors for value-propagation on change
8686
*/
87-
initProp(propName: string, cascade: string|string[]) {
87+
initProp(propName: string, cascade: string | string[]) {
8888
for (const nodeItem of [cascade].flat(Infinity).filter(Boolean) as string[]) {
8989
const { attribute } = this.class.getPropertyOptions(propName);
9090

core/pfe-core/controllers/floating-dom-controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
flip as flipMiddleware,
1515
} from '@floating-ui/dom';
1616

17-
type Lazy<T> = T|(() => T|null|undefined);
17+
type Lazy<T> = T | (() => T | null | undefined);
1818

1919
interface FloatingDOMControllerOptions {
2020
content: Lazy<HTMLElement>;
@@ -30,8 +30,8 @@ interface ShowOptions {
3030
placement?: Placement;
3131
}
3232

33-
export type Anchor = ''|'top'|'left'|'bottom'|'right';
34-
export type Alignment = 'center'|'start'|'end';
33+
export type Anchor = '' | 'top' | 'left' | 'bottom' | 'right';
34+
export type Alignment = 'center' | 'start' | 'end';
3535

3636
/**
3737
* Controls floating DOM within a web component, e.g. tooltips and popovers

core/pfe-core/controllers/light-dom-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ReactiveController, ReactiveElement } from 'lit';
33
import { Logger } from './logger.js';
44

55
export interface Options {
6-
observe?: boolean|MutationObserverInit;
6+
observe?: boolean | MutationObserverInit;
77
emptyWarning?: string;
88
}
99

core/pfe-core/controllers/roving-tabindex-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class RovingTabindexController implements ReactiveController {
161161
/**
162162
* sets tabindex of item based on whether or not it is active
163163
*/
164-
updateActiveItem(item?: HTMLElement):void {
164+
updateActiveItem(item?: HTMLElement): void {
165165
if (item) {
166166
if (!!this.#activeItem && item !== this.#activeItem) {
167167
this.#activeItem.tabIndex = -1;
@@ -174,7 +174,7 @@ export class RovingTabindexController implements ReactiveController {
174174
/**
175175
* focuses on an item and sets it as active
176176
*/
177-
focusOnItem(item?: HTMLElement):void {
177+
focusOnItem(item?: HTMLElement): void {
178178
this.updateActiveItem(item || this.firstItem);
179179
this.#activeItem?.focus();
180180
}

core/pfe-core/controllers/scroll-spy-controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ScrollSpyControllerOptions extends IntersectionObserverInit {
2222
* function to call on link children to get their URL hash (i.e. id to scroll to)
2323
* @default el => el.getAttribute('href');
2424
*/
25-
getHash?: (el: Element) => string|null;
25+
getHash?: (el: Element) => string | null;
2626
}
2727

2828
export class ScrollSpyController implements ReactiveController {
@@ -42,10 +42,10 @@ export class ScrollSpyController implements ReactiveController {
4242

4343
#root: ScrollSpyControllerOptions['root'];
4444
#rootMargin?: string;
45-
#threshold: number|number[];
45+
#threshold: number | number[];
4646

4747
#rootNode: Node;
48-
#getHash: (el: Element) => string|null;
48+
#getHash: (el: Element) => string | null;
4949

5050
get #linkChildren(): Element[] {
5151
return Array.from(this.host.querySelectorAll(this.#tagNames.join(',')))
@@ -122,7 +122,7 @@ export class ScrollSpyController implements ReactiveController {
122122
}
123123
}
124124

125-
#setActive(link?: EventTarget|null) {
125+
#setActive(link?: EventTarget | null) {
126126
for (const child of this.#linkChildren) {
127127
child.toggleAttribute(this.#activeAttribute, child === link);
128128
}
@@ -154,7 +154,7 @@ export class ScrollSpyController implements ReactiveController {
154154
}
155155

156156
/** Explicitly set the active item */
157-
public async setActive(link: EventTarget|null) {
157+
public async setActive(link: EventTarget | null) {
158158
this.#force = true;
159159
this.#setActive(link);
160160
let sawActive = false;

core/pfe-core/controllers/slot-controller.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import { Logger } from './logger.js';
66
interface AnonymousSlot {
77
hasContent: boolean;
88
elements: Element[];
9-
slot: HTMLSlotElement|null;
9+
slot: HTMLSlotElement | null;
1010
}
1111

1212
interface NamedSlot extends AnonymousSlot {
1313
name: string;
1414
initialized: true;
1515
}
1616

17-
export type Slot = NamedSlot|AnonymousSlot;
17+
export type Slot = NamedSlot | AnonymousSlot;
1818

1919
export interface SlotsConfig {
20-
slots: (string|null)[];
20+
slots: (string | null)[];
2121
/**
2222
* Object mapping new slot name keys to deprecated slot name values
2323
* @example `pf-modal--header` is deprecated in favour of `header`
@@ -33,7 +33,7 @@ export interface SlotsConfig {
3333
deprecations?: Record<string, string>;
3434
}
3535

36-
function isObjectConfigSpread(config: ([SlotsConfig]|(string|null)[])): config is [SlotsConfig] {
36+
function isObjectConfigSpread(config: ([SlotsConfig] | (string | null)[])): config is [SlotsConfig] {
3737
return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;
3838
}
3939

@@ -42,27 +42,27 @@ function isObjectConfigSpread(config: ([SlotsConfig]|(string|null)[])): config i
4242
* for the default slot, look for direct children not assigned to a slot
4343
*/
4444
const isSlot =
45-
<T extends Element = Element>(n: string|typeof SlotController.anonymous) =>
45+
<T extends Element = Element>(n: string | typeof SlotController.anonymous) =>
4646
(child: Element): child is T =>
4747
n === SlotController.anonymous ? !child.hasAttribute('slot')
4848
: child.getAttribute('slot') === n;
4949

5050
export class SlotController implements ReactiveController {
5151
public static anonymous = Symbol('anonymous slot');
5252

53-
private nodes = new Map<string|typeof SlotController.anonymous, Slot>();
53+
private nodes = new Map<string | typeof SlotController.anonymous, Slot>();
5454

5555
private logger: Logger;
5656

5757
private firstUpdated = false;
5858

5959
private mo = new MutationObserver(this.onMutation);
6060

61-
private slotNames: (string|null)[];
61+
private slotNames: (string | null)[];
6262

6363
private deprecations: Record<string, string> = {};
6464

65-
constructor(public host: ReactiveElement, ...config: ([SlotsConfig]|(string|null)[])) {
65+
constructor(public host: ReactiveElement, ...config: ([SlotsConfig] | (string | null)[])) {
6666
this.logger = new Logger(this.host);
6767

6868
if (isObjectConfigSpread(config)) {
@@ -163,12 +163,12 @@ export class SlotController implements ReactiveController {
163163
}
164164
}
165165

166-
private getChildrenForSlot<T extends Element = Element>(name: string|typeof SlotController.anonymous): T[] {
166+
private getChildrenForSlot<T extends Element = Element>(name: string | typeof SlotController.anonymous): T[] {
167167
const children = Array.from(this.host.children) as T[];
168168
return children.filter(isSlot(name));
169169
}
170170

171-
@bound private initSlot(slotName: string|null) {
171+
@bound private initSlot(slotName: string | null) {
172172
const name = slotName || SlotController.anonymous;
173173
const elements = this.nodes.get(name)?.slot?.assignedElements?.() ?? this.getChildrenForSlot(name);
174174
const selector = slotName ? `slot[name="${slotName}"]` : 'slot:not([name])';

core/pfe-core/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface PfeConfig {
1313
const noPref = Symbol();
1414

1515
/** Retrieve an HTML metadata item */
16-
function getMeta(name: string): string|undefined {
16+
function getMeta(name: string): string | undefined {
1717
return document.head.querySelector<HTMLMetaElement>(`meta[name="${name}"]`)?.content;
1818
}
1919

@@ -33,7 +33,7 @@ export function trackPerformance(preference: boolean | typeof noPref = noPref) {
3333
* A LitElement property converter which represents a list of numbers as a comma separated string
3434
* @see https://lit.dev/docs/components/properties/#conversion-converter
3535
*/
36-
export const NumberListConverter: ComplexAttributeConverter<null|number[]> = {
36+
export const NumberListConverter: ComplexAttributeConverter<null | number[]> = {
3737
fromAttribute(value: string) {
3838
if (typeof value !== 'string') {
3939
return null;

core/pfe-core/decorators/observed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type TypedFieldDecorator<T> = (proto: T, key: string | keyof T) => void ;
4040
export function observed<T extends ReactiveElement>(methodName: string): TypedFieldDecorator<T>
4141
export function observed<T extends ReactiveElement>(cb: ChangeCallback<T>): TypedFieldDecorator<T>
4242
export function observed<T extends ReactiveElement>(proto: T, key: string): void
43-
export function observed<T extends ReactiveElement>(...as: any[]): void|TypedFieldDecorator<T> {
43+
export function observed<T extends ReactiveElement>(...as: any[]): void | TypedFieldDecorator<T> {
4444
/** @observed('_myCustomChangeCallback') */
4545
if (as.length === 1) {
4646
const [methodNameOrCallback] = as;

core/pfe-core/functions/debounce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function debounce(
1111
delay: number,
1212
immediate = false
1313
) {
14-
let timeout: number|null;
14+
let timeout: number | null;
1515
return function(this: unknown, ...args: any[]) {
1616
// eslint-disable-next-line @typescript-eslint/no-this-alias
1717
const context = this;

0 commit comments

Comments
 (0)