Skip to content

Commit

Permalink
revert rules
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Jan 19, 2022
1 parent b9bf888 commit 557d973
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 95 deletions.
13 changes: 3 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,7 @@ module.exports = {
],
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-parameter-properties': 'error',
'@typescript-eslint/strict-boolean-expressions': [
'error',
{
allowString: false,
allowNumber: false,
allowNullableObject: false
}
]
'@typescript-eslint/strict-boolean-expressions': 'off'
}
},
{
Expand All @@ -145,7 +138,7 @@ module.exports = {
'no-template-curly-in-string': 'error',
'array-callback-return': 'error',
'consistent-return': 'error',
curly: 'warn',
curly: 'off',
'default-param-last': 'error',
eqeqeq: 'error',
'no-constructor-return': 'error',
Expand All @@ -154,7 +147,7 @@ module.exports = {
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-floating-decimal': 'error',
'no-implicit-coercion': 'error',
'no-implicit-coercion': 'off',
'no-implicit-globals': 'error',
'no-implied-eval': 'error',
'no-invalid-this': 'error',
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/plugins/metadata/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<tbody>
${props
.map(prop => {
const hasAttribute = typeof prop.attribute !== 'undefined';
const hasAttribute = !!prop.attribute;
const isAttributeDifferent = prop.attribute !== prop.name;
let attributeInfo = '';
Expand Down Expand Up @@ -266,7 +266,7 @@
}

function escapeHtml(html) {
if (typeof html === 'undefined') {
if (!html) {
return '';
}
return html
Expand Down
10 changes: 5 additions & 5 deletions src/components/animation/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class SlAnimation extends LitElement {
}

set currentTime(time: number) {
if (typeof this.animation !== 'undefined') {
if (this.animation) {
this.animation.currentTime = time;
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ export default class SlAnimation extends LitElement {

@watch('play')
handlePlayChange() {
if (typeof this.animation !== 'undefined') {
if (this.animation) {
if (this.play && !this.hasStarted) {
this.hasStarted = true;
emit(this, 'sl-start');
Expand All @@ -145,7 +145,7 @@ export default class SlAnimation extends LitElement {

@watch('playbackRate')
handlePlaybackRateChange() {
if (typeof this.animation !== 'undefined') {
if (this.animation) {
this.animation.playbackRate = this.playbackRate;
}
}
Expand All @@ -162,7 +162,7 @@ export default class SlAnimation extends LitElement {
const slot = await this.defaultSlot;
const element = slot.assignedElements()[0] as HTMLElement | undefined;

if (typeof element === 'undefined' || typeof keyframes === 'undefined') {
if (!element || !keyframes) {
return false;
}

Expand Down Expand Up @@ -192,7 +192,7 @@ export default class SlAnimation extends LitElement {
}

destroyAnimation() {
if (typeof this.animation !== 'undefined') {
if (this.animation) {
this.animation.cancel();
this.animation.removeEventListener('cancel', this.handleAnimationCancel);
this.animation.removeEventListener('finish', this.handleAnimationFinish);
Expand Down
3 changes: 1 addition & 2 deletions src/components/avatar/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { customElement, property, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import styles from './avatar.styles';
import '~/components/icon/icon';
import { isTruthy } from '~/internal/is-truthy';

/**
* @since 2.0
Expand Down Expand Up @@ -51,7 +50,7 @@ export default class SlAvatar extends LitElement {
role="img"
aria-label=${this.label}
>
${isTruthy(this.initials)
${this.initials
? html` <div part="initials" class="avatar__initials">${this.initials}</div> `
: html`
<div part="icon" class="avatar__icon" aria-hidden="true">
Expand Down
9 changes: 4 additions & 5 deletions src/components/breadcrumb-item/breadcrumb-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { customElement, property } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import styles from './breadcrumb-item.styles';
import { isTruthy } from '~/internal/is-truthy';
import { HasSlotController } from '~/internal/slot';

/**
Expand Down Expand Up @@ -41,7 +40,7 @@ export default class SlBreadcrumbItem extends LitElement {
@property() rel = 'noreferrer noopener';

render() {
const isLink = typeof this.href !== 'undefined';
const isLink = this.href ? true : false;

return html`
<div
Expand All @@ -61,9 +60,9 @@ export default class SlBreadcrumbItem extends LitElement {
<a
part="label"
class="breadcrumb-item__label breadcrumb-item__label--link"
href="${this.href}"
target="${this.target}"
rel=${ifDefined(isTruthy(this.target) ? this.rel : undefined)}
href="${this.href!}"
target="${ifDefined(this.target ? this.target : undefined)}"
rel=${ifDefined(this.target ? this.rel : undefined)}
>
<slot></slot>
</a>
Expand Down
5 changes: 2 additions & 3 deletions src/components/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import styles from './button.styles';
import '~/components/spinner/spinner';
import { emit } from '~/internal/event';
import { FormSubmitController } from '~/internal/form-control';
import { isTruthy } from '~/internal/is-truthy';
import { HasSlotController } from '~/internal/slot';

/**
Expand Down Expand Up @@ -124,7 +123,7 @@ export default class SlButton extends LitElement {
}

render() {
const isLink = typeof this.href !== 'undefined';
const isLink = this.href ? true : false;
const tag = isLink ? literal`a` : literal`button`;

/* eslint-disable lit/binding-positions, lit/no-invalid-html */
Expand Down Expand Up @@ -162,7 +161,7 @@ export default class SlButton extends LitElement {
href=${ifDefined(this.href)}
target=${ifDefined(this.target)}
download=${ifDefined(this.download)}
rel=${ifDefined(isTruthy(this.target) ? 'noreferrer noopener' : undefined)}
rel=${ifDefined(this.target ? 'noreferrer noopener' : undefined)}
role="button"
aria-disabled=${this.disabled ? 'true' : 'false'}
tabindex=${this.disabled ? '-1' : '0'}
Expand Down
13 changes: 6 additions & 7 deletions src/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type SlMenuItem from '~/components/menu-item/menu-item';
import type SlMenu from '~/components/menu/menu';
import { animateTo, stopAnimations } from '~/internal/animate';
import { emit, waitForEvent } from '~/internal/event';
import { isTruthy } from '~/internal/is-truthy';
import { scrollIntoView } from '~/internal/scroll';
import { getTabbableBoundary } from '~/internal/tabbable';
import { watch } from '~/internal/watch';
Expand Down Expand Up @@ -95,7 +94,7 @@ export default class SlDropdown extends LitElement {
this.handleDocumentKeyDown = this.handleDocumentKeyDown.bind(this);
this.handleDocumentMouseDown = this.handleDocumentMouseDown.bind(this);

if (typeof this.containingElement === 'undefined') {
if (!this.containingElement) {
this.containingElement = this;
}

Expand Down Expand Up @@ -177,7 +176,7 @@ export default class SlDropdown extends LitElement {
: document.activeElement;

if (
!isTruthy(this.containingElement) ||
!this.containingElement ||
activeElement?.closest(this.containingElement.tagName.toLowerCase()) !== this.containingElement
) {
this.hide();
Expand All @@ -189,7 +188,7 @@ export default class SlDropdown extends LitElement {
handleDocumentMouseDown(event: MouseEvent) {
// Close when clicking outside of the containing element
const path = event.composedPath();
if (isTruthy(this.containingElement) && !path.includes(this.containingElement)) {
if (this.containingElement && !path.includes(this.containingElement)) {
this.hide();
}
}
Expand Down Expand Up @@ -275,13 +274,13 @@ export default class SlDropdown extends LitElement {
}

// Focus on a menu item
if (event.key === 'ArrowDown' && typeof firstMenuItem !== 'undefined') {
if (event.key === 'ArrowDown') {
menu!.setCurrentItem(firstMenuItem);
firstMenuItem.focus();
return;
}

if (event.key === 'ArrowUp' && typeof lastMenuItem !== 'undefined') {
if (event.key === 'ArrowUp') {
menu!.setCurrentItem(lastMenuItem);
lastMenuItem.focus();
return;
Expand Down Expand Up @@ -321,7 +320,7 @@ export default class SlDropdown extends LitElement {
const assignedElements = slot.assignedElements({ flatten: true }) as HTMLElement[];
const accessibleTrigger = assignedElements.find(el => getTabbableBoundary(el).start);

if (typeof accessibleTrigger !== 'undefined') {
if (accessibleTrigger) {
accessibleTrigger.setAttribute('aria-haspopup', 'true');
accessibleTrigger.setAttribute('aria-expanded', this.open ? 'true' : 'false');
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/icon-button/icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import styles from './icon-button.styles';
import '~/components/icon/icon';
import { isTruthy } from '~/internal/is-truthy';

/**
* @since 2.0
Expand Down Expand Up @@ -48,7 +47,7 @@ export default class SlIconButton extends LitElement {
@property({ type: Boolean, reflect: true }) disabled = false;

render() {
const isLink = typeof this.href !== 'undefined';
const isLink = this.href ? true : false;

const interior = html`
<sl-icon
Expand All @@ -67,7 +66,7 @@ export default class SlIconButton extends LitElement {
href=${ifDefined(this.href)}
target=${ifDefined(this.target)}
download=${ifDefined(this.download)}
rel=${ifDefined(isTruthy(this.target) ? 'noreferrer noopener' : undefined)}
rel=${ifDefined(this.target ? 'noreferrer noopener' : undefined)}
role="button"
aria-disabled=${this.disabled ? 'true' : 'false'}
aria-label="${this.label}"
Expand Down
4 changes: 2 additions & 2 deletions src/components/icon/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class SlIcon extends LitElement {

private getUrl() {
const library = getIconLibrary(this.library);
if (typeof this.name !== 'undefined' && typeof library !== 'undefined') {
if (this.name && library) {
return library.resolver(this.name);
}
return this.src;
Expand All @@ -74,7 +74,7 @@ export default class SlIcon extends LitElement {
async setIcon() {
const library = getIconLibrary(this.library);
const url = this.getUrl();
if (typeof url !== 'undefined' && url.length > 0) {
if (url) {
try {
const file = await requestIcon(url);
if (url !== this.getUrl()) {
Expand Down
4 changes: 0 additions & 4 deletions src/components/include/include.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export default class SlInclude extends LitElement {
return;
}

if (typeof file === 'undefined') {
return;
}

if (!file.ok) {
emit(this, 'sl-error', { detail: { status: file.status } });
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class SlMenu extends LitElement {
if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) {
const items = this.getAllItems({ includeDisabled: false });
const activeItem = this.getCurrentItem();
let index = typeof activeItem !== 'undefined' ? items.indexOf(activeItem) : 0;
let index = activeItem ? items.indexOf(activeItem) : 0;

if (items.length > 0) {
event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion src/components/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class SlRadio extends LitElement {
radio.input.tabIndex = -1;
});

if (typeof checkedRadio !== 'undefined') {
if (checkedRadio) {
checkedRadio.input.tabIndex = 0;
} else if (radios.length > 0) {
radios[0].input.tabIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/components/range/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class SlRange extends LitElement {
super.connectedCallback();
this.resizeObserver = new ResizeObserver(() => this.syncRange());

if (typeof this.value === 'undefined') {
if (!this.value) {
this.value = this.min;
}
if (this.value < this.min) {
Expand Down
8 changes: 4 additions & 4 deletions src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ export default class SlSelect extends LitElement {
}

// Focus on a menu item
if (event.key === 'ArrowDown' && typeof firstItem !== 'undefined') {
if (event.key === 'ArrowDown') {
this.menu.setCurrentItem(firstItem);
firstItem.focus();
return;
}

if (event.key === 'ArrowUp' && typeof lastItem !== 'undefined') {
if (event.key === 'ArrowUp') {
this.menu.setCurrentItem(lastItem);
lastItem.focus();
return;
Expand Down Expand Up @@ -343,7 +343,7 @@ export default class SlSelect extends LitElement {
return false;
});

if (typeof clearButton !== 'undefined') {
if (clearButton) {
event.stopPropagation();
}
}
Expand Down Expand Up @@ -408,7 +408,7 @@ export default class SlSelect extends LitElement {
} else {
const checkedItem = items.find(item => item.value === value[0]);

this.displayLabel = typeof checkedItem !== 'undefined' ? this.getItemLabel(checkedItem) : '';
this.displayLabel = checkedItem ? this.getItemLabel(checkedItem) : '';
this.displayTags = [];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/split-panel/split-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class SlSplitPanel extends LitElement {
}

// Check snap points
if (typeof this.snap !== 'undefined') {
if (this.snap) {
const snaps = this.snap.split(' ');

snaps.forEach(value => {
Expand Down Expand Up @@ -190,7 +190,7 @@ export default class SlSplitPanel extends LitElement {
this.size = this.vertical ? height : width;

// Resize when a primary panel is set
if (typeof this.primary !== 'undefined') {
if (this.primary) {
this.position = this.pixelsToPercentage(this.cachedPositionInPixels);
}
}
Expand Down

0 comments on commit 557d973

Please sign in to comment.