Skip to content

Commit

Permalink
refactor: Convert to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed May 6, 2021
1 parent 6e8c9c0 commit 726f94a
Show file tree
Hide file tree
Showing 37 changed files with 4,514 additions and 4,190 deletions.
31 changes: 16 additions & 15 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
"extends": [
"eslint:recommended",
"plugin:jsdoc/recommended",
"plugin:jest/recommended",
"plugin:node/recommended",
"prettier"
],
"env": {
"node": true,
"es6": true
},
"env": { "node": true },
"rules": {
"array-callback-return": [
2,
{
"allowImplicit": true
}
],
"block-scoped-var": 2,
"no-lonely-if": 2,
"no-proto": 2,
"eqeqeq": [2, "smart"],
Expand Down Expand Up @@ -48,7 +43,6 @@
"no-useless-call": 2,
"no-use-before-define": [2, "nofunc"],
"no-void": 2,
"strict": 2,

"jsdoc/require-jsdoc": 0,
"jsdoc/check-param-names": 0,
Expand All @@ -62,17 +56,18 @@
"jsdoc/require-param-type": 0,
"jsdoc/require-returns-type": 0,
"jsdoc/require-param": 0,
"jsdoc/no-types": 2,
"jsdoc/valid-types": 2,

"node/no-unsupported-features/es-syntax": 0,
"node/no-missing-import": [
2,
{ "tryExtensions": [".js", ".json", ".node", ".ts"] }
]
"node/no-missing-import": [2, { "tryExtensions": [".js", ".json", ".ts"] }]
},
"settings": {
"jsdoc": {
"mode": "typescript"
"mode": "typescript",
"tagNamePreference": {
"category": "category"
}
}
},
"overrides": [
Expand Down Expand Up @@ -103,9 +98,15 @@
"@typescript-eslint/switch-exhaustiveness-check": 2,
"@typescript-eslint/prefer-nullish-coalescing": 2,

"@typescript-eslint/no-explicit-any": 1, // TODO
"@typescript-eslint/ban-ts-comment": 0, // TODO
"@typescript-eslint/no-non-null-assertion": 0 // TODO
"@typescript-eslint/no-explicit-any": 1 // TODO
}
},
{
"files": "*.spec.ts",
"extends": "plugin:jest/recommended",
"rules": {
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/ban-ts-comment": 0
}
}
]
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,3 @@ jobs:

- name: Run lint
run: npm run lint

- name: Test types
run: npm run test:types
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ node_modules
npm-debug.log
.DS_Store
/.netlify/
/coverage/
/docs/
/coverage
/docs
/lib
14 changes: 8 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<a href="https://coveralls.io/github/cheeriojs/cheerio">
<img src="https://img.shields.io/coveralls/github/cheeriojs/cheerio/main" alt="Coverage">
</a>
<a href="https://gitter.im/cheeriojs/cheerio">
<img src="https://img.shields.io/gitter/room/cheeriojs/cheerio?color=%2348b293" alt="Join the chat at https://gitter.im/cheeriojs/cheerio">
</a>
<a href="#backers">
<img src="https://img.shields.io/opencollective/backers/cheerio" alt="OpenCollective backers">
</a>
Expand Down Expand Up @@ -79,7 +76,12 @@ First you need to load in the HTML. This step in jQuery is implicit, since jQuer
This is the _preferred_ method:

```js
// ES6 or TypeScript:
import * as cheerio from 'cheerio';

// In other environments:
const cheerio = require('cheerio');

const $ = cheerio.load('<ul id="fruits">...</ul>');

$.html();
Expand Down Expand Up @@ -131,7 +133,7 @@ The options in the `xml` object are taken directly from [htmlparser2](https://gi
}
```

For a full list of options and their effects, see [this](https://github.com/fb55/DomHandler) and
For a full list of options and their effects, see [domhandler](https://github.com/fb55/DomHandler) and
[htmlparser2's options](https://github.com/fb55/htmlparser2/wiki/Parser-options).

Some users may wish to parse markup with the `htmlparser2` library, and
Expand All @@ -149,9 +151,9 @@ structure as its first argument. Users may install `htmlparser2`, use it to
parse input, and pass the result to `load`:

```js
// Usage as of htmlparser2 version 3:
// Usage as of htmlparser2 version 6:
const htmlparser2 = require('htmlparser2');
const dom = htmlparser2.parseDOM(document, options);
const dom = htmlparser2.parseDocument(document, options);

const $ = cheerio.load(dom);
```
Expand Down
Loading

3 comments on commit 726f94a

@yorkie
Copy link

@yorkie yorkie commented on 726f94a May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fb55 This commit is not working with TypeScript < 4.1.0 because it requires Template Literal Types.

@fb55
Copy link
Member Author

@fb55 fb55 commented on 726f94a May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yorkie That is true — I honestly don't know how fragmented the TS ecosystem is, and just assumed this would be fine.

@yorkie
Copy link

@yorkie yorkie commented on 726f94a May 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I used ^cheerio-rc.3, it upgrades the version from cheerio-rc.8 to cheerio-rc.9, and the later causes a tsc compiler error. In my opinion, both a major version and non-latest version tag make sense.

Please sign in to comment.