Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add typescript linting #4762

Merged
merged 3 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
const config = {
root: true,
parser: 'babel-eslint',
parserOptions: {
Expand Down Expand Up @@ -122,3 +122,26 @@ module.exports = {
}
]
};

config.overrides.push({
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: config.parserOptions,
plugins: [
...config.plugins,
'@typescript-eslint'
],
extends: [
...config.extends,
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
env: config.env,
rules: {
...config.rules,
'@typescript-eslint/no-explicit-any': 'off'
},
globals: config.globals
})

module.exports = config;
2 changes: 1 addition & 1 deletion app/components/events/view/export/api-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default Component.extend({
const include = [];

for (const key in this.toggleSwitches) {
if (this.toggleSwitches.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(this.toggleSwitches, key)) {
this.toggleSwitches[key] && include.push(key);
}
}
Expand Down
18 changes: 8 additions & 10 deletions app/components/forms/wizard/custom-form-input.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Component from '@glimmer/component';
import { slugify } from 'open-event-frontend/utils/text';
import { action } from '@ember/object';
import { computed } from '@ember/object';
import { action, computed, set } from '@ember/object';
import { inject as service } from '@ember/service';
import { set } from '@ember/object';
import DS from 'ember-data';

interface CustomForm { fieldIdentifier: string }
Expand All @@ -19,12 +17,12 @@ function getIdentifier(name: string, fields: CustomForm[]): string {
}

interface Args {
newFormField: {
name: string,
type: string
},
customForms: CustomForm[],
form: string,
newFormField: {
name: string,
type: string
},
customForms: CustomForm[],
form: string,
event: any
}

Expand All @@ -43,7 +41,7 @@ export default class CustomFormInput extends Component<Args> {
}

@action
addFormField() {
addFormField(): void {
if (!this.validIdentifier) {
return;
}
Expand Down
110 changes: 55 additions & 55 deletions app/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,67 @@ import { Integrations as ApmIntegrations } from '@sentry/apm';

if (!config.sentry.dsn.includes('dummy')) {

Sentry.init({
integrations: [
new Ember(),
new Dedupe(),
new CaptureConsole({
levels: ['error']
}),
new ApmIntegrations.Tracing(),
],
beforeSend(event: Sentry.Event) {
const exception = event.exception?.values?.[0];
const errorValue = exception?.value;
if (errorValue?.includes("Ember Data Request")) {
if (errorValue?.includes("404")) {
// Ignore 404 errors from Ember Data because
// I don't know how to turn them off
return null;
}
}
Sentry.init({
integrations: [
new Ember(),
new Dedupe(),
new CaptureConsole({
levels: ['error']
}),
new ApmIntegrations.Tracing()
],
beforeSend(event: Sentry.Event) {
const exception = event.exception?.values?.[0];
const errorValue = exception?.value;
if (errorValue?.includes('Ember Data Request')) {
if (errorValue?.includes('404')) {
// Ignore 404 errors from Ember Data because
// I don't know how to turn them off
return null;
}
}

if (errorValue?.includes("TransitionAborted") &&
exception?.mechanism?.handled) {
// Every page load has a handled TransitionAborted for some reason
return null;
}
if (errorValue?.includes('TransitionAborted')
&& exception?.mechanism?.handled) {
// Every page load has a handled TransitionAborted for some reason
return null;
}

return event;
},
...config.sentry
});
return event;
},
...config.sentry
});

Sentry.configureScope(function(scope) {
function addAdapterError(error: any, event: Sentry.Event) {
if (error.isAdapterError) {
event.extra = {
...event.extra,
adapter_errors: error.errors,
adapter_errors_json: JSON.stringify(error.errors)
}
}
Sentry.configureScope(function(scope) {
function addAdapterError(error: any, event: Sentry.Event) {
if (error.isAdapterError) {
event.extra = {
...event.extra,
adapter_errors : error.errors,
adapter_errors_json : JSON.stringify(error.errors)
};
}

try {
// Try to store JSON of error for diagnosing bugs
event.extra = {
...event.extra,
error_json: JSON.stringify(error)
}
} catch {
// Ignore error to prevent stackoverflow
}
}
try {
// Try to store JSON of error for diagnosing bugs
event.extra = {
...event.extra,
error_json: JSON.stringify(error)
};
} catch {
// Ignore error to prevent stackoverflow
}
}

scope.addEventProcessor(function(event: Sentry.Event, hints: Sentry.EventHint) {
addAdapterError(hints.originalException, event);
scope.addEventProcessor(function(event: Sentry.Event, hints: Sentry.EventHint) {
addAdapterError(hints.originalException, event);

const args: any[] = event.extra?.arguments || [];
for (const arg of args) {
addAdapterError(arg, event);
}
return event;
});
const args: any[] = event.extra?.arguments || [];
for (const arg of args) {
addAdapterError(arg, event);
}
return event;
});
});

}
8 changes: 4 additions & 4 deletions app/services/bug-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Service from '@ember/service';
import * as Sentry from '@sentry/browser';

export default class BugTracker extends Service {
setUser(user: Sentry.User | null) {
Sentry.setUser(user)

setUser(user: Sentry.User | null): void {
Sentry.setUser(user);
}

clearUser() {
clearUser(): void {
Sentry.setUser(null);
}

Expand Down
2 changes: 1 addition & 1 deletion app/services/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default Service.extend({
xhr.open(fetchOptions.method || 'get', url);
let headers = fetchOptions.headers || {};
for (let k in headers) {
if (k !== 'Content-Type' && headers.hasOwnProperty(k)) {
if (k !== 'Content-Type' && Object.prototype.hasOwnProperty.call(headers, k)) {
xhr.setRequestHeader(k, fetchOptions.headers[k]);
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/utils/dictionary/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const stateColorMap = {
draft: 'grey',
accepted: 'teal',
confirmed: 'green',
pending: 'yellow',
rejected: 'red',
deleted: 'red',
withdrawn: 'black',
canceled: 'orange'
draft : 'grey',
accepted : 'teal',
confirmed : 'green',
pending : 'yellow',
rejected : 'red',
deleted : 'red',
withdrawn : 'black',
canceled : 'orange'
};

export const SESSION_STATES = ['pending', 'accepted', 'confirmed', 'rejected', 'withdrawn', 'canceled'];
4 changes: 2 additions & 2 deletions app/utils/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ interface CustomFormField {
}

export function sortCustomFormFields(fields: CustomFormField[], fieldOrder: string[]): CustomFormField[] {
fieldOrder = [...fieldOrder].reverse();
return sortBy(fields, 'isComplex', item => -fieldOrder.indexOf(item.fieldIdentifier));
fieldOrder = [...fieldOrder].reverse();
return sortBy(fields, 'isComplex', item => -fieldOrder.indexOf(item.fieldIdentifier));
}
10 changes: 5 additions & 5 deletions app/utils/text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function slugify(string: string, sep: string = '-'): string {
return string.toLowerCase()
.replace(/[^\w\s-]/g, '') // remove non-word [a-z0-9_], non-whitespace, non-hyphen characters
.replace(/[\s_-]+/g, sep) // swap any length of whitespace, underscore, hyphen characters with a single -
.replace(/^-+|-+$/g, ''); // remove leading, trailing -
export function slugify(string: string, sep = '-'): string {
return string.toLowerCase()
.replace(/[^\w\s-]/g, '') // remove non-word [a-z0-9_], non-whitespace, non-hyphen characters
.replace(/[\s_-]+/g, sep) // swap any length of whitespace, underscore, hyphen characters with a single -
.replace(/^-+|-+$/g, ''); // remove leading, trailing -
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"@types/lodash-es": "^4.17.3",
"@types/qunit": "^2.9.1",
"@types/rsvp": "^4.0.3",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"async": "^3.2.0",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
Expand Down Expand Up @@ -71,7 +73,6 @@
"ember-cli-deprecation-workflow": "^1.0.1",
"ember-cli-document-title-northm": "^1.0.3",
"ember-cli-dotenv": "^3.1.0",
"ember-cli-eslint": "^5.1.0",
"ember-cli-fastboot": "^2.2.3",
"ember-cli-head": "^1.0.0",
"ember-cli-html-minifier": "^1.1.0",
Expand Down Expand Up @@ -128,6 +129,7 @@
"ember-template-lint": "^2.10.0",
"ember-truth-helpers": "^2.1.0",
"ember-uuid": "^2.1.0",
"eslint": "^7.6.0",
"eslint-plugin-ember": "^8.10.1",
"eslint-plugin-ember-suave": "^2.0.1",
"eslint-plugin-node": "^11.1.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/services/bug-tracker-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module('Unit | Service | bug-tracker', function(hooks) {

// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.owner.lookup('service:bug-tracker');
const service = this.owner.lookup('service:bug-tracker');
assert.ok(service);
});
});
4 changes: 2 additions & 2 deletions tests/unit/utils/sort-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { module, test } from 'qunit';

module('Unit | Sort | Custom Form Fields', function() {
test('test custom form fields sort', function(assert) {
const items = [{fieldIdentifier: 'age', isComplex: false}, {fieldIdentifier: 'job', isComplex: false}, {fieldIdentifier: 'majama', isComplex: true}, {fieldIdentifier: 'name', isComplex: false}, {fieldIdentifier: 'hay', isComplex: true}, {fieldIdentifier: 'trust', isComplex: false}, {fieldIdentifier: 'company', isComplex: false}];
const items = [{ fieldIdentifier: 'age', isComplex: false }, { fieldIdentifier: 'job', isComplex: false }, { fieldIdentifier: 'majama', isComplex: true }, { fieldIdentifier: 'name', isComplex: false }, { fieldIdentifier: 'hay', isComplex: true }, { fieldIdentifier: 'trust', isComplex: false }, { fieldIdentifier: 'company', isComplex: false }];
const order = ['name', 'age', 'company'];
assert.equal(JSON.stringify(sortCustomFormFields(items, order)), JSON.stringify([{fieldIdentifier:"name",isComplex:false},{fieldIdentifier:"age",isComplex:false},{fieldIdentifier:"company",isComplex:false},{fieldIdentifier:"job",isComplex:false},{fieldIdentifier:"trust",isComplex:false},{fieldIdentifier:"majama",isComplex:true},{fieldIdentifier:"hay",isComplex:true}]));
assert.equal(JSON.stringify(sortCustomFormFields(items, order)), JSON.stringify([{ fieldIdentifier: 'name', isComplex: false }, { fieldIdentifier: 'age', isComplex: false }, { fieldIdentifier: 'company', isComplex: false }, { fieldIdentifier: 'job', isComplex: false }, { fieldIdentifier: 'trust', isComplex: false }, { fieldIdentifier: 'majama', isComplex: true }, { fieldIdentifier: 'hay', isComplex: true }]));
});
});
Loading