From d5b468e1d1f61e9e90b34357d03698420765fd37 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Mon, 11 Jan 2021 15:56:20 +0800 Subject: [PATCH 1/3] fix(typing): AttrFunction --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index e5c8957f79..5620dbeab7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,7 +2,7 @@ import { Document, Element, DomHandlerOptions } from 'domhandler'; import { ParserOptions } from 'htmlparser2'; declare namespace cheerio { - type AttrFunction = (el: Element, i: number, currentValue: string) => any; + type AttrFunction = (this: Element, i: number, currentValue: string) => any; interface Cheerio { // Document References From 9813e733814e3d6797cb5b31500817266f1da3bd Mon Sep 17 00:00:00 2001 From: Max Ma Date: Mon, 11 Jan 2021 16:11:05 +0800 Subject: [PATCH 2/3] test(types): AttrFunction --- types/index.test-d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index bfed0143c2..3ccd05b98b 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -81,8 +81,8 @@ $el.cheerio; $el.attr(); $el.attr('id'); $el.attr('id', 'favorite').html(); -$el.attr('id', (el, i, attr) => el.tagName + i * 2 + attr).html(); -$el.attr('id', (el) => el.tagName).html(); +$el.attr('id', function (i, attr) { return this.tagName + i * 2 + attr }).html(); +$el.attr('id', function () { return this.tagName }).html(); $el.attr({ id: 'uniq', class: 'big' }).html(); $multiEl.prop('foo') === undefined; From e6330d8d4d110d2cc989d1a2372b35e24ce51bf0 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Mon, 11 Jan 2021 16:24:46 +0800 Subject: [PATCH 3/3] chore(lint): AttrFunction prettier --- types/index.test-d.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 3ccd05b98b..c86fcbfe0c 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -81,8 +81,16 @@ $el.cheerio; $el.attr(); $el.attr('id'); $el.attr('id', 'favorite').html(); -$el.attr('id', function (i, attr) { return this.tagName + i * 2 + attr }).html(); -$el.attr('id', function () { return this.tagName }).html(); +$el + .attr('id', function (i, attr) { + return this.tagName + i * 2 + attr; + }) + .html(); +$el + .attr('id', function () { + return this.tagName; + }) + .html(); $el.attr({ id: 'uniq', class: 'big' }).html(); $multiEl.prop('foo') === undefined;