Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Convert to TypeScript #1816

Merged
merged 3 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 67 additions & 30 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,76 +1,113 @@
{
"env": {
"node": true
},
"plugins": ["jsdoc"],
"extends": [
"eslint:recommended",
"plugin:jsdoc/recommended",
"plugin:jest/recommended",
"plugin:node/recommended",
"prettier"
],
"globals": { "Set": true, "Symbol": true },
"env": { "node": true },
"rules": {
"array-callback-return": [
2,
{
"allowImplicit": true
}
],
"block-scoped-var": 2,
"eqeqeq": [
2,
"always",
{
"null": "ignore"
}
],
"no-lonely-if": 2,
"no-proto": 2,
"curly": [2, "multi-line"],
"eqeqeq": [2, "smart"],
"no-caller": 2,
"dot-notation": 2,
"no-var": 2,
"prefer-const": 2,
"prefer-arrow-callback": [2, { "allowNamedFunctions": true }],
"arrow-body-style": [2, "as-needed"],
"object-shorthand": 2,
"prefer-template": 2,
"one-var": [2, "never"],
"prefer-destructuring": [2, { "object": true }],
"capitalized-comments": 2,
"multiline-comment-style": [2, "starred-block"],
"spaced-comment": 2,
"yoda": [2, "never"],
"curly": [2, "multi-line"],

"no-else-return": [
2,
{
"allowElseIf": false
}
],
"no-shadow": 2,
"no-unused-expressions": 2,
"no-useless-call": 2,
"no-use-before-define": [2, "nofunc"],
"no-void": 2,
"yoda": 2,
"strict": 2,

"jsdoc/require-jsdoc": 0,
"jsdoc/check-param-names": 2,
"jsdoc/check-param-names": 0,
"jsdoc/check-tag-names": 2,
"jsdoc/check-types": 2,
"jsdoc/newline-after-description": 2,
"jsdoc/require-description-complete-sentence": 2,
"jsdoc/require-hyphen-before-param-description": 2,
"jsdoc/require-param-description": 2,
"jsdoc/require-param-name": 2,
"jsdoc/require-param-type": 2,
"jsdoc/require-param": 2,
"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-builtins": 0, // TODO
"node/shebang": 0
"node/no-unsupported-features/es-syntax": 0,
"node/no-missing-import": [2, { "tryExtensions": [".js", ".json", ".ts"] }]
},
"settings": {
"jsdoc": {
"additionalTagNames": {
"customTags": ["hideconstructor"]
"mode": "typescript",
"tagNamePreference": {
"category": "category"
}
}
},
"overrides": [
{
"files": "*.ts",
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parserOptions": {
"sourceType": "module",
"project": "./tsconfig.eslint.json"
},
"preferredTypes": {
"node": "Node",
"nodewithchildren": "NodeWithChildren",
"element": "Element",
"cheerio": "Cheerio"
"rules": {
"@typescript-eslint/prefer-for-of": 0,
"@typescript-eslint/member-ordering": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/no-use-before-define": [2, { "functions": false }],
"@typescript-eslint/consistent-type-definitions": [2, "interface"],
"@typescript-eslint/prefer-function-type": 2,
"@typescript-eslint/no-unnecessary-type-arguments": 2,
"@typescript-eslint/prefer-string-starts-ends-with": 2,
"@typescript-eslint/prefer-readonly": 2,
"@typescript-eslint/prefer-includes": 2,
"@typescript-eslint/no-unnecessary-condition": 0, // TODO
"@typescript-eslint/switch-exhaustiveness-check": 2,
"@typescript-eslint/prefer-nullish-coalescing": 2,

"@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
}
}
}
]
}
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