Refactor code to comply with ESLint rules
Major refactoring using ESLint with rules from AirBnb and Vue. Enable most of the ESLint rules and do necessary linting in the code. Also add more information for rules that are disabled to describe what they are and why they are disabled. Allow logging (`console.log`) in test files, and in development mode (e.g. when working with `npm run serve`), but disable it when environment is production (as pre-configured by Vue). Also add flag (`--mode production`) in `lint:eslint` command so production linting is executed earlier in lifecycle. Disable rules that requires a separate work. Such as ESLint rules that are broken in TypeScript: no-useless-constructor (eslint/eslint#14118) and no-shadow (eslint/eslint#13014).
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
<template>
|
||||
<Responsive v-on:widthChanged="width = $event">
|
||||
<!-- <div id="responsivity-debug">
|
||||
Width: {{ width || 'undefined' }}
|
||||
Size: <span v-if="width <= 500">small</span><span v-if="width > 500 && width < 750">medium</span><span v-if="width >= 750">big</span>
|
||||
</div> -->
|
||||
<!--
|
||||
<div id="responsivity-debug">
|
||||
Width: {{ width || 'undefined' }}
|
||||
Size:
|
||||
<span v-if="width <= 500">small</span>
|
||||
<span v-if="width > 500 && width < 750">medium</span>
|
||||
<span v-if="width >= 750">big</span>
|
||||
</div>
|
||||
-->
|
||||
<div v-if="categoryIds != null && categoryIds.length > 0" class="cards">
|
||||
<CardListItem
|
||||
class="card"
|
||||
v-bind:class="{
|
||||
v-bind:class="{
|
||||
'small-screen': width <= 500,
|
||||
'medium-screen': width > 500 && width < 750,
|
||||
'big-screen': width >= 750
|
||||
'big-screen': width >= 750
|
||||
}"
|
||||
v-for="categoryId of categoryIds"
|
||||
:data-category="categoryId"
|
||||
@@ -25,13 +30,13 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import CardListItem from './CardListItem.vue';
|
||||
import Responsive from '@/presentation/components/Shared/Responsive.vue';
|
||||
import { Component } from 'vue-property-decorator';
|
||||
import Responsive from '@/presentation/components/Shared/Responsive.vue';
|
||||
import { StatefulVue } from '@/presentation/components/Shared/StatefulVue';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
import { hasDirective } from './NonCollapsingDirective';
|
||||
import { IReadOnlyCategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
|
||||
import { hasDirective } from './NonCollapsingDirective';
|
||||
import CardListItem from './CardListItem.vue';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
@@ -40,8 +45,10 @@ import { IReadOnlyCategoryCollectionState } from '@/application/Context/State/IC
|
||||
},
|
||||
})
|
||||
export default class CardList extends StatefulVue {
|
||||
public width: number = 0;
|
||||
public width = 0;
|
||||
|
||||
public categoryIds: number[] = [];
|
||||
|
||||
public activeCategoryId?: number = null;
|
||||
|
||||
public created() {
|
||||
@@ -75,9 +82,10 @@ export default class CardList extends StatefulVue {
|
||||
}
|
||||
this.activeCategoryId = null;
|
||||
}
|
||||
|
||||
private outsideClickListener(event: PointerEvent) {
|
||||
if (this.areAllCardsCollapsed()) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
const element = document.querySelector(`[data-category="${this.activeCategoryId}"]`);
|
||||
const target = event.target as Element;
|
||||
@@ -89,6 +97,7 @@ export default class CardList extends StatefulVue {
|
||||
private collapseAllCards(): void {
|
||||
this.activeCategoryId = undefined;
|
||||
}
|
||||
|
||||
private areAllCardsCollapsed(): boolean {
|
||||
return !this.activeCategoryId;
|
||||
}
|
||||
@@ -96,10 +105,10 @@ export default class CardList extends StatefulVue {
|
||||
|
||||
function isClickable(element: Element) {
|
||||
const cursorName = window.getComputedStyle(element).cursor;
|
||||
return [ 'pointer', 'move', 'grab'].some((name) => cursorName === name)
|
||||
return ['pointer', 'move', 'grab'].some((name) => cursorName === name)
|
||||
|| cursorName.includes('resize')
|
||||
|| [ 'onclick', 'href'].some((attributeName) => element.hasAttribute(attributeName))
|
||||
|| [ 'a', 'button'].some((tagName) => element.closest(`.${tagName}`));
|
||||
|| ['onclick', 'href'].some((attributeName) => element.hasAttribute(attributeName))
|
||||
|| ['a', 'button'].some((tagName) => element.closest(`.${tagName}`));
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -112,9 +121,10 @@ function isClickable(element: Element) {
|
||||
flex-flow: row wrap;
|
||||
font-family: $font-main;
|
||||
gap: $card-gap;
|
||||
/*
|
||||
/*
|
||||
Padding is used to allow scale animation (growing size) for cards on hover.
|
||||
It ensures that there's room to grow, so the animation is shown without overflowing with scrollbars.
|
||||
It ensures that there's room to grow, so the animation is shown without overflowing
|
||||
with scrollbars.
|
||||
*/
|
||||
padding: 10px;
|
||||
}
|
||||
@@ -125,4 +135,4 @@ function isClickable(element: Element) {
|
||||
font-size: 3.5em;
|
||||
font-family: $font-normal;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user