Skip to content

Commit

Permalink
Pull forward the lint changes from #275
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Dec 27, 2023
1 parent 44f009f commit 29df6cb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
8 changes: 7 additions & 1 deletion addon/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion addon/src/helpers/page-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class PageTitle extends Helper<Signature> {
}

compute(params, _hash) {
let hash = {
const hash = {
..._hash,
id: this.tokenId,
title: params.join(''),
Expand Down
54 changes: 27 additions & 27 deletions addon/src/services/page-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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])) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion addon/src/test-support/get-page-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <title> 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();

Expand Down

0 comments on commit 29df6cb

Please sign in to comment.