Skip to content

Commit

Permalink
Merge branch 'main' into unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
5saviahv authored Jan 5, 2021
2 parents aca422b + bb6cb38 commit 2e3ffaa
Show file tree
Hide file tree
Showing 29 changed files with 196 additions and 61 deletions.
14 changes: 12 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"node": true
},
"plugins": ["jsdoc"],
"extends": ["eslint:recommended", "plugin:jsdoc/recommended", "prettier"],
"extends": [
"eslint:recommended",
"plugin:jsdoc/recommended",
"plugin:jest/recommended",
"plugin:node/recommended",
"prettier"
],
"globals": { "Set": true, "Symbol": true },
"rules": {
"array-callback-return": [
Expand Down Expand Up @@ -35,6 +41,7 @@
"no-use-before-define": [2, "nofunc"],
"no-void": 2,
"yoda": 2,
"strict": 2,

"jsdoc/require-jsdoc": 0,
"jsdoc/check-param-names": 2,
Expand All @@ -47,7 +54,10 @@
"jsdoc/require-param-name": 2,
"jsdoc/require-param-type": 2,
"jsdoc/require-param": 2,
"jsdoc/valid-types": 2
"jsdoc/valid-types": 2,

"node/no-unsupported-features/es-builtins": 0, // TODO
"node/shebang": 0
},
"settings": {
"jsdoc": {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
'use strict';

var Suites = require('./suite');
var suites = new Suites();

var regexIdx = process.argv.indexOf('--regex') + 1;
if (regexIdx > 0) {
if (regexIdx === process.argv.length) {
console.error('Error: the "--regex" option requires a value');
process.exit(1);
throw new Error('Error: the "--regex" option requires a value');
}
suites.filter(process.argv[regexIdx]);
}
Expand Down
1 change: 1 addition & 0 deletions benchmark/suite.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var fs = require('fs');
var path = require('path');

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* @module cheerio
* @borrows static.load as load
Expand Down
1 change: 1 addition & 0 deletions lib/api/attributes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* Methods for getting and modifying attributes.
*
Expand Down
1 change: 1 addition & 0 deletions lib/api/css.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/** @module cheerio/css */

var domEach = require('../utils').domEach;
Expand Down
1 change: 1 addition & 0 deletions lib/api/forms.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/** @module cheerio/forms */

// https://github.com/jquery/jquery/blob/2.1.3/src/manipulation/var/rcheckableType.js
Expand Down
1 change: 1 addition & 0 deletions lib/api/manipulation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* Methods for modifying the DOM structure.
*
Expand Down
1 change: 1 addition & 0 deletions lib/api/traversing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* Methods for traversing the DOM structure.
*
Expand Down
1 change: 1 addition & 0 deletions lib/cheerio.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
Module dependencies
*/
Expand Down
1 change: 1 addition & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/** Cheerio default options. */
exports.default = {
xml: false,
Expand Down
1 change: 1 addition & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/*
Module Dependencies
*/
Expand Down
1 change: 1 addition & 0 deletions lib/parsers/htmlparser2.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
'use strict';
exports.parse = require('htmlparser2').parseDocument;
exports.render = require('dom-serializer').default;
1 change: 1 addition & 0 deletions lib/parsers/parse5.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var parse5 = require('parse5');
var htmlparser2Adapter = require('parse5-htmlparser2-tree-adapter');

Expand Down
3 changes: 2 additions & 1 deletion lib/static.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* @module cheerio/static
* @ignore
Expand Down Expand Up @@ -117,7 +118,7 @@ exports.html = function (dom, options) {
options = Object.assign(
{},
defaultOptions,
this._options,
this ? this._options : {},
flattenOptions(options || {})
);

Expand Down
1 change: 1 addition & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var htmlparser2 = require('htmlparser2');
var domhandler = require('domhandler');

Expand Down
124 changes: 121 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@
"benchmark": "^2.1.4",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jsdoc": "^30.7.13",
"eslint-plugin-node": "^11.1.0",
"husky": "^4.3.6",
"jest": "^26.6.3",
"jquery": "^3.5.1",
"jsdoc": "^3.6.6",
"jsdom": "^16.4.0",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"prettier-plugin-jsdoc": "^0.2.12",
"prettier-plugin-jsdoc": "^0.2.13",
"tsd": "^0.14.0"
},
"scripts": {
Expand All @@ -68,6 +70,7 @@
"format:prettier:raw": "prettier \"**/*.{js,ts,md,json,yml}\" --ignore-path .gitignore",
"build:docs": "jsdoc --configure jsdoc-config.json",
"benchmark": "node benchmark/benchmark.js --regex \"^(?!.*highmem)\"",
"bench": "npm run benchmark",
"pre-commit": "lint-staged"
},
"prettier": {
Expand Down
1 change: 1 addition & 0 deletions test/__fixtures__/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
exports.fruits = [
'<ul id="fruits">',
'<li class="apple">Apple</li>',
Expand Down
27 changes: 14 additions & 13 deletions test/api/attributes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var cheerio = require('../..');
var fruits = require('../__fixtures__/fixtures').fruits;
var vegetables = require('../__fixtures__/fixtures').vegetables;
Expand Down Expand Up @@ -33,13 +34,13 @@ describe('$(...)', function () {
expect(attr).toBe('autofocus');
});

it('(key, value) : should set attr', function () {
it('(key, value) : should set one attr', function () {
var $pear = $('.pear').attr('id', 'pear');
expect($('#pear')).toHaveLength(1);
expect($pear).toBeInstanceOf($);
});

it('(key, value) : should set attr', function () {
it('(key, value) : should set multiple attr', function () {
var $el = cheerio('<div></div> <div></div>').attr('class', 'pear');

expect($el[0].attribs['class']).toBe('pear');
Expand Down Expand Up @@ -539,26 +540,26 @@ describe('$(...)', function () {
});

describe('.hasClass', function () {
function test(attr) {
function withClass(attr) {
return cheerio('<div class="' + attr + '"></div>');
}

it('(valid class) : should return true', function () {
var cls = $('.apple').hasClass('apple');
expect(cls).toBe(true);

expect(test('foo').hasClass('foo')).toBe(true);
expect(test('foo bar').hasClass('foo')).toBe(true);
expect(test('bar foo').hasClass('foo')).toBe(true);
expect(test('bar foo bar').hasClass('foo')).toBe(true);
expect(withClass('foo').hasClass('foo')).toBe(true);
expect(withClass('foo bar').hasClass('foo')).toBe(true);
expect(withClass('bar foo').hasClass('foo')).toBe(true);
expect(withClass('bar foo bar').hasClass('foo')).toBe(true);
});

it('(invalid class) : should return false', function () {
var cls = $('#fruits').hasClass('fruits');
expect(cls).toBe(false);
expect(test('foo-bar').hasClass('foo')).toBe(false);
expect(test('foo-bar').hasClass('foo')).toBe(false);
expect(test('foo-bar').hasClass('foo-ba')).toBe(false);
expect(withClass('foo-bar').hasClass('foo')).toBe(false);
expect(withClass('foo-bar').hasClass('foo')).toBe(false);
expect(withClass('foo-bar').hasClass('foo-ba')).toBe(false);
});

it('should check multiple classes', function () {
Expand All @@ -573,9 +574,9 @@ describe('$(...)', function () {
});

it('(empty string argument) : should return false', function () {
expect(test('foo').hasClass('')).toBe(false);
expect(test('foo bar').hasClass('')).toBe(false);
expect(test('foo bar').removeClass('foo').hasClass('')).toBe(false);
expect(withClass('foo').hasClass('')).toBe(false);
expect(withClass('foo bar').hasClass('')).toBe(false);
expect(withClass('foo bar').removeClass('foo').hasClass('')).toBe(false);
});
});

Expand Down
Loading

0 comments on commit 2e3ffaa

Please sign in to comment.