Skip to content

Commit

Permalink
Fixing more eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Sep 4, 2023
1 parent 7d6d43f commit 25833ba
Show file tree
Hide file tree
Showing 18 changed files with 734 additions and 237 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"no-void": "off"
"@typescript-eslint/no-non-null-assertion": "off",
"no-void": "off",
"no-labels": "off"
}
}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
See Github for changes https://github.com/infernojs/inferno/releases
See GitHub for changes https://github.com/infernojs/inferno/releases
13 changes: 13 additions & 0 deletions documentation/v9-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# InfernoJS v9.0.0

## Breaking changes

Inferno v9 requires following features to be present in the executing runtime:

- `Promise`
- `Array.prototype.includes()`
- `Array.prototype.includes()`
- `Object.spread()`

`options.componentComparator` has been removed
`options.renderComplete` has been removed, same result can be achieved by calling own function after render
49 changes: 28 additions & 21 deletions packages/inferno-router/src/NavLink.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createComponentVNode, Inferno, VNode } from 'inferno';
import { createComponentVNode, type Inferno, type VNode } from 'inferno';
import { VNodeFlags } from 'inferno-vnode-flags';
import { Route } from './Route';
import { ILinkProps, Link } from './Link';
import { type ILinkProps, Link } from './Link';
import type { Location } from 'history';

function filter(i) {
function filter(i): any {
return i;
}

Expand Down Expand Up @@ -38,34 +38,41 @@ export function NavLink({
isActive: getIsActive,
ariaCurrent = 'true',
...rest
}: NavLinkProps & Omit<Inferno.LinkHTMLAttributes<HTMLLinkElement>, 'className' | 'style'>): any {
}: NavLinkProps &
Omit<
Inferno.LinkHTMLAttributes<HTMLLinkElement>,
'className' | 'style'
>): any {
function linkComponent({ location, match }): VNode {
const isActive = Boolean(getIsActive ? getIsActive(match, location) : match);
const isActive = Boolean(
getIsActive ? getIsActive(match, location) : match,
);

const className = typeof classNameProp === 'function' ? classNameProp(isActive) : classNameProp;
const className =
typeof classNameProp === 'function'
? classNameProp(isActive)
: classNameProp;

const style = typeof styleProp === 'function' ? styleProp(isActive) : styleProp;
const style =
typeof styleProp === 'function' ? styleProp(isActive) : styleProp;

return createComponentVNode(
VNodeFlags.ComponentFunction,
Link,
{
'aria-current': (isActive && ariaCurrent) || null,
className: isActive ? [className, activeClassName].filter(filter).join(' ') : className,
onClick,
style: isActive ? {...style, ...activeStyle} : style,
to,
...rest
},
)
);
return createComponentVNode(VNodeFlags.ComponentFunction, Link, {
'aria-current': ((isActive && ariaCurrent) || null) as any,
className: isActive
? [className, activeClassName].filter(filter).join(' ')
: className,
onClick,
style: isActive ? { ...style, ...activeStyle } : style,
to,
...rest,
});
}

return createComponentVNode(VNodeFlags.ComponentClass, Route, {
children: linkComponent as any,
exact,
location: linkLocation,
path: typeof to === 'object' ? to.pathname : to,
strict
strict,
});
}
2 changes: 1 addition & 1 deletion packages/inferno-router/src/Switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Switch extends Component<IRouteProps, SwitchState> {

if (match) {
location ??= context.router.route.location;
return createComponentVNode(_child.flags, _child.type, {..._child.props, ...{ location, computedMatch: match }}));
return createComponentVNode(_child.flags, _child.type, {..._child.props, ...{ location, computedMatch: match }});
}

return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/inferno-vnode-flags/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const enum VNodeFlags {
DOMRef = Element | Text | Portal,
InUseOrNormalized = InUse | Normalized,
ClearInUse = ~InUse,
ComponentKnown = ComponentFunction | ComponentClass
ComponentKnown = ComponentFunction | ComponentClass,
}

// Combinations are not possible, its bitwise only to reduce vNode size
Expand All @@ -42,5 +42,5 @@ export const enum ChildFlags {
HasKeyedChildren = 1 << 3,
HasTextChildren = 1 << 4,

MultipleChildren = HasNonKeyedChildren | HasKeyedChildren
MultipleChildren = HasNonKeyedChildren | HasKeyedChildren,
}
2 changes: 1 addition & 1 deletion packages/inferno/src/DOM/events/attachEvent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isFunction } from 'inferno-shared';

export function attachEvent(dom, eventName, handler) {
export function attachEvent(dom, eventName, handler): void {
const previousKey = `$${eventName}`;
const previousArgs = dom[previousKey];

Expand Down
12 changes: 6 additions & 6 deletions packages/inferno/src/DOM/events/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const attachedEvents = getDelegatedEventObject(null);

export const syntheticEvents = getDelegatedEventObject(true);

function updateOrAddSyntheticEvent(name: string, dom) {
function updateOrAddSyntheticEvent(name: string, dom): DelegateEventTypes {
let eventsObject = dom.$EV;

if (!eventsObject) {
Expand All @@ -63,7 +63,7 @@ function updateOrAddSyntheticEvent(name: string, dom) {
return eventsObject;
}

export function unmountSyntheticEvent(name: string, dom) {
export function unmountSyntheticEvent(name: string, dom): void {
const eventsObject = dom.$EV;

if (eventsObject?.[name]) {
Expand All @@ -80,10 +80,10 @@ export function unmountSyntheticEvent(name: string, dom) {

export function handleSyntheticEvent(
name: string,
lastEvent: Function | LinkedEvent<any, any> | null | false | true,
nextEvent: Function | LinkedEvent<any, any> | null | false | true,
lastEvent: (() => void) | LinkedEvent<any, any> | null | false | true,
nextEvent: (() => void) | LinkedEvent<any, any> | null | false | true,
dom,
) {
): void {
if (isFunction(nextEvent)) {
updateOrAddSyntheticEvent(name, dom)[name] = nextEvent;
} else if (isLinkEventObject(nextEvent)) {
Expand All @@ -97,7 +97,7 @@ export function handleSyntheticEvent(
}

// TODO: When browsers fully support event.composedPath we could loop it through instead of using parentNode property
function getTargetNode(event) {
function getTargetNode(event): any {
return isFunction(event.composedPath)
? event.composedPath()[0]
: event.target;
Expand Down
5 changes: 4 additions & 1 deletion packages/inferno/src/DOM/events/linkEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { isFunction, isNull } from 'inferno-shared';
* @param {Function} event Function to be called when event occurs
* @returns {{data: *, event: Function}}
*/
export function linkEvent<T, E extends Event>(data: T, event: (data: T, event: E) => void): LinkedEvent<T, E> | null {
export function linkEvent<T, E extends Event>(
data: T,
event: (data: T, event: E) => void,
): LinkedEvent<T, E> | null {
if (isFunction(event)) {
return { data, event };
}
Expand Down
21 changes: 10 additions & 11 deletions packages/inferno/src/DOM/mounting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VNode } from '../core/types';
import type { VNode, ContextObject } from '../core/types';
import {
isFunction,
isNull,
Expand Down Expand Up @@ -29,7 +29,6 @@ import {
} from './utils/componentUtil';
import { validateKeys } from '../core/validate';
import { mountRef } from '../core/refs';
import { ContextObject } from "../core/types";

export function mount(
vNode: VNode,
Expand Down Expand Up @@ -109,7 +108,7 @@ function mountPortal(
nextNode: Element | null,
lifecycle: Array<() => void>,
animations: AnimationQueues,
) {
): void {
mount(
vNode.children as VNode,
vNode.ref,
Expand Down Expand Up @@ -186,7 +185,7 @@ export function mountText(
export function mountElement(
vNode: VNode,
parentDOM: Element | null,
context: unknown,
context: ContextObject,
isSVG: boolean,
nextNode: Element | null,
lifecycle: Array<() => void>,
Expand Down Expand Up @@ -269,7 +268,7 @@ export function mountElement(
export function mountArrayChildren(
children,
dom: Element | null,
context: Object,
context: ContextObject,
isSVG: boolean,
nextNode: Element | null,
lifecycle: Array<() => void>,
Expand All @@ -288,12 +287,12 @@ export function mountArrayChildren(
export function mountClassComponent(
vNode: VNode,
parentDOM: Element | null,
context: Object,
context: ContextObject,
isSVG: boolean,
nextNode: Element | null,
lifecycle: Array<() => void>,
animations: AnimationQueues,
) {
): void {
const instance = createClassComponentInstance(
vNode,
vNode.type,
Expand Down Expand Up @@ -323,7 +322,7 @@ export function mountClassComponent(
export function mountFunctionalComponent(
vNode: VNode,
parentDOM: Element | null,
context: Object,
context: ContextObject,
isSVG: boolean,
nextNode: Element | null,
lifecycle,
Expand Down Expand Up @@ -360,7 +359,7 @@ function addAppearAnimationHook(
dom: Element,
flags: VNodeFlags,
props,
) {
): void {
animations.componentDidAppear.push(() => {
if (flags & VNodeFlags.ComponentClass) {
instanceOrRef.componentDidAppear(dom);
Expand All @@ -375,7 +374,7 @@ export function mountClassComponentCallbacks(
instance,
lifecycle: Array<() => void>,
animations: AnimationQueues,
) {
): void {
mountRef(ref, instance, lifecycle);

if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -421,7 +420,7 @@ export function mountFunctionalComponentCallbacks(
vNode: VNode,
lifecycle: Array<() => void>,
animations: AnimationQueues,
) {
): void {
const ref = vNode.ref;

if (!isNullOrUndef(ref)) {
Expand Down
Loading

0 comments on commit 25833ba

Please sign in to comment.