-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port over linting and test for typings
- Move typings from lib/ to types/. - Add dtslint for validating types. - Use grunt-bg-shell to call out to dtslint during build step.
- Loading branch information
1 parent
f691db5
commit 3fb6687
Showing
6 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* These test cases were imported from https://github.com/DefinitelyTyped/DefinitelyTyped | ||
* and includes previous contributions from the DefinitelyTyped community. | ||
* For full history prior to their migration to handlebars.js, please see: | ||
* https://github.com/DefinitelyTyped/DefinitelyTyped/commits/1ce60bdc07f10e0b076778c6c953271c072bc894/types/handlebars/handlebars-tests.ts | ||
*/ | ||
|
||
import * as Handlebars from 'handlebars'; | ||
|
||
const context = { | ||
author: { firstName: 'Alan', lastName: 'Johnson' }, | ||
body: 'I Love Handlebars', | ||
comments: [{ | ||
author: { firstName: 'Yehuda', lastName: 'Katz' }, | ||
body: 'Me too!' | ||
}] | ||
}; | ||
Handlebars.registerHelper('fullName', (person: typeof context.author) => { | ||
return person.firstName + ' ' + person.lastName; | ||
}); | ||
|
||
Handlebars.registerHelper('agree_button', function(this: any) { | ||
return new Handlebars.SafeString( | ||
'<button>I agree. I ' + this.emotion + ' ' + this.name + '</button>' | ||
); | ||
}); | ||
|
||
const source1 = '<p>Hello, my name is {{name}}. I am from {{hometown}}. I have ' + | ||
'{{kids.length}} kids:</p>' + | ||
'<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>'; | ||
const template1 = Handlebars.compile(source1); | ||
template1({ name: "Alan", hometown: "Somewhere, TX", kids: [{name: "Jimmy", age: 12}, {name: "Sally", age: 4}]}); | ||
|
||
Handlebars.registerHelper('link_to', (context: typeof post) => { | ||
return '<a href="' + context.url + '">' + context.body + '</a>'; | ||
}); | ||
const post = { url: "/hello-world", body: "Hello World!" }; | ||
const context2 = { posts: [post] }; | ||
const source2 = '<ul>{{#posts}}<li>{{{link_to this}}}</li>{{/posts}}</ul>'; | ||
const template2: HandlebarsTemplateDelegate<{ posts: { url: string, body: string }[] }> = Handlebars.compile(source2); | ||
template2(context2); | ||
|
||
Handlebars.registerHelper('link_to', (title: string, context: typeof post) => { | ||
return '<a href="/posts' + context.url + '">' + title + '!</a>'; | ||
}); | ||
const context3 = { posts: [{url: '/hello-world', body: 'Hello World!'}] }; | ||
const source3 = '<ul>{{#posts}}<li>{{{link_to "Post" this}}}</li>{{/posts}}</ul>'; | ||
const template3 = Handlebars.compile<typeof context3>(source3); | ||
template3(context3); | ||
|
||
const source4 = '<ul>{{#people}}<li>{{#link}}{{name}}{{/link}}</li>{{/people}}</ul>'; | ||
Handlebars.registerHelper('link', function(this: any, context: any) { | ||
return '<a href="/people/' + this.id + '">' + context.fn(this) + '</a>'; | ||
}); | ||
const template4 = Handlebars.compile<{ people: { name: string, id: number }[] }>(source4); | ||
const data2 = { 'people': [ | ||
{ 'name': 'Alan', 'id': 1 }, | ||
{ 'name': 'Yehuda', 'id': 2 } | ||
]}; | ||
template4(data2); | ||
|
||
const source5 = '<ul>{{#people}}<li>{{> link}}</li>{{/people}}</ul>'; | ||
Handlebars.registerPartial('link', '<a href="/people/{{id}}">{{name}}</a>'); | ||
const template5 = Handlebars.compile(source5); | ||
const data3 = { 'people': [ | ||
{ 'name': 'Alan', 'id': 1 }, | ||
{ 'name': 'Yehuda', 'id': 2 } | ||
]}; | ||
template5(data3); | ||
|
||
const source6 = '{{#list nav}}<a href="{{url}}">{{title}}</a>{{/list}}'; | ||
const template6 = Handlebars.compile(source6); | ||
Handlebars.registerHelper('list', (context, options: Handlebars.HelperOptions) => { | ||
let ret = "<ul>"; | ||
for(let i=0, j=context.length; i<j; i++) { | ||
ret = ret + "<li>" + options.fn(context[i]) + "</li>"; | ||
} | ||
return ret + "</ul>"; | ||
}); | ||
template6([{url:"", title:""}]) | ||
|
||
|
||
const escapedExpression = Handlebars.Utils.escapeExpression('<script>alert(\'xss\');</script>'); | ||
|
||
Handlebars.helpers !== undefined; | ||
|
||
const parsedTmpl = Handlebars.parse('<p>Hello, my name is {{name}}.</p>', { | ||
srcName: "/foo/bar/baz.hbs", | ||
ignoreStandalone: true | ||
}); | ||
|
||
const parsedTmplWithoutOptions = Handlebars.parse('<p>Hello, my name is {{name}}.</p>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"noEmit": true, | ||
|
||
"baseUrl": ".", | ||
"paths": { | ||
"handlebars": ["."] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"adjacent-overload-signatures": false, | ||
"array-type": false, | ||
"arrow-return-shorthand": false, | ||
"ban-types": false, | ||
"callable-types": false, | ||
"comment-format": false, | ||
"dt-header": false, | ||
"eofline": false, | ||
"export-just-namespace": false, | ||
"import-spacing": false, | ||
"interface-name": false, | ||
"interface-over-type-literal": false, | ||
"jsdoc-format": false, | ||
"max-line-length": false, | ||
"member-access": false, | ||
"new-parens": false, | ||
"no-any-union": false, | ||
"no-boolean-literal-compare": false, | ||
"no-conditional-assignment": false, | ||
"no-consecutive-blank-lines": false, | ||
"no-construct": false, | ||
"no-declare-current-package": false, | ||
"no-duplicate-imports": false, | ||
"no-duplicate-variable": false, | ||
"no-empty-interface": false, | ||
"no-for-in-array": false, | ||
"no-inferrable-types": false, | ||
"no-internal-module": false, | ||
"no-irregular-whitespace": false, | ||
"no-mergeable-namespace": false, | ||
"no-misused-new": false, | ||
"no-namespace": false, | ||
"no-object-literal-type-assertion": false, | ||
"no-padding": false, | ||
"no-redundant-jsdoc": false, | ||
"no-redundant-jsdoc-2": false, | ||
"no-redundant-undefined": false, | ||
"no-reference-import": false, | ||
"no-relative-import-in-test": false, | ||
"no-self-import": false, | ||
"no-single-declare-module": false, | ||
"no-string-throw": false, | ||
"no-unnecessary-callback-wrapper": false, | ||
"no-unnecessary-class": false, | ||
"no-unnecessary-generics": false, | ||
"no-unnecessary-qualifier": false, | ||
"no-unnecessary-type-assertion": false, | ||
"no-useless-files": false, | ||
"no-var-keyword": false, | ||
"no-var-requires": false, | ||
"no-void-expression": false, | ||
"no-trailing-whitespace": false, | ||
"object-literal-key-quotes": false, | ||
"object-literal-shorthand": false, | ||
"one-line": false, | ||
"one-variable-per-declaration": false, | ||
"only-arrow-functions": false, | ||
"prefer-conditional-expression": false, | ||
"prefer-const": false, | ||
"prefer-declare-function": false, | ||
"prefer-for-of": false, | ||
"prefer-method-signature": false, | ||
"prefer-template": false, | ||
"radix": false, | ||
"semicolon": false, | ||
"space-before-function-paren": false, | ||
"space-within-parens": false, | ||
"strict-export-declare-modifiers": false, | ||
"trim-file": false, | ||
"triple-equals": false, | ||
"typedef-whitespace": false, | ||
"unified-signatures": false, | ||
"void-return": false, | ||
"whitespace": false | ||
} | ||
} |