From 29df6cb657f0c828999a2c8b83f345969ffb355d Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Wed, 27 Dec 2023 12:29:58 -0500 Subject: [PATCH] Pull forward the lint changes from #275 --- addon/.eslintrc.cjs | 8 +++- addon/src/helpers/page-title.ts | 2 +- addon/src/services/page-title.ts | 54 ++++++++++++------------ addon/src/test-support/get-page-title.ts | 2 +- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/addon/.eslintrc.cjs b/addon/.eslintrc.cjs index 8aeca25..bb08159 100644 --- a/addon/.eslintrc.cjs +++ b/addon/.eslintrc.cjs @@ -7,15 +7,21 @@ module.exports = { { files: ['src/**/*.{js,ts}'], parser: '@typescript-eslint/parser', - plugins: ['ember'], + plugins: ['ember', '@typescript-eslint'], extends: [ 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', 'plugin:ember/recommended', 'plugin:prettier/recommended', ], env: { browser: true, }, + rules: { + // temp, remove these in #275 + '@typescript-eslint/ban-ts-comment': 'off', + 'prefer-rest-params': 'off', + }, }, // node files { diff --git a/addon/src/helpers/page-title.ts b/addon/src/helpers/page-title.ts index c4e03c7..2009d98 100644 --- a/addon/src/helpers/page-title.ts +++ b/addon/src/helpers/page-title.ts @@ -44,7 +44,7 @@ export default class PageTitle extends Helper { } compute(params, _hash) { - let hash = { + const hash = { ..._hash, id: this.tokenId, title: params.join(''), diff --git a/addon/src/services/page-title.ts b/addon/src/services/page-title.ts index ebf7ec3..2918532 100644 --- a/addon/src/services/page-title.ts +++ b/addon/src/services/page-title.ts @@ -6,7 +6,7 @@ import { isEmpty } from '@ember/utils'; import { assert } from '@ember/debug'; import type RouterService from '@ember/routing/router-service'; -let isFastBoot = typeof FastBoot !== 'undefined'; +const isFastBoot = typeof FastBoot !== 'undefined'; const RouterEvent = { ROUTE_DID_CHANGE: 'routeDidChange', @@ -62,7 +62,7 @@ export default class PageTitleService extends Service { super(...arguments); this._validateExistingTitleElement(); - let config = getOwner(this).resolveRegistration('config:environment'); + const config = getOwner(this).resolveRegistration('config:environment'); if (config.pageTitle) { ['separator', 'prepend', 'replace'].forEach((key) => { if (!isEmpty(config.pageTitle[key])) { @@ -74,9 +74,9 @@ export default class PageTitleService extends Service { } applyTokenDefaults(token) { - let defaultSeparator = this._defaultConfig.separator; - let defaultPrepend = this._defaultConfig.prepend; - let defaultReplace = this._defaultConfig.replace; + const defaultSeparator = this._defaultConfig.separator; + const defaultPrepend = this._defaultConfig.prepend; + const defaultReplace = this._defaultConfig.replace; token.previous ??= null; token.next ??= null; @@ -95,7 +95,7 @@ export default class PageTitleService extends Service { } inheritFromPrevious(token) { - let previous = token.previous; + const previous = token.previous; if (previous) { if (token.separator == null) { token.separator = previous.separator; @@ -108,11 +108,11 @@ export default class PageTitleService extends Service { } push(token) { - let tokenForId = this._findTokenById(token.id); + const tokenForId = this._findTokenById(token.id); if (tokenForId) { - let index = this.tokens.indexOf(tokenForId); - let tokens = [...this.tokens]; - let previous = tokenForId.previous; + const index = this.tokens.indexOf(tokenForId); + const tokens = [...this.tokens]; + const previous = tokenForId.previous; token.previous = previous; token.next = tokenForId.next; this.inheritFromPrevious(token); @@ -123,7 +123,7 @@ export default class PageTitleService extends Service { return; } - let previous = this.tokens.slice(-1)[0]; + const previous = this.tokens.slice(-1)[0]; if (previous) { token.previous = previous ?? null; previous.next = token; @@ -135,8 +135,8 @@ export default class PageTitleService extends Service { } remove(id) { - let token = this._findTokenById(id); - let { next, previous } = token; + const token = this._findTokenById(id); + const { next, previous } = token; if (next) { next.previous = previous; } @@ -147,17 +147,17 @@ export default class PageTitleService extends Service { token.previous = token.next = null; - let tokens = [...this.tokens]; + const tokens = [...this.tokens]; tokens.splice(tokens.indexOf(token), 1); this.tokens = tokens; } get visibleTokens() { - let tokens = this.tokens; + const tokens = this.tokens; let i = tokens ? tokens.length : 0; - let visible = []; + const visible = []; while (i--) { - let token = tokens[i]; + const token = tokens[i]; if (token.replace) { visible.unshift(token); break; @@ -169,11 +169,11 @@ export default class PageTitleService extends Service { } get sortedTokens() { - let visible = this.visibleTokens; + const visible = this.visibleTokens; let appending = true; let group = []; - let groups = [group]; - let frontGroups = []; + const groups = [group]; + const frontGroups = []; visible.forEach((token) => { if (token.front) { frontGroups.unshift(token); @@ -183,7 +183,7 @@ export default class PageTitleService extends Service { group = []; groups.push(group); } - let lastToken = group[0]; + const lastToken = group[0]; if (lastToken) { token = { ...token }; token.separator = lastToken.separator; @@ -207,10 +207,10 @@ export default class PageTitleService extends Service { }; toString() { - let tokens = this.sortedTokens; - let title = []; + const tokens = this.sortedTokens; + const title = []; for (let i = 0, len = tokens.length; i < len; i++) { - let token = tokens[i]; + const token = tokens[i]; if (token.title) { title.push(token.title); if (i + 1 < len) { @@ -282,15 +282,15 @@ export default class PageTitleService extends Service { // Remove existing title elements from previous render cycle for (let i = 0; i < headChildNodes.length; i++) { - let node = headChildNodes[i]; + const node = headChildNodes[i]; if (node.nodeName.toLowerCase() === 'title') { headElement.removeChild(node); } } // Add title element with latest value - let titleEl = this.document.createElement('title'); - let titleContents = this.document.createTextNode(toBeTitle); + const titleEl = this.document.createElement('title'); + const titleContents = this.document.createTextNode(toBeTitle); titleEl.appendChild(titleContents); headElement.appendChild(titleEl); } diff --git a/addon/src/test-support/get-page-title.ts b/addon/src/test-support/get-page-title.ts index edc430b..6918ca9 100644 --- a/addon/src/test-support/get-page-title.ts +++ b/addon/src/test-support/get-page-title.ts @@ -5,7 +5,7 @@ export function getPageTitle(doc: Document) { // In Fastboot context we get 2 title elements if we don't remove one from app/index.html // In real world applications, it is mandatory to remove from app/index.html // We are keeping both for sake for testing browser and fastboot scenarios - let element = [ + const element = [ ...(doc || window.document).querySelectorAll('head title'), ].pop();