From f31a031a634a9af88d3c104915061e1a5a6420a5 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 7 Feb 2018 23:01:56 +0200 Subject: [PATCH] chore: fix lint errors and test --- src/services/MarkdownRenderer.ts | 7 +++-- .../__tests__/MarkdownRenderer.test.ts | 10 +++---- src/utils/decorators.ts | 29 ++++++++++++------- tslint.json | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/services/MarkdownRenderer.ts b/src/services/MarkdownRenderer.ts index 57fa9f27..588ca333 100644 --- a/src/services/MarkdownRenderer.ts +++ b/src/services/MarkdownRenderer.ts @@ -1,9 +1,9 @@ import * as Remarkable from 'remarkable'; +import slugify from 'slugify'; import { MDComponent } from '../components/Markdown/Markdown'; import { highlight, html2Str } from '../utils'; import { SECTION_ATTR } from './MenuStore'; -import slugify from 'slugify'; const md = new Remarkable('default', { html: true, @@ -47,6 +47,7 @@ export class MarkdownRenderer { const item = { id: 'section' + '/' + slugify(name), name, + items: [], }; container.push(item); return item; @@ -139,8 +140,8 @@ export class MarkdownRenderer { } extractHeadings(rawText: string): MarkdownHeading[] { - const md = this.renderMd(rawText, false); - this.attachHeadingsDescriptions(md); + const text = this.renderMd(rawText, false); + this.attachHeadingsDescriptions(text); const res = this.headings; this.headings = []; return res; diff --git a/src/services/__tests__/MarkdownRenderer.test.ts b/src/services/__tests__/MarkdownRenderer.test.ts index bf2c2667..13d44617 100644 --- a/src/services/__tests__/MarkdownRenderer.test.ts +++ b/src/services/__tests__/MarkdownRenderer.test.ts @@ -12,10 +12,10 @@ describe('Markdown renderer', () => { expect(renderer.headings[0].name).toEqual('Sub Intro'); }); test('should return a level-2 heading as a child of level-1', () => { - renderer.renderMd('# Introduction \n ## Sub Intro', false); - expect(renderer.headings).toHaveLength(1); - expect(renderer.headings[0].name).toEqual('Introduction'); - expect(renderer.headings[0].items).toBeDefined(); - expect(renderer.headings[0].items).toHaveLength(1); + const headings = renderer.extractHeadings('# Introduction \n ## Sub Intro', false); + expect(headings).toHaveLength(1); + expect(headings[0].name).toEqual('Introduction'); + expect(headings[0].items).toBeDefined(); + expect(headings[0].items).toHaveLength(1); }); }); diff --git a/src/utils/decorators.ts b/src/utils/decorators.ts index 027c2023..62624a01 100644 --- a/src/utils/decorators.ts +++ b/src/utils/decorators.ts @@ -1,15 +1,20 @@ -const throttle = function(func, wait) { - var context, args, result; - var timeout: any = null; - var previous = 0; - var later = function() { - (previous = new Date().getTime()), (timeout = null); +function throttle(func, wait) { + let context; + let args; + let result; + let timeout: any = null; + let previous = 0; + const later = () => { + previous = new Date().getTime(); + timeout = null; result = func.apply(context, args); - if (!timeout) context = args = null; + if (!timeout) { + context = args = null; + } }; return function() { - var now = new Date().getTime(); - var remaining = wait - (now - previous); + const now = new Date().getTime(); + const remaining = wait - (now - previous); context = this; args = arguments; if (remaining <= 0 || remaining > wait) { @@ -19,13 +24,15 @@ const throttle = function(func, wait) { } previous = now; result = func.apply(context, args); - if (!timeout) context = args = null; + if (!timeout) { + context = args = null; + } } else if (!timeout) { timeout = setTimeout(later, remaining); } return result; }; -}; +} export function Throttle(delay: number) { return (_, _2, desc: PropertyDescriptor) => { diff --git a/tslint.json b/tslint.json index 415245bb..e7e8fcf1 100644 --- a/tslint.json +++ b/tslint.json @@ -17,7 +17,7 @@ "quotemark": [true, "single", "avoid-template", "jsx-double"], "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"], "arrow-parens": [true, "ban-single-arg-parens"], - "no-submodule-imports": [true, "prismjs", "perfect-scrollbar"], + "no-submodule-imports": [true, "prismjs", "perfect-scrollbar", "react-tippy"], "object-literal-key-quotes": [true, "as-needed"], "no-unused-expression": [true, "allow-tagged-template"], "semicolon": [true, "always", "ignore-bound-class-methods"],