Skip to content

Commit 7947e34

Browse files
authored
ref(ember): Update ember type/eslint/tsconfig usage (#8718)
To actually align with the monorepo rules. We were actually not applying the general eslint rules for the ember package, leading to a bunch of more ambiguous typing. Also tests were all in JS, not TS, I streamlined this as well.
1 parent 2e1c4a5 commit 7947e34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+807
-639
lines changed

packages/ember/.eslintrc.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
'use strict';
22

33
module.exports = {
4-
root: true,
5-
parser: 'babel-eslint',
6-
parserOptions: {
7-
ecmaVersion: 2018,
8-
sourceType: 'module',
9-
ecmaFeatures: {
10-
legacyDecorators: true,
11-
},
12-
},
13-
plugins: ['ember'],
14-
extends: ['eslint:recommended', 'plugin:ember/recommended'],
15-
env: {
16-
browser: true,
17-
},
18-
globals: {
19-
QUnit: true,
20-
},
21-
rules: {},
4+
extends: ['../../.eslintrc.js'],
5+
226
overrides: [
237
{
24-
files: ['addon/**'],
25-
plugins: ['@sentry-internal/eslint-plugin-sdk'],
8+
// addon files
9+
files: ['{addon,app,tests}/**/*.{js,ts,d.ts}'],
10+
parserOptions: {
11+
sourceType: 'module',
12+
babelOptions: {
13+
plugins: [['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }]],
14+
},
15+
},
16+
plugins: ['ember'],
17+
extends: ['plugin:ember/recommended'],
18+
rules: {
19+
'import/no-unresolved': 'off',
20+
},
21+
},
22+
{
23+
// test files
24+
files: ['tests/**/*-test.{js,ts}', 'tests/helpers/**/*.{js,ts}'],
25+
extends: ['plugin:qunit/recommended'],
26+
/* globals: {
27+
QUnit: true,
28+
}, */
29+
rules: {
30+
'qunit/require-expect': 'off',
31+
},
2632
},
27-
// node files
2833
{
2934
files: [
3035
'./.eslintrc.js',
31-
'./.prettierrc.js',
3236
'./.template-lintrc.js',
3337
'./ember-cli-build.js',
3438
'./index.js',
@@ -44,13 +48,7 @@ module.exports = {
4448
browser: false,
4549
node: true,
4650
},
47-
plugins: ['node'],
48-
extends: ['plugin:node/recommended'],
49-
},
50-
{
51-
// test files
52-
files: ['tests/**/*-test.{js,ts}'],
53-
extends: ['plugin:qunit/recommended'],
51+
extends: ['plugin:n/recommended'],
5452
},
5553
],
5654
};

packages/ember/addon/index.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
import * as Sentry from '@sentry/browser';
2-
import { SDK_VERSION, BrowserOptions } from '@sentry/browser';
3-
import { macroCondition, isDevelopingApp, getOwnConfig } from '@embroider/macros';
4-
import { next } from '@ember/runloop';
51
import { assert, warn } from '@ember/debug';
2+
import type Route from '@ember/routing/route';
3+
import { next } from '@ember/runloop';
4+
import { getOwnConfig, isDevelopingApp, macroCondition } from '@embroider/macros';
5+
import type { BrowserOptions } from '@sentry/browser';
6+
import * as Sentry from '@sentry/browser';
7+
import { SDK_VERSION } from '@sentry/browser';
8+
import type { Transaction } from '@sentry/types';
9+
import { GLOBAL_OBJ, timestampInSeconds } from '@sentry/utils';
610
import Ember from 'ember';
7-
import { timestampInSeconds, GLOBAL_OBJ } from '@sentry/utils';
8-
import { GlobalConfig, OwnConfig } from './types';
911

10-
function _getSentryInitConfig() {
12+
import type { EmberSentryConfig, GlobalConfig, OwnConfig } from './types';
13+
14+
function _getSentryInitConfig(): EmberSentryConfig['sentry'] {
1115
const _global = GLOBAL_OBJ as typeof GLOBAL_OBJ & GlobalConfig;
1216
_global.__sentryEmberConfig = _global.__sentryEmberConfig ?? {};
1317
return _global.__sentryEmberConfig;
1418
}
1519

16-
export function InitSentryForEmber(_runtimeConfig?: BrowserOptions) {
20+
export function InitSentryForEmber(_runtimeConfig?: BrowserOptions): void {
1721
const environmentConfig = getOwnConfig<OwnConfig>().sentryConfig;
1822

1923
assert('Missing configuration.', environmentConfig);
2024
assert('Missing configuration for Sentry.', environmentConfig.sentry || _runtimeConfig);
2125

2226
if (!environmentConfig.sentry) {
2327
// If environment config is not specified but the above assertion passes, use runtime config.
24-
environmentConfig.sentry = { ..._runtimeConfig } as any;
28+
environmentConfig.sentry = { ..._runtimeConfig };
2529
}
2630

2731
// Merge runtime config into environment config, preferring runtime.
@@ -62,12 +66,20 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions) {
6266
}
6367
}
6468

65-
export const getActiveTransaction = () => {
69+
export const getActiveTransaction = (): Transaction | undefined => {
6670
return Sentry.getCurrentHub().getScope().getTransaction();
6771
};
6872

69-
export const instrumentRoutePerformance = (BaseRoute: any) => {
70-
const instrumentFunction = async (op: string, description: string, fn: Function, args: any) => {
73+
type RouteConstructor = new (...args: ConstructorParameters<typeof Route>) => Route;
74+
75+
export const instrumentRoutePerformance = <T extends RouteConstructor>(BaseRoute: T): T => {
76+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77+
const instrumentFunction = async <X extends (...args: unknown[]) => any>(
78+
op: string,
79+
description: string,
80+
fn: X,
81+
args: Parameters<X>,
82+
): Promise<ReturnType<X>> => {
7183
const startTimestamp = timestampInSeconds();
7284
const result = await fn(...args);
7385

@@ -79,40 +91,38 @@ export const instrumentRoutePerformance = (BaseRoute: any) => {
7991
return result;
8092
};
8193

94+
const routeName = BaseRoute.name;
95+
8296
return {
83-
[BaseRoute.name]: class extends BaseRoute {
84-
beforeModel(...args: any[]) {
97+
// @ts-expect-error TS2545 We do not need to redefine a constructor here
98+
[routeName]: class extends BaseRoute {
99+
public beforeModel(...args: unknown[]): void | Promise<unknown> {
85100
return instrumentFunction(
86101
'ui.ember.route.before_model',
87-
(<any>this).fullRouteName,
102+
this.fullRouteName,
88103
super.beforeModel.bind(this),
89104
args,
90105
);
91106
}
92107

93-
async model(...args: any[]) {
94-
return instrumentFunction('ui.ember.route.model', (<any>this).fullRouteName, super.model.bind(this), args);
108+
public async model(...args: unknown[]): Promise<unknown> {
109+
return instrumentFunction('ui.ember.route.model', this.fullRouteName, super.model.bind(this), args);
95110
}
96111

97-
async afterModel(...args: any[]) {
98-
return instrumentFunction(
99-
'ui.ember.route.after_model',
100-
(<any>this).fullRouteName,
101-
super.afterModel.bind(this),
102-
args,
103-
);
112+
public afterModel(...args: unknown[]): void | Promise<unknown> {
113+
return instrumentFunction('ui.ember.route.after_model', this.fullRouteName, super.afterModel.bind(this), args);
104114
}
105115

106-
async setupController(...args: any[]) {
116+
public setupController(...args: unknown[]): void | Promise<unknown> {
107117
return instrumentFunction(
108118
'ui.ember.route.setup_controller',
109-
(<any>this).fullRouteName,
119+
this.fullRouteName,
110120
super.setupController.bind(this),
111121
args,
112122
);
113123
}
114124
},
115-
}[BaseRoute.name];
125+
}[routeName] as T;
116126
};
117127

118128
export * from '@sentry/browser';

0 commit comments

Comments
 (0)