diff --git a/.eslintrc.json b/.eslintrc.json index 09aa97c0f1..2522061174 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -42,6 +42,7 @@ "no-unused-expressions": 2, "no-useless-call": 2, "no-use-before-define": [2, "nofunc"], + "no-constant-binary-expression": 2, "no-void": 2, "jsdoc/require-jsdoc": 0, @@ -83,6 +84,9 @@ "project": "./tsconfig.eslint.json" }, "rules": { + "dot-notation": 0, + "curly": [2, "multi-line"], + "@typescript-eslint/prefer-for-of": 0, "@typescript-eslint/member-ordering": 0, "@typescript-eslint/explicit-function-return-type": 0, diff --git a/src/api/attributes.spec.ts b/src/api/attributes.spec.ts index 4bd6802f76..ec60bb3ddc 100644 --- a/src/api/attributes.spec.ts +++ b/src/api/attributes.spec.ts @@ -51,9 +51,9 @@ describe('$(...)', () => { 'pear' ) as Cheerio; - expect($el[0].attribs.class).toBe('pear'); + expect($el[0].attribs).toHaveProperty('class', 'pear'); expect($el[1].attribs).toBeUndefined(); - expect($el[2].attribs.class).toBe('pear'); + expect($el[2].attribs).toHaveProperty('class', 'pear'); }); it('(key, value) : should return an empty object for an empty object', () => { @@ -204,7 +204,7 @@ describe('$(...)', () => { it('(valid key) : valid prop should get value', () => { expect(checkbox.prop('checked')).toBe(true); checkbox.css('display', 'none'); - expect(checkbox.prop('style').display).toBe('none'); + expect(checkbox.prop('style')).toHaveProperty('display', 'none'); expect(checkbox.prop('style')).toHaveLength(1); expect(checkbox.prop('style')).toContain('display'); expect(checkbox.prop('tagName')).toBe('INPUT'); diff --git a/src/api/attributes.ts b/src/api/attributes.ts index 1dd6962b35..a4b70c21d0 100644 --- a/src/api/attributes.ts +++ b/src/api/attributes.ts @@ -76,7 +76,7 @@ function getAttr( // Mimic DOM with default value for radios/checkboxes if ( elem.name === 'input' && - (elem.attribs.type === 'radio' || elem.attribs.type === 'checkbox') && + (elem.attribs['type'] === 'radio' || elem.attribs['type'] === 'checkbox') && name === 'value' ) { return 'on'; @@ -387,13 +387,14 @@ export function prop( throw new Error('Bad combination of arguments.'); } return domEach(this, (el, i) => { - if (isTag(el)) + if (isTag(el)) { setProp( el, name, value.call(el, i, getProp(el, name, this.options.xmlMode)), this.options.xmlMode ); + } }); } @@ -599,9 +600,10 @@ export function data( // Set the value (with attr map support) if (typeof name === 'object' || value !== undefined) { domEach(this, (el) => { - if (isTag(el)) + if (isTag(el)) { if (typeof name === 'object') setData(el, name); else setData(el, name, value as unknown); + } }); return this; } @@ -777,7 +779,7 @@ export function hasClass( className: string ): boolean { return this.toArray().some((elem) => { - const clazz = isTag(elem) && elem.attribs.class; + const clazz = isTag(elem) && elem.attribs['class']; let idx = -1; if (clazz && className.length) { @@ -825,7 +827,7 @@ export function addClass>( if (typeof value === 'function') { return domEach(this, (el, i) => { if (isTag(el)) { - const className = el.attribs.class || ''; + const className = el.attribs['class'] || ''; addClass.call([el], value.call(el, i, className)); } }); @@ -891,8 +893,9 @@ export function removeClass>( // Handle if value is a function if (typeof name === 'function') { return domEach(this, (el, i) => { - if (isTag(el)) - removeClass.call([el], name.call(el, i, el.attribs.class || '')); + if (isTag(el)) { + removeClass.call([el], name.call(el, i, el.attribs['class'] || '')); + } }); } @@ -905,9 +908,9 @@ export function removeClass>( if (removeAll) { // Short circuit the remove all case as this is the nice one - el.attribs.class = ''; + el.attribs['class'] = ''; } else { - const elClasses = splitNames(el.attribs.class); + const elClasses = splitNames(el.attribs['class']); let changed = false; for (let j = 0; j < numClasses; j++) { @@ -925,7 +928,7 @@ export function removeClass>( } } if (changed) { - el.attribs.class = elClasses.join(' '); + el.attribs['class'] = elClasses.join(' '); } } }); @@ -969,7 +972,7 @@ export function toggleClass>( if (isTag(el)) { toggleClass.call( [el], - value.call(el, i, el.attribs.class || '', stateVal), + value.call(el, i, el.attribs['class'] || '', stateVal), stateVal ); } @@ -989,7 +992,7 @@ export function toggleClass>( // If selected element isn't a tag, move on if (!isTag(el)) continue; - const elementClasses = splitNames(el.attribs.class); + const elementClasses = splitNames(el.attribs['class']); // Check if class already exists for (let j = 0; j < numClasses; j++) { @@ -1005,7 +1008,7 @@ export function toggleClass>( } } - el.attribs.class = elementClasses.join(' '); + el.attribs['class'] = elementClasses.join(' '); } return this; diff --git a/src/api/css.ts b/src/api/css.ts index fe0c400366..2a63767823 100644 --- a/src/api/css.ts +++ b/src/api/css.ts @@ -112,7 +112,7 @@ function setCss( styles[prop] = val; } - el.attribs.style = stringify(styles); + el.attribs['style'] = stringify(styles); } else if (typeof prop === 'object') { Object.keys(prop).forEach((k, i) => { setCss(el, k, prop[k], i); @@ -146,7 +146,7 @@ function getCss( ): Record | string | undefined { if (!el || !isTag(el)) return; - const styles = parse(el.attribs.style); + const styles = parse(el.attribs['style']); if (typeof prop === 'string') { return styles[prop]; } diff --git a/src/api/traversing.spec.ts b/src/api/traversing.spec.ts index 5ccc8c015d..7c6ebe370a 100644 --- a/src/api/traversing.spec.ts +++ b/src/api/traversing.spec.ts @@ -40,13 +40,16 @@ describe('$(...)', () => { }); it('(single) : should find one descendant', () => { - expect($('#fruits').find('.apple')[0].attribs.class).toBe('apple'); + expect($('#fruits').find('.apple')[0].attribs).toHaveProperty( + 'class', + 'apple' + ); }); // #1679 - text tags not filtered it('(single) : should filter out text nodes', () => { const $root = $(`\n${fruits.replace(/>\n<')}\n`); - expect($root.find('.apple')[0].attribs.class).toBe('apple'); + expect($root.find('.apple')[0].attribs).toHaveProperty('class', 'apple'); }); it('(many) : should find all matching descendant', () => { @@ -158,8 +161,8 @@ describe('$(...)', () => { }); it('(selector) : should return children matching selector', () => { - const cls = $('ul').children('.orange')[0].attribs.class; - expect(cls).toBe('orange'); + const { attribs } = $('ul').children('.orange')[0]; + expect(attribs).toHaveProperty('class', 'orange'); }); it('(invalid selector) : should return empty', () => { @@ -195,8 +198,8 @@ describe('$(...)', () => { describe('.next', () => { it('() : should return next element', () => { - const cls = $('.orange').next()[0].attribs.class; - expect(cls).toBe('pear'); + const { attribs } = $('.orange').next()[0]; + expect(attribs).toHaveProperty('class', 'pear'); }); it('() : should skip text nodes', () => { @@ -245,8 +248,8 @@ describe('$(...)', () => { it('() : should return all following siblings', () => { const elems = $('.apple').nextAll(); expect(elems).toHaveLength(2); - expect(elems[0].attribs.class).toBe('orange'); - expect(elems[1].attribs.class).toBe('pear'); + expect(elems[0].attribs).toHaveProperty('class', 'orange'); + expect(elems[1].attribs).toHaveProperty('class', 'pear'); }); it('(no next) : should return empty for last child', () => { @@ -286,8 +289,8 @@ describe('$(...)', () => { it('() : should return all following siblings if no selector specified', () => { const elems = $('.apple', food).nextUntil(); expect(elems).toHaveLength(2); - expect(elems[0].attribs.class).toBe('orange'); - expect(elems[1].attribs.class).toBe('pear'); + expect(elems[0].attribs).toHaveProperty('class', 'orange'); + expect(elems[1].attribs).toHaveProperty('class', 'pear'); }); it('() : should filter out non-element nodes', () => { @@ -309,14 +312,14 @@ describe('$(...)', () => { it('(selector) : should return all following siblings until selector', () => { const elems = $('.apple', food).nextUntil('.pear'); expect(elems).toHaveLength(1); - expect(elems[0].attribs.class).toBe('orange'); + expect(elems[0].attribs).toHaveProperty('class', 'orange'); }); it('(selector) : should support selector matching multiple elements', () => { const elems = $('#disabled', forms).nextUntil('option, #unnamed'); expect(elems).toHaveLength(2); - expect(elems[0].attribs.id).toBe('submit'); - expect(elems[1].attribs.id).toBe('select'); + expect(elems[0].attribs).toHaveProperty('id', 'submit'); + expect(elems[1].attribs).toHaveProperty('id', 'select'); }); it('(selector not sibling) : should return all following siblings', () => { @@ -327,7 +330,7 @@ describe('$(...)', () => { it('(selector, filterString) : should return all following siblings until selector, filtered by filter', () => { const elems = $('.beer', drinks).nextUntil('.water', '.milk'); expect(elems).toHaveLength(1); - expect(elems[0].attribs.class).toBe('milk'); + expect(elems[0].attribs).toHaveProperty('class', 'milk'); }); it('(null, filterString) : should return all following siblings until selector, filtered by filter', () => { @@ -360,8 +363,8 @@ describe('$(...)', () => { describe('.prev', () => { it('() : should return previous element', () => { - const cls = $('.orange').prev()[0].attribs.class; - expect(cls).toBe('apple'); + const { attribs } = $('.orange').prev()[0]; + expect(attribs).toHaveProperty('class', 'apple'); }); it('() : should skip text nodes', () => { @@ -422,8 +425,8 @@ describe('$(...)', () => { it('() : should return all preceding siblings', () => { const elems = $('.pear').prevAll(); expect(elems).toHaveLength(2); - expect(elems[0].attribs.class).toBe('orange'); - expect(elems[1].attribs.class).toBe('apple'); + expect(elems[0].attribs).toHaveProperty('class', 'orange'); + expect(elems[1].attribs).toHaveProperty('class', 'apple'); }); it('() : should not contain text elements', () => { @@ -465,8 +468,8 @@ describe('$(...)', () => { it('() : should return all preceding siblings if no selector specified', () => { const elems = $('.pear').prevUntil(); expect(elems).toHaveLength(2); - expect(elems[0].attribs.class).toBe('orange'); - expect(elems[1].attribs.class).toBe('apple'); + expect(elems[0].attribs).toHaveProperty('class', 'orange'); + expect(elems[1].attribs).toHaveProperty('class', 'apple'); }); it('() : should filter out non-element nodes', () => { @@ -490,26 +493,26 @@ describe('$(...)', () => { it('(selector) : should return all preceding siblings until selector', () => { const elems = $('.pear').prevUntil('.apple'); expect(elems).toHaveLength(1); - expect(elems[0].attribs.class).toBe('orange'); + expect(elems[0].attribs).toHaveProperty('class', 'orange'); }); it('(selector) : should support selector matching multiple elements', () => { const elems = $('#unnamed', forms).prevUntil('option, #disabled'); expect(elems).toHaveLength(2); - expect(elems[0].attribs.id).toBe('select'); - expect(elems[1].attribs.id).toBe('submit'); + expect(elems[0].attribs).toHaveProperty('id', 'select'); + expect(elems[1].attribs).toHaveProperty('id', 'submit'); }); it('(selector not sibling) : should return all preceding siblings', () => { const elems = $('.sweetcorn', food).prevUntil('#fruits'); expect(elems).toHaveLength(1); - expect(elems[0].attribs.class).toBe('carrot'); + expect(elems[0].attribs).toHaveProperty('class', 'carrot'); }); it('(selector, filterString) : should return all preceding siblings until selector, filtered by filter', () => { const elems = $('.cider', drinks).prevUntil('.juice', '.water'); expect(elems).toHaveLength(1); - expect(elems[0].attribs.class).toBe('water'); + expect(elems[0].attribs).toHaveProperty('class', 'water'); }); it('(selector, filterString) : should return all preceding siblings until selector', () => { @@ -600,13 +603,13 @@ describe('$(...)', () => { it('() : should get all of the parents in logical order', () => { let result = $('.orange').parents(); expect(result).toHaveLength(4); - expect(result[0].attribs.id).toBe('fruits'); - expect(result[1].attribs.id).toBe('food'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); + expect(result[1].attribs).toHaveProperty('id', 'food'); expect(result[2].tagName).toBe('body'); expect(result[3].tagName).toBe('html'); result = $('#fruits').parents(); expect(result).toHaveLength(3); - expect(result[0].attribs.id).toBe('food'); + expect(result[0].attribs).toHaveProperty('id', 'food'); expect(result[1].tagName).toBe('body'); expect(result[2].tagName).toBe('html'); }); @@ -614,11 +617,11 @@ describe('$(...)', () => { it('(selector) : should get all of the parents that match the selector in logical order', () => { let result = $('.orange').parents('#fruits'); expect(result).toHaveLength(1); - expect(result[0].attribs.id).toBe('fruits'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); result = $('.orange').parents('ul'); expect(result).toHaveLength(2); - expect(result[0].attribs.id).toBe('fruits'); - expect(result[1].attribs.id).toBe('food'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); + expect(result[1].attribs).toHaveProperty('id', 'food'); }); it('() : should not break if the selector does not have any results', () => { @@ -651,8 +654,8 @@ describe('$(...)', () => { it('() : should get all of the parents in logical order', () => { const result = $('.orange').parentsUntil(); expect(result).toHaveLength(4); - expect(result[0].attribs.id).toBe('fruits'); - expect(result[1].attribs.id).toBe('food'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); + expect(result[1].attribs).toHaveProperty('id', 'food'); expect(result[2].tagName).toBe('body'); expect(result[3].tagName).toBe('html'); }); @@ -670,7 +673,7 @@ describe('$(...)', () => { it('(selector) : should get all of the parents until selector', () => { let result = $('.orange').parentsUntil('#food'); expect(result).toHaveLength(1); - expect(result[0].attribs.id).toBe('fruits'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); result = $('.orange').parentsUntil('#fruits'); expect(result).toHaveLength(0); }); @@ -683,8 +686,8 @@ describe('$(...)', () => { it('(selector not parent) : should return all parents', () => { const result = $('.orange').parentsUntil('.apple'); expect(result).toHaveLength(4); - expect(result[0].attribs.id).toBe('fruits'); - expect(result[1].attribs.id).toBe('food'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); + expect(result[1].attribs).toHaveProperty('id', 'food'); expect(result[2].tagName).toBe('body'); expect(result[3].tagName).toBe('html'); }); @@ -695,7 +698,7 @@ describe('$(...)', () => { '#vegetables' ); expect(result).toHaveLength(1); - expect(result[0].attribs.id).toBe('vegetables'); + expect(result[0].attribs).toHaveProperty('id', 'vegetables'); }); it('(selector, filter) : Multiple-filtered parentsUntil check', () => { @@ -721,7 +724,7 @@ describe('$(...)', () => { const $until = $('#food'); const result = $fruits.children().eq(1).parentsUntil($until); expect(result).toHaveLength(1); - expect(result[0].attribs.id).toBe('fruits'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); }); it('(cheerio object) : should return all parents until body element', () => { @@ -736,11 +739,11 @@ describe('$(...)', () => { it('() : should return the parent of each matched element', () => { let result = $('.orange').parent(); expect(result).toHaveLength(1); - expect(result[0].attribs.id).toBe('fruits'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); result = $('li', food).parent(); expect(result).toHaveLength(2); - expect(result[0].attribs.id).toBe('fruits'); - expect(result[1].attribs.id).toBe('vegetables'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); + expect(result[1].attribs).toHaveProperty('id', 'vegetables'); }); it('(undefined) : should not throw an exception', () => { @@ -762,10 +765,10 @@ describe('$(...)', () => { it('(selector) : should filter the matched parent elements by the selector', () => { let result = $('.orange').parent(); expect(result).toHaveLength(1); - expect(result[0].attribs.id).toBe('fruits'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); result = $('li', food).parent('#fruits'); expect(result).toHaveLength(1); - expect(result[0].attribs.id).toBe('fruits'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); }); }); @@ -779,11 +782,11 @@ describe('$(...)', () => { it('(selector) : should find the closest element that matches the selector, searching through its ancestors and itself', () => { expect($('.orange').closest('.apple')).toHaveLength(0); let result = $('.orange', food).closest('#food') as Cheerio; - expect(result[0].attribs.id).toBe('food'); + expect(result[0].attribs).toHaveProperty('id', 'food'); result = $('.orange', food).closest('ul') as Cheerio; - expect(result[0].attribs.id).toBe('fruits'); + expect(result[0].attribs).toHaveProperty('id', 'fruits'); result = $('.orange', food).closest('li') as Cheerio; - expect(result[0].attribs.class).toBe('orange'); + expect(result[0].attribs).toHaveProperty('class', 'orange'); }); it('(selector) : should find the closest element of each item, removing duplicates', () => { @@ -803,11 +806,11 @@ describe('$(...)', () => { const classes = ['apple', 'orange', 'pear']; $('li').each(function (idx, elem) { items[idx] = elem; - expect(this.attribs.class).toBe(classes[idx]); + expect(this.attribs).toHaveProperty('class', classes[idx]); }); - expect(items[0].attribs.class).toBe('apple'); - expect(items[1].attribs.class).toBe('orange'); - expect(items[2].attribs.class).toBe('pear'); + expect(items[0].attribs).toHaveProperty('class', 'apple'); + expect(items[1].attribs).toHaveProperty('class', 'orange'); + expect(items[2].attribs).toHaveProperty('class', 'pear'); }); it('( (i, elem) -> ) : should break iteration when the iterator function returns false', () => { @@ -827,9 +830,9 @@ describe('$(...)', () => { // The equivalent of: for (const element of $('li')) ... const $li = $('li'); const iterator = $li[Symbol.iterator](); - expect(iterator.next().value.attribs.class).toBe('apple'); - expect(iterator.next().value.attribs.class).toBe('orange'); - expect(iterator.next().value.attribs.class).toBe('pear'); + expect(iterator.next().value.attribs).toHaveProperty('class', 'apple'); + expect(iterator.next().value.attribs).toHaveProperty('class', 'orange'); + expect(iterator.next().value.attribs).toHaveProperty('class', 'pear'); expect(iterator.next().done).toBe(true); }); }); diff --git a/src/cheerio.spec.ts b/src/cheerio.spec.ts index ef4f19b83d..c93d44bd28 100644 --- a/src/cheerio.spec.ts +++ b/src/cheerio.spec.ts @@ -2,7 +2,7 @@ import { parseDOM } from 'htmlparser2'; import cheerio from '.'; import * as utils from './utils'; import { fruits, food, noscript } from './__fixtures__/fixtures'; -import { Cheerio } from './cheerio'; +import type { Cheerio } from './cheerio'; import type { Element } from 'domhandler'; import type { CheerioOptions } from './options'; @@ -56,7 +56,7 @@ describe('cheerio', () => { const $script = cheerio(script) as Cheerio; expect($script).not.toHaveLength(0); expect($script).toHaveLength(1); - expect($script[0].attribs.src).toBe('script.js'); + expect($script[0].attribs).toHaveProperty('src', 'script.js'); expect($script[0].attribs).toHaveProperty('type', 'text/javascript'); expect($script[0].childNodes).toHaveLength(0); }); @@ -66,7 +66,7 @@ describe('cheerio', () => { const apple = $apple[0]; expect(apple.parentNode).toHaveProperty('tagName', 'ul'); expect(apple.prev).toBe(null); - expect((apple.next as Element).attribs.class).toBe('orange'); + expect((apple.next as Element).attribs).toHaveProperty('class', 'orange'); expect(apple.childNodes).toHaveLength(1); expect(apple.childNodes[0]).toHaveProperty('data', 'Apple'); } @@ -92,7 +92,7 @@ describe('cheerio', () => { it('should be able to select an id', () => { const $fruits = cheerio('#fruits', null, fruits); expect($fruits).toHaveLength(1); - expect($fruits[0].attribs.id).toBe('fruits'); + expect($fruits[0].attribs).toHaveProperty('id', 'fruits'); }); it('should be able to select a tag', () => { @@ -124,7 +124,7 @@ describe('cheerio', () => { expect($fruits).toHaveLength(3); const classes = ['apple', 'orange', 'pear']; $fruits.each((idx, $fruit) => { - expect($fruit.attribs.class).toBe(classes[idx]); + expect($fruit.attribs).toHaveProperty('class', classes[idx]); }); }); @@ -163,12 +163,12 @@ describe('cheerio', () => { const $apple = $elems .toArray() - .filter((elem) => elem.attribs.class === 'apple'); + .filter((elem) => elem.attribs['class'] === 'apple'); const $fruits = $elems .toArray() - .filter((elem) => elem.attribs.id === 'fruits'); + .filter((elem) => elem.attribs['id'] === 'fruits'); testAppleSelect($apple); - expect($fruits[0].attribs.id).toBe('fruits'); + expect($fruits[0].attribs).toHaveProperty('id', 'fruits'); }); it('should select first element cheerio(:first)', () => { diff --git a/src/cheerio.ts b/src/cheerio.ts index 657ef98e89..f7fbacdf20 100644 --- a/src/cheerio.ts +++ b/src/cheerio.ts @@ -1,6 +1,6 @@ -import { InternalOptions } from './options'; +import type { InternalOptions } from './options'; import type { AnyNode, Document, ParentNode } from 'domhandler'; -import { BasicAcceptedElems } from './types'; +import type { BasicAcceptedElems } from './types'; import * as Attributes from './api/attributes'; import * as Traversing from './api/traversing'; diff --git a/src/load.ts b/src/load.ts index 2d15a6356a..2038f222a7 100644 --- a/src/load.ts +++ b/src/load.ts @@ -8,7 +8,7 @@ import * as staticMethods from './static'; import { Cheerio } from './cheerio'; import { isHtml, isCheerio } from './utils'; import type { AnyNode, Document, Element, ParentNode } from 'domhandler'; -import { SelectorType, BasicAcceptedElems } from './types'; +import type { SelectorType, BasicAcceptedElems } from './types'; type StaticType = typeof staticMethods; diff --git a/src/parse.spec.ts b/src/parse.spec.ts index 3c10d10a6a..2931758a2f 100644 --- a/src/parse.spec.ts +++ b/src/parse.spec.ts @@ -101,15 +101,15 @@ describe('parse', () => { const attrs = parse(attributes, defaultOpts, false, null) .children[0] as Element; expect(attrs.attribs).toBeTruthy(); - expect(attrs.attribs.src).toBe('hello.png'); - expect(attrs.attribs.alt).toBe('man waving'); + expect(attrs.attribs).toHaveProperty('src', 'hello.png'); + expect(attrs.attribs).toHaveProperty('alt', 'man waving'); }); it(`should handle value-less attributes: ${noValueAttribute}`, () => { const attrs = parse(noValueAttribute, defaultOpts, false, null) .children[0] as Element; expect(attrs.attribs).toBeTruthy(); - expect(attrs.attribs.disabled).toBe(''); + expect(attrs.attribs).toHaveProperty('disabled', ''); }); it(`should handle comments: ${comment}`, () => { @@ -138,7 +138,7 @@ describe('parse', () => { .children[0] as Element; expect(script_.type).toBe('script'); expect(script_.tagName).toBe('script'); - expect(script_.attribs.type).toBe('text/javascript'); + expect(script_.attribs).toHaveProperty('type', 'text/javascript'); expect(script_.childNodes).toHaveLength(1); expect(script_.childNodes[0].type).toBe('text'); expect(script_.childNodes[0]).toHaveProperty( @@ -152,7 +152,7 @@ describe('parse', () => { .children[0] as Element; expect(style_.type).toBe('style'); expect(style_.tagName).toBe('style'); - expect(style_.attribs.type).toBe('text/css'); + expect(style_.attribs).toHaveProperty('type', 'text/css'); expect(style_.childNodes).toHaveLength(1); expect(style_.childNodes[0].type).toBe('text'); expect(style_.childNodes[0]).toHaveProperty( @@ -388,7 +388,7 @@ describe('parse', () => { const root = parse(html, defaultOpts, false, null); const childNodes = root.childNodes as Element[]; - expect(childNodes[0].attribs.style).toBe(expectedAttr); + expect(childNodes[0].attribs).toHaveProperty('style', expectedAttr); }); it('Should treat tag content as text', () => { diff --git a/src/static.ts b/src/static.ts index c3b9dcd55a..cba34410c6 100644 --- a/src/static.ts +++ b/src/static.ts @@ -1,4 +1,4 @@ -import { BasicAcceptedElems } from './types'; +import type { BasicAcceptedElems } from './types'; import type { CheerioAPI, Cheerio } from '.'; import { AnyNode, Document, isText, hasChildren } from 'domhandler'; import { diff --git a/tsconfig.json b/tsconfig.json index a4165129ff..42a229c78b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,30 +1,31 @@ { "compilerOptions": { /* Basic Options */ - "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, - "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, - // "lib": [], /* Specify library files to be included in the compilation. */ - "declaration": true /* Generates corresponding '.d.ts' file. */, - "declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */, - // "sourceMap": true, /* Generates corresponding '.map' file. */ - "outDir": "lib" /* Redirect output structure to the directory. */, - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + "target": "es5", + "module": "commonjs", + "lib": ["ES2015.Core"], + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "lib", /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */, - - /* Use tslib */ - "importHelpers": true, + "strict": true, /* Additional Checks */ - "noUnusedLocals": true /* Report errors on unused locals. */, - "noUnusedParameters": true /* Report errors on unused parameters. */, - "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, - "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "forceConsistentCasingInFileNames": true, + "importsNotUsedAsValues": "error", + "isolatedModules": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + "noUnusedLocals": true, + "noUnusedParameters": true, /* Module Resolution Options */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "esModuleInterop": true, + "moduleResolution": "node", "resolveJsonModule": true }, "include": ["src"],