Skip to content

Commit

Permalink
Merge pull request #34 from salsify/add-typescript
Browse files Browse the repository at this point in the history
Add typescript
  • Loading branch information
katrynmc committed Oct 18, 2021
2 parents 788ad08 + 6a9a4fe commit 67c9e71
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 108 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = {
{
files: [
'.eslintrc.js',
'typescript.js',
'.prettierrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
Expand All @@ -59,5 +60,9 @@ module.exports = {
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
files: '*.ts',
extends: require.resolve('./typescript'),
},
],
};
4 changes: 3 additions & 1 deletion addon/-private/binding.js → addon/-private/binding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default class Binding {
constructor(path) {
public path: Array<string>;

public constructor(path: string) {
this.path = path.split('.');
}
}
39 changes: 34 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,51 @@
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
"lint:hbs": "ember-template-lint .",
"lint:hbs:fix": "ember-template-lint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:js": "eslint . --cache --ext ts,js",
"lint:js:fix": "eslint . --fix --ext ts,js",
"start": "ember server",
"test": "npm-run-all lint test:*",
"test:ember": "ember test",
"test:ember-compatibility": "ember try:each"
"test:ember-compatibility": "ember try:each",
"prepack": "ember ts:precompile",
"postpack": "ember ts:clean"
},
"dependencies": {
"ember-botanist": "^1.0.1",
"ember-cli-babel": "^7.26.3",
"ember-cli-htmlbars": "^5.7.1"
"ember-cli-htmlbars": "^5.7.1",
"ember-cli-typescript": "^4.2.1"
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.2.5",
"@embroider/test-setup": "^0.37.0",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
"@types/ember-qunit": "^3.4.14",
"@types/ember-resolver": "^5.0.10",
"@types/ember__application": "^3.16.3",
"@types/ember__array": "^3.16.4",
"@types/ember__component": "^3.16.6",
"@types/ember__controller": "^3.16.6",
"@types/ember__debug": "^3.16.5",
"@types/ember__engine": "^3.16.3",
"@types/ember__error": "^3.16.1",
"@types/ember__object": "^3.12.6",
"@types/ember__polyfills": "^3.12.1",
"@types/ember__routing": "^3.16.15",
"@types/ember__runloop": "^3.16.3",
"@types/ember__service": "^3.16.1",
"@types/ember__string": "^3.16.3",
"@types/ember__template": "^3.16.1",
"@types/ember__test": "^3.16.1",
"@types/ember__test-helpers": "^2.0.2",
"@types/ember__utils": "^3.16.2",
"@types/htmlbars-inline-precompile": "^1.0.1",
"@types/qunit": "^2.11.2",
"@types/rsvp": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
"ember-ace": "^1.3.1",
Expand All @@ -50,6 +77,7 @@
"ember-cli-shims": "^1.2.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-terser": "^4.0.1",
"ember-cli-typescript-blueprints": "^3.0.0",
"ember-common-tags": "^0.1.2",
"ember-css-modules": "^1.2.1",
"ember-disable-prototype-extensions": "^1.1.3",
Expand All @@ -73,7 +101,8 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"qunit": "^2.14.1",
"qunit-dom": "^1.6.0"
"qunit-dom": "^1.6.0",
"typescript": "^4.4.3"
},
"engines": {
"node": "8.* || >= 10.*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import HelperSpec from 'ember-exclaim/-private/helper-spec';
module('Unit | helper-spec');

test('discovering bindings', function (assert) {
let config = {
const config = {
foo: new Binding('foo'),
bar: [new Binding('bar[1]'), new Binding('bar[2]')],
baz: {
Expand All @@ -14,10 +14,10 @@ test('discovering bindings', function (assert) {
},
};

let spec = new HelperSpec(() => {}, config);
const spec = new HelperSpec(() => {}, config);

assert.deepEqual(
spec.bindings.map((binding) => binding.path.join('')).sort(),
spec.bindings.map((binding: Binding) => binding.path.join('')).sort(),
['a', 'b', 'bar[1]', 'bar[2]', 'foo', 'value']
);
});
56 changes: 56 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"compilerOptions": {
"target": "es2020",
"allowJs": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noEmitOnError": true,
"noEmit": true,
"inlineSourceMap": true,
"inlineSources": true,
"baseUrl": ".",
"module": "es6",
"experimentalDecorators": true,
"paths": {
"dummy/tests/*": [
"tests/*"
],
"dummy/*": [
"tests/dummy/app/*",
"app/*"
],
"ember-exclaim": [
"addon"
],
"ember-exclaim/*": [
"addon/*"
],
"ember-exclaim/test-support": [
"addon-test-support"
],
"ember-exclaim/test-support/*": [
"addon-test-support/*"
],
"*": [
"types/*"
]
}
},
"include": [
"app/**/*",
"addon/**/*",
"tests/**/*",
"types/**/*",
"test-support/**/*",
"addon-test-support/**/*"
]
}
Empty file added types/dummy/index.d.ts
Empty file.
6 changes: 6 additions & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Types for compiled templates
declare module 'ember-exclaim/templates/*' {
import { TemplateFactory } from 'htmlbars-inline-precompile';
const tmpl: TemplateFactory;
export default tmpl;
}
81 changes: 81 additions & 0 deletions typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/** Rules for TypeScript code. */
module.exports = {
// eslint-disable-next-line node/no-unpublished-require
parser: require.resolve('@typescript-eslint/parser'),
plugins: ['@typescript-eslint', 'prettier'],
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/array-type': ['error', { default: 'generic' }],

// Disallow the use of bare `Function`, `Object` and boxed types
'@typescript-eslint/ban-types': [
'error',
{
types: {
Function: {
fixWith: '() => unknown',
message:
'Avoid `Function` in favor of a more precise callable type.',
},

String: {
fixWith: 'string',
message:
'Avoid boxed types. See https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#general-types',
},

Number: {
message:
'Avoid boxed types. See https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#general-types',
fixWith: 'number',
},

Symbol: {
message:
'Avoid boxed types. See https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#general-types',
fixWith: 'symbol',
},

Boolean: {
message:
'Avoid boxed types. See https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#general-types',
fixWith: 'boolean',
},
},
},
],

// We prefer `type` to `interface` for consistency, but unfortunately the lint rule for that
// is applied universally, including in `declare` blocks where changing an `interface` to a
// `type` breaks the intended semantics. It may be worth seeing if we can get that rule updated
// not to apply in places like that, but for now we just disable it.
//
// See https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/prefer-interface': 'off',
'@typescript-eslint/no-empty-interface': 'off',

// @ts-ignore is something we should generally avoid, but shouldn't need to include
// a static directive to allow us to insert other static directives.
'@typescript-eslint/ban-ts-comment': 'off',

// Only require return type annotations on declarations
'@typescript-eslint/explicit-function-return-type': [
'error',
{ allowExpressions: true },
],

// Require explicit visibility (`public`/`private`/`protected`) on class members
'@typescript-eslint/explicit-member-accessibility': 'error',

// These default to warnings rather than errors
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],

// Allow use of empty arrow functions
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['arrowFunctions'] },
],
},
};
Loading

0 comments on commit 67c9e71

Please sign in to comment.