Skip to content

Commit

Permalink
Update eslint and presets; stricter rules; fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
danimoh committed Feb 12, 2020
1 parent fbac956 commit 42941d1
Show file tree
Hide file tree
Showing 51 changed files with 1,027 additions and 642 deletions.
88 changes: 71 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,72 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-extraneous-dependencies
const airbnb = require('eslint-config-airbnb-base/rules/style');
// Do not restrict usage of for...of
const noRestrictedSyntax = airbnb.rules['no-restricted-syntax'].slice(1).filter((r) => r.selector !== 'ForOfStatement');
const memberDelimiterStyleOverrides = {
overrides: { typeLiteral: { multiline: { delimiter: 'comma' }, singleline: { delimiter: 'comma' } } },
};
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'eslint:recommended',
'@vue/typescript'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
},
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
env: {
browser: true,
es6: true,
},
extends: [
'plugin:vue/essential',
'@vue/airbnb',
'@vue/typescript/recommended',
],
parserOptions: {
ecmaVersion: 2020,
},
root: true,
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'function-paren-newline': 'off',
indent: ['error', 4, { SwitchCase: 1 }],
'max-len': ['error', 120],
'no-underscore-dangle': 'off',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-continue': 'off',
'no-confusing-arrow': 'off',
'no-floating-decimal': 'off',
'no-return-assign': 'off',
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
'import/prefer-default-export': 'off',
'implicit-arrow-linebreak': 'off',
'object-curly-newline': ['error', { ObjectPattern: { multiline: true } }],
'prefer-const': ['error', { destructuring: 'all' }],
'no-nested-ternary': 'off',
'no-restricted-syntax': ['error', ...noRestrictedSyntax],

'@typescript-eslint/member-delimiter-style': ['error', memberDelimiterStyleOverrides],
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',

/*
// TODO these rules have been used on previous versions of typescript-eslint and the linter presets and might
// not be necessary anymore
// Typescript plugin replacements
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'error',
// False positives that are checked by TS
'no-redeclare': 'off',
'no-param-reassign': 'off',
'import/no-unresolved': 'off',
'no-use-before-define': 'off',
*/
},
overrides: [{
files: ['src/components/icons/*'],
rules: {
'max-len': 'off',
},
}],
};
14 changes: 7 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
],
}
presets: [
'@vue/cli-plugin-babel/preset',
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
],
};
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"serve": "vue-cli-service serve --port 8081",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"lint": "vue-cli-service lint --no-fix",
"test": "echo 'No tests'",
"i18n:extract": "node ./node_modules/translation-key-extractor/index.js ./src/i18n/en.po",
"i18n:push": "tx push --source",
Expand All @@ -28,23 +28,27 @@
"v-click-outside": "^3.0.1",
"vue": "^2.6.11",
"vue-i18n": "^8.15.3",
"vue-property-decorator": "^8.4.0",
"vue-router": "^3.1.5",
"vue-virtual-scroller": "^1.0.0-rc.2"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
"@fullhuman/postcss-purgecss": "^1.3.0",
"@nimiq/core-web": "^1.5.4",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"@typescript-eslint/parser": "^2.19.2",
"@vue/cli-plugin-babel": "^4.2.2",
"@vue/cli-plugin-eslint": "^4.2.2",
"@vue/cli-plugin-pwa": "^4.2.2",
"@vue/cli-plugin-typescript": "^4.2.2",
"@vue/cli-service": "^4.2.2",
"@vue/eslint-config-typescript": "^4.0.0",
"@vue/eslint-config-airbnb": "^5.0.2",
"@vue/eslint-config-typescript": "^5.0.1",
"copy-webpack-plugin": "^5.1.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-vue": "^6.1.2",
"node-sass": "^4.13.1",
"po-loader": "https://github.com/Yukiioz/po-loader.git#master",
"sass-loader": "^8.0.2",
Expand Down
20 changes: 13 additions & 7 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
const autoprefixer = require('autoprefixer')
const postcssPurgecss = require(`@fullhuman/postcss-purgecss`)
/* eslint-disable @typescript-eslint/no-var-requires, import/no-extraneous-dependencies, no-unused-vars */
const autoprefixer = require('autoprefixer');

const purgecss = postcssPurgecss({
const postcssPurgecss = require('@fullhuman/postcss-purgecss');

/* const purgecss = */postcssPurgecss({
// Specify the paths to all of the template files in your project.
content: [
'./public/**/*.html',
'./src/**/*.vue',
],
// Include any special characters you're using in this regular expression.
// See: https://tailwindcss.com/docs/controlling-file-size/#understanding-the-regex
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || [],
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
// Whitelist auto generated classes for transitions and router links.
// From: https://github.com/ky-is/vue-cli-plugin-tailwind
// whitelistPatterns: [/-(leave|enter|appear)(|-(to|from|active))$/, /^(?!(|.*?:)cursor-move).+-move$/, /^router-link(|-exact)-active$/],
// whitelistPatterns: [
// /-(leave|enter|appear)(|-(to|from|active))$/,
// /^(?!(|.*?:)cursor-move).+-move$/,
// /^router-link(|-exact)-active$/,
// ],
});

module.exports = {
Expand All @@ -21,5 +27,5 @@ module.exports = {
// ...process.env.NODE_ENV === 'production'
// ? [purgecss]
// : []
]
}
],
};
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</template>

<script lang="ts">
import { createComponent, watch } from '@vue/composition-api';
import { createComponent } from '@vue/composition-api';
import Sidebar from './components/layouts/Sidebar.vue';
import AccountOverview from './components/layouts/AccountOverview.vue';
Expand Down
2 changes: 1 addition & 1 deletion src/components/AccountList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { createComponent } from '@vue/composition-api';
import AccountListItem from './AccountListItem.vue';
import { useAccountStore, AccountInfo, AccountType } from '../stores/Account';
import { useAccountStore } from '../stores/Account';
export default createComponent({
name: 'account-list',
Expand Down
5 changes: 3 additions & 2 deletions src/components/AccountListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@click="selectAccount(account.id)"
>
<div class="icon" :class="getBackgroundClass(account.addresses[0])">
<!-- eslint-disable-next-line max-len -->
<svg width="28" height="47" viewBox="0 0 28 47" fill="none" xmlns="http://www.w3.org/2000/svg"><g opacity=".5" fill="#fff"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.82 32.16H7.4a.57.57 0 01-.57-.58V28.1c0-.32.26-.58.57-.58h3.42c.32 0 .57.26.57.58v3.48c0 .32-.25.58-.57.58zm-2.7-3.48a.14.14 0 00-.15.15v2.03c0 .08.07.14.15.14h1.99c.08 0 .14-.06.14-.14v-2.03a.14.14 0 00-.14-.15h-2zM7.4 36.8h3.42c.32 0 .57.25.57.57v3.48c0 .32-.25.58-.57.58H7.4a.57.57 0 01-.57-.58v-3.48c0-.32.26-.58.57-.58zm2.7 3.47c.09 0 .15-.06.15-.14V38.1a.14.14 0 00-.14-.15h-2a.14.14 0 00-.14.15v2.03c0 .08.07.14.15.14h1.99zM16.52 27.52h3.41c.32 0 .57.26.57.58v3.48c0 .32-.25.58-.57.58h-3.41a.57.57 0 01-.57-.58V28.1c0-.32.25-.58.57-.58zm2.7 3.48c.08 0 .14-.06.14-.14v-2.03a.14.14 0 00-.14-.15h-2a.14.14 0 00-.13.15v2.03c0 .08.06.14.14.14h2z"/><path d="M12.53 29.99h.57c.24 0 .43-.2.43-.44s-.2-.43-.43-.43a.14.14 0 01-.14-.15v-.87c0-.24-.2-.43-.43-.43-.24 0-.43.2-.43.43v1.45c0 .24.2.44.43.44zM14.24 28.54c.08 0 .14.06.14.14v3.19c0 .24.2.43.43.43.23 0 .43-.19.43-.43V28.1c0-.24-.2-.43-.43-.43h-.57c-.24 0-.43.2-.43.43 0 .24.2.44.43.44zM10.1 33.6c0 .25.2.44.44.44h1.99c.24 0 .43-.2.43-.43v-2.32c0-.24-.2-.43-.43-.43-.24 0-.43.19-.43.43v1.74c0 .08-.06.14-.14.14h-1.42c-.24 0-.43.2-.43.44z"/><path d="M8.54 33.17c-.23 0-.42.2-.42.44v1.45c0 .08-.07.14-.15.14H7.4c-.23 0-.42.2-.42.44s.19.43.42.43h7.4c.24 0 .44-.2.44-.43V33.9c0-.24-.2-.44-.43-.44-.24 0-.43.2-.43.44v1.16c0 .08-.06.14-.14.14H9.1a.14.14 0 01-.14-.14V33.6c0-.24-.2-.44-.43-.44zM14.67 37.37c0-.24-.2-.43-.43-.43h-1.71c-.24 0-.43.2-.43.43v2.32c0 .24.2.44.43.44.24 0 .43-.2.43-.44v-1.74c0-.08.06-.14.14-.14h1.14c.23 0 .43-.2.43-.44zM19.93 40.42H15.1a.14.14 0 01-.14-.15v-1.16c0-.24-.2-.43-.43-.43-.23 0-.42.2-.42.43v1.74c0 .24.19.44.42.44h5.41c.24 0 .43-.2.43-.44s-.19-.43-.43-.43z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M17.94 39.26h-1.7a.43.43 0 01-.44-.44v-1.74c0-.24.2-.43.43-.43h1.71c.24 0 .43.2.43.43v1.74c0 .24-.2.44-.43.44zm-1.14-1.74a.14.14 0 00-.14.14v.58c0 .08.06.15.14.15h.57c.08 0 .14-.07.14-.15v-.58a.14.14 0 00-.14-.14h-.57z"/><path d="M19.65 34.91c-.24 0-.43.2-.43.44v3.76c0 .24.2.44.43.44.24 0 .43-.2.43-.44v-3.76c0-.24-.2-.44-.43-.44zM20.08 33.32c0-.24-.2-.44-.43-.44h-3.13c-.24 0-.43.2-.43.44v1.74c0 .24.2.43.43.43.23 0 .42-.2.42-.43V33.9c0-.08.07-.15.15-.15h2.56c.24 0 .43-.2.43-.43z"/></g><circle opacity=".4" cx="13.5" cy="13.5" r="5.5" fill="#fff"/></svg>
</div>
<div class="label">{{ account.label }}</div>
Expand Down Expand Up @@ -31,7 +32,7 @@
</template>

<script lang="ts">
import { createComponent, computed } from '@vue/composition-api'
import { createComponent, computed } from '@vue/composition-api';
import { ArrowRightSmallIcon } from '@nimiq/vue-components';
import getBackgroundClass from '../lib/AddressColor';
Expand Down Expand Up @@ -67,7 +68,7 @@ export default createComponent({
components: {
ArrowRightSmallIcon,
},
})
});
</script>

<style lang="scss" scoped>
Expand Down
32 changes: 18 additions & 14 deletions src/components/AccountMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<div class="menu flex-column">
<div class="current-account">
<AccountMenuItem :id="activeAccountId"/>
<button v-if="canExportFile" class="item reset flex-row" @click="backup(activeAccountId, { fileOnly: true })">
<button v-if="canExportFile" class="item reset flex-row"
@click="backup(activeAccountId, { fileOnly: true })">
{{ $t('Save Login File') }}
<AlertTriangleIcon v-if="!activeAccountInfo.fileExported" class="alert"/>
</button>
<button v-if="canExportWords" class="item reset flex-row" @click="backup(activeAccountId, { wordsOnly: true })">
<button v-if="canExportWords" class="item reset flex-row"
@click="backup(activeAccountId, { wordsOnly: true })">
{{ $t('Create Backup') }}
<AlertTriangleIcon v-if="!activeAccountInfo.wordsExported" class="alert"/>
</button>
Expand Down Expand Up @@ -53,22 +55,20 @@
</template>

<script lang="ts">
import { createComponent, computed, ref, onMounted } from '@vue/composition-api'
import { createComponent, computed, ref } from '@vue/composition-api';
import { ArrowRightSmallIcon, AlertTriangleIcon } from '@nimiq/vue-components';
// @ts-ignore Could not find a declaration file for module 'vue-click-outside'.
import VueClickOutside from 'vue-click-outside';
// @ts-ignore Could not find a declaration file for module 'v-click-outside'.
import vClickOutside from 'v-click-outside';
import LoginFileIcon from './icons/LoginFileIcon.vue';
import AccountMenuItem from './AccountMenuItem.vue';
import getBackgroundClass from '../lib/AddressColor';
import { useAccountStore, AccountInfo, AccountType } from '../stores/Account';
import { useAccountStore, AccountType } from '../stores/Account';
import { backup, rename, changePassword, logout, onboard } from '../hub';
import { useAddressStore } from '../stores/Address';
export default createComponent({
setup(_, context) {
setup() {
const { accountInfos, activeAccountInfo, activeAccountId, selectAccount } = useAccountStore();
const { accountBalance } = useAddressStore();
Expand All @@ -82,13 +82,17 @@ export default createComponent({
menuOpen.value = false;
}
const canExportFile = computed(() => !!activeAccountInfo.value && activeAccountInfo.value.type === AccountType.BIP39);
const canExportWords = computed(() => !!activeAccountInfo.value && activeAccountInfo.value.type !== AccountType.LEDGER);
const canChangePassword = computed(() => !!activeAccountInfo.value && activeAccountInfo.value.type !== AccountType.LEDGER);
const canExportFile = computed(() => activeAccountInfo.value?.type === AccountType.BIP39);
const isNotLedger = computed(() =>
!!activeAccountInfo.value && activeAccountInfo.value.type !== AccountType.LEDGER);
const canExportWords = isNotLedger;
const canChangePassword = isNotLedger;
const backgroundColor = computed(() => !!activeAccountInfo.value && getBackgroundClass(activeAccountInfo.value.addresses[0]));
const backgroundColor = computed(() => !!activeAccountInfo.value
&& getBackgroundClass(activeAccountInfo.value.addresses[0]));
const otherAccountIds = computed(() => Object.keys(accountInfos.value).filter(id => id !== activeAccountId.value));
const otherAccountIds = computed(() => Object.keys(accountInfos.value)
.filter((id) => id !== activeAccountId.value));
return {
otherAccountIds,
Expand All @@ -110,7 +114,7 @@ export default createComponent({
onboard,
};
},
mounted () {
mounted() {
// prevent click outside event with popupItem.
// @ts-ignore
this.popupItem = this.$el;
Expand All @@ -124,7 +128,7 @@ export default createComponent({
directives: {
ClickOutside: vClickOutside.directive,
},
})
});
</script>

<style lang="scss" scoped>
Expand Down
2 changes: 1 addition & 1 deletion src/components/AccountMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default createComponent({
const { state: addressState } = useAddressStore();
const accountInfo = computed(() => accountInfos.value[props.id]);
const addressInfos = computed(() => accountInfo.value.addresses.map(addr => addressState.addressInfos[addr]));
const addressInfos = computed(() => accountInfo.value.addresses.map((addr) => addressState.addressInfos[addr]));
const backgroundClass = computed(() => getBackgroundClass(addressInfos.value[0].address));
const accountBalance = computed(() => addressInfos.value.reduce((sum, acc) => sum + (acc.balance || 0), 0));
Expand Down
8 changes: 4 additions & 4 deletions src/components/AddressList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
</template>

<script lang="ts">
import { createComponent, computed } from '@vue/composition-api'
import { createComponent, computed } from '@vue/composition-api';
import { Identicon, LockLockedIcon } from '@nimiq/vue-components';
import { useAddressStore, AddressType, AddressInfo } from '../stores/Address'
import { useAddressStore, AddressType, AddressInfo } from '../stores/Address';
import { useNetworkStore } from '../stores/Network';
import Amount from './Amount.vue';
import FiatConvertedAmount from './FiatConvertedAmount.vue';
Expand All @@ -52,7 +52,7 @@ export default createComponent({
return passedSteps < numberVestingSteps;
}
const processedAddressInfos = computed(() => addressInfos.value.map(addressInfo => ({
const processedAddressInfos = computed(() => addressInfos.value.map((addressInfo) => ({
...addressInfo,
hasLockedBalance: hasLockedBalance(addressInfo, network$.height),
})));
Expand All @@ -71,7 +71,7 @@ export default createComponent({
ClockIcon,
LockLockedIcon,
} as any,
})
});
</script>

<style scoped lang="scss">
Expand Down
17 changes: 8 additions & 9 deletions src/components/Amount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@
</template>

<script lang="ts">
import { createComponent, computed } from '@vue/composition-api'
import { useSettingsStore } from '../stores/Settings'
import { createComponent, computed } from '@vue/composition-api';
import { Amount } from '@nimiq/vue-components';
import { useSettingsStore } from '../stores/Settings';
export default createComponent({
name: 'amount',
props: {
amount: {
type: Number,
required: true
required: true,
},
currency: {
type: String,
required: false,
},
},
setup(props) {
setup() {
const { showDecimals } = useSettingsStore();
const maxDecimals = computed(() => {
const maxDecimals = computed(() =>
// for BTC add condition here
return showDecimals.value ? 5 : 2;
});
showDecimals.value ? 5 : 2);
return {
maxDecimals,
};
},
components: {
Amount,
}
})
},
});
</script>

<style lang="scss">
Expand Down
Loading

0 comments on commit 42941d1

Please sign in to comment.