From dd30e2af0d0f5e0d26b48c95edbd9fed5b304599 Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Tue, 22 Aug 2017 09:38:32 +1200 Subject: [PATCH] Fixed lint errors --- .../backbone.marionette-tests.ts | 51 ++++++++----------- types/backbone.marionette/index.d.ts | 37 ++++++-------- types/backbone.marionette/tslint.json | 3 ++ 3 files changed, 38 insertions(+), 53 deletions(-) create mode 100644 types/backbone.marionette/tslint.json diff --git a/types/backbone.marionette/backbone.marionette-tests.ts b/types/backbone.marionette/backbone.marionette-tests.ts index ac834f8ead..23a037d49c 100644 --- a/types/backbone.marionette/backbone.marionette-tests.ts +++ b/types/backbone.marionette/backbone.marionette-tests.ts @@ -6,7 +6,7 @@ class DestroyWarn extends Marionette.Behavior { // just like you can in your Backbone Models // they will be overriden if you pass in an option with the same key defaults = { - 'message': 'you are destroying!' + message: 'you are destroying!' }; // behaviors have events that are bound to the views DOM @@ -22,7 +22,6 @@ class DestroyWarn extends Marionette.Behavior { } } - Marionette.Behaviors.getBehaviorClass = (options, key) => { if (key === 'DestroyWarn') return DestroyWarn; @@ -44,7 +43,6 @@ class MyRouter extends Marionette.AppRouter { someOtherMethod() { // do something here. } - } class MyApplication extends Marionette.Application { @@ -60,7 +58,7 @@ class MyApplication extends Marionette.Application { this.mainRegion = new Marionette.Region({ el: '#main' }); this.layoutView.addRegion('main', this.mainRegion); this.layoutView.render(); - this.layoutView.showChildView('main', new MyView(new MyModel)); + this.layoutView.showChildView('main', new MyView(new MyModel())); let view: Backbone.View = this.layoutView.getChildView('main'); let regions: {[key: string]: Marionette.Region} = this.layoutView.getRegions(); let region: Marionette.Region = this.layoutView.removeRegion('main'); @@ -88,7 +86,6 @@ class AppLayoutView extends Marionette.View { } class MyModel extends Backbone.Model { - constructor(options?: any) { super(options); } @@ -103,7 +100,6 @@ class MyModel extends Backbone.Model { } class MyBaseView extends Marionette.View { - constructor() { super(); this.getOption('foo'); @@ -111,14 +107,13 @@ class MyBaseView extends Marionette.View { 'click .foo': 'bar' }; } - } class MyView extends Marionette.View { behaviors: any; constructor(model: MyModel) { - super({ model: model }); + super({ model }); this.ui = { destroy: '.destroy' @@ -134,8 +129,7 @@ class MyView extends Marionette.View { template() { return '

' + this.model.getName() + '

'; } -}; - +} class MainRegion extends Marionette.Region { constructor() { @@ -144,7 +138,6 @@ class MainRegion extends Marionette.Region { } } - class MyObject extends Marionette.Object { name: string; options: any; @@ -193,16 +186,16 @@ class MyCollectionView extends Marionette.CollectionView { super(); this.childView = MyView; this.childViewEvents = { - render: function () { + render() { console.log('a childView has been rendered'); } }; - this.childViewOptions = function (model: any, index: any): any { + this.childViewOptions = (model: any, index: any): any => { // do some calculations based on the model return { id: 'bar' - } + }; }; this.childViewOptions = { @@ -211,32 +204,30 @@ class MyCollectionView extends Marionette.CollectionView { this.childViewEventPrefix = 'some:prefix'; - this.on('some:prefix:render', function () { - + this.on('some:prefix:render', () => { }); - } } -var app: MyApplication; +let app: MyApplication; function ApplicationTests() { app = new MyApplication(); app.start(); - var view = new MyView(new MyModel()); + let view = new MyView(new MyModel()); app.mainRegion.show(view); } function ObjectTests() { - var obj = new MyObject(); + let obj = new MyObject(); console.log(obj.getOption('name')); obj.destroy('goodbye'); } function RegionTests() { - var myView: Marionette.View = new MyView(new MyModel()); + let myView: Marionette.View = new MyView(new MyModel()); // render and display the view app.mainRegion.show(myView); @@ -247,13 +238,13 @@ function RegionTests() { myView = new MyView(new MyModel()); app.mainRegion.show(myView, { preventDestroy: true }); - var hasView: boolean = app.mainRegion.hasView(); + let hasView: boolean = app.mainRegion.hasView(); app.mainRegion.reset(); - Marionette.Region.prototype.attachHtml = function (view: any): void { + Marionette.Region.prototype.attachHtml = (view: any): void => { this.$el.empty().append(view.el); - } + }; myView = new Marionette.View({ el: $('#existing-view-stuff') @@ -261,12 +252,11 @@ function RegionTests() { app.mainRegion.show(myView); - app.mainRegion.on('empty', function (view: any, region: any, options: any) { + app.mainRegion.on('empty', (view: any, region: any, options: any) => { // manipulate the `view` or do something extra // with the `region` // you also have access to the `options` that were passed to the Region.show call }); - } function ViewTests() { @@ -278,7 +268,7 @@ function ViewTests() { } function CollectionViewTests() { - var cv = new MyCollectionView(); + let cv = new MyCollectionView(); cv.collection.add(new MyModel()); app.mainRegion.show(cv); cv.emptyView = MyView; @@ -292,14 +282,13 @@ class MyController { } function AppRouterTests() { - var myController = new MyController(); - var router = new MyRouter(); + let myController = new MyController(); + let router = new MyRouter(); router.appRoute('/foo', 'fooThat'); router.processAppRoutes(myController, { - 'foo': 'doFoo', + foo: 'doFoo', 'bar/:id': 'doBar' }); - } diff --git a/types/backbone.marionette/index.d.ts b/types/backbone.marionette/index.d.ts index d833164d06..5292a4bfe7 100644 --- a/types/backbone.marionette/index.d.ts +++ b/types/backbone.marionette/index.d.ts @@ -1,10 +1,11 @@ -// Type definitions for Marionette v3.3.1 +// Type definitions for Marionette 3.3 // Project: https://github.com/marionettejs/ // Definitions by: Zeeshan Hamid , Natan Vivo , Sven Tschui // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 import * as Backbone from 'backbone'; +import * as JQuery from 'jquery'; import * as Radio from 'backbone.radio'; export as namespace Marionette; @@ -21,7 +22,6 @@ interface CommonMixin { } interface RadioMixinOptions { - /** * Defines the Radio channel that will be used for the requests and/or * events. @@ -62,7 +62,6 @@ interface DomMixin { } interface ViewMixinOptions { - /** * Behavior objects to assign to this View. */ @@ -143,7 +142,6 @@ interface RegionsMixin { } declare class Container { - /** * Find a view by it's cid. */ @@ -181,7 +179,6 @@ declare class Container { } declare namespace Marionette { - /** * Alias of Backbones extend function. */ @@ -272,7 +269,7 @@ declare namespace Marionette { * Initialize is called immediately after the Object has been instantiated, * and is invoked with the same arguments that the constructor received. */ - initialize?: (options?: ObjectOptions) => void; + initialize?(options?: ObjectOptions): void; [index: string]: any; } @@ -282,7 +279,6 @@ declare namespace Marionette { * backbone conventions and utilities like initialize and Backbone.Events. */ class Object extends Backbone.Events implements CommonMixin, RadioMixin { - constructor(options?: ObjectOptions); /** @@ -384,7 +380,6 @@ declare namespace Marionette { * in your HTML. This will improve the speed of subsequent calls to get a template. */ class TemplateCache implements DomMixin { - /** * Returns a new HTML DOM node instance. The resulting node can be * passed into the other DOM functions. @@ -425,7 +420,7 @@ declare namespace Marionette { * @param el is a jQuery argument: https://api.jquery.com/jQuery/ * @param html is a jQuery.html argument: https://api.jquery.com/html/ */ - setInnerContent(el: any, html: string | Function): void; + setInnerContent(el: any, html: string): void; /** * Detach el from the DOM. @@ -450,7 +445,10 @@ declare namespace Marionette { findEls(selector: any, context: any): void; /** - * To use the TemplateCache, call the get method on TemplateCache directly. Internally, instances of the TemplateCache class will be created and stored but you do not have to manually create these instances yourself. get will return a compiled template function. + * To use the TemplateCache, call the get method on TemplateCache + * directly. Internally, instances of the TemplateCache class will be + * created and stored but you do not have to manually create these + * instances yourself. get will return a compiled template function. */ static get(templateId: string, options?: any): any; @@ -526,7 +524,6 @@ declare namespace Marionette { * views in the correct place. */ class Region extends Object implements DomMixin { - /** * Returns a new HTML DOM node instance. The resulting node can be * passed into the other DOM functions. @@ -567,7 +564,7 @@ declare namespace Marionette { * @param el is a jQuery argument: https://api.jquery.com/jQuery/ * @param html is a jQuery.html argument: https://api.jquery.com/html/ */ - setInnerContent(el: any, html: string | Function): void; + setInnerContent(el: any, html: string): void; /** * Detach el from the DOM. @@ -712,7 +709,6 @@ declare namespace Marionette { } interface ViewOptions extends Backbone.ViewOptions, ViewMixinOptions { - /** * The events attribute binds DOM events to actions to perform on the * view. It takes DOM event key and a mapping to the handler. @@ -749,7 +745,6 @@ declare namespace Marionette { * easily nest multiple views through the regions attribute. */ class View extends Backbone.View implements ViewMixin, RegionsMixin { - constructor(options?: ViewOptions); events(): EventsHash; @@ -794,7 +789,7 @@ declare namespace Marionette { * @param el is a jQuery argument: https://api.jquery.com/jQuery/ * @param html is a jQuery.html argument: https://api.jquery.com/html/ */ - setInnerContent(el: any, html: string | Function): void; + setInnerContent(el: any, html: string): void; /** * Detach el from the DOM. @@ -1149,8 +1144,10 @@ declare namespace Marionette { ui: any; } - interface CollectionViewOptions = Backbone.Collection> extends Backbone.ViewOptions, ViewMixinOptions { - + interface CollectionViewOptions< + TModel extends Backbone.Model, + TCollection extends Backbone.Collection = Backbone.Collection + > extends Backbone.ViewOptions, ViewMixinOptions { /** * Specify a child view to use. */ @@ -1171,7 +1168,7 @@ declare namespace Marionette { * Prevent some of the underlying collection's models from being * rendered as child views. */ - filter?: (child?: TModel, index?: number, collection?: TCollection) => boolean; + filter?(child?: TModel, index?: number, collection?: TCollection): boolean; /** * Specify a view to use if the collection has no children. @@ -1211,7 +1208,6 @@ declare namespace Marionette { * initialize. */ class CollectionView, TCollection extends Backbone.Collection = Backbone.Collection> extends View { - constructor(options?: CollectionViewOptions); /** @@ -1457,7 +1453,6 @@ declare namespace Marionette { * user loads a specific endpoint directly. */ class AppRouter extends Backbone.Router { - constructor(options?: AppRouterOptions); /** @@ -1499,7 +1494,6 @@ declare namespace Marionette { * your app */ class Application extends Object { - constructor(options?: ApplicationOptions); /** @@ -1553,7 +1547,6 @@ declare namespace Marionette { * allowing you to share common user-facing operations between your views. */ class Behavior extends Object { - constructor(options?: any); options: any; diff --git a/types/backbone.marionette/tslint.json b/types/backbone.marionette/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/backbone.marionette/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}