Skip to content

Commit

Permalink
Add JSDoc based types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 16, 2021
1 parent a1af541 commit 7c5987c
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 20 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules/
coverage/
packages/*/*.d.ts
.DS_Store
*.log
node_modules
coverage
*.d.ts
yarn.lock
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@
},
"type": "module",
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"chalk": "^4.0.0",
"lerna": "^4.0.0",
"nlcst-test": "^3.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"unist-util-remove-position": "^4.0.0",
"xo": "^0.39.0"
},
"scripts": {
"postinstall": "lerna bootstrap --no-ci",
"build-workspace": "lerna run build",
"build-monorepo": "rimraf \"*.d.ts\" && tsc && type-coverage",
"build": "npm run build-workspace && npm run build-monorepo",
"todo": "remark -qfo && ",
"format": "prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test.js",
"test": "npm run format && npm run test-coverage"
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -45,5 +52,11 @@
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
14 changes: 11 additions & 3 deletions packages/retext-dutch/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
*/

import {unherit} from 'unherit'
import {ParseDutch} from 'parse-dutch'
// @ts-expect-error: untyped.
import {ParseDutch as Parser} from 'parse-dutch'

export {ParseDutch as Parser}
// Untyped.
// type-coverage:ignore-next-line
export {Parser}

/** @type {Plugin} */
export default function retextDutch() {
this.Parser = unherit(ParseDutch)
Object.assign(this, {Parser: unherit(Parser)})
}
15 changes: 14 additions & 1 deletion packages/retext-dutch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"parse-dutch": "^5.0.0",
"unherit": "^3.0.0"
"unherit": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/retext-dutch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
14 changes: 11 additions & 3 deletions packages/retext-english/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
*/

import {unherit} from 'unherit'
import {ParseEnglish} from 'parse-english'
// @ts-expect-error: untyped.
import {ParseEnglish as Parser} from 'parse-english'

export {ParseEnglish as Parser}
// Untyped.
// type-coverage:ignore-next-line
export {Parser}

/** @type {Plugin} */
export default function retextEnglish() {
this.Parser = unherit(ParseEnglish)
Object.assign(this, {Parser: unherit(Parser)})
}
15 changes: 14 additions & 1 deletion packages/retext-english/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"parse-english": "^5.0.0",
"unherit": "^3.0.0"
"unherit": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/retext-english/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
14 changes: 11 additions & 3 deletions packages/retext-latin/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
*/

import {unherit} from 'unherit'
import {ParseLatin} from 'parse-latin'
// @ts-expect-error: untyped.
import {ParseLatin as Parser} from 'parse-latin'

export {ParseLatin as Parser}
// Untyped.
// type-coverage:ignore-next-line
export {Parser}

/** @type {Plugin} */
export default function retextLatin() {
this.Parser = unherit(ParseLatin)
Object.assign(this, {Parser: unherit(Parser)})
}
15 changes: 14 additions & 1 deletion packages/retext-latin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"parse-latin": "^5.0.0",
"unherit": "^3.0.0"
"unherit": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/retext-latin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
14 changes: 12 additions & 2 deletions packages/retext-stringify/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
* @typedef {import('unist').Node} Node
*/

import {toString} from 'nlcst-to-string'

/** @type {Plugin} */
export default function retextStringify() {
this.Compiler = compiler
Object.assign(this, {Compiler})
}

function compiler(tree) {
/**
* @param {Node} tree
* @returns {string}
*/
function Compiler(tree) {
return toString(tree)
}
16 changes: 15 additions & 1 deletion packages/retext-stringify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,24 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"nlcst-to-string": "^3.0.0"
"@types/unist": "^2.0.0",
"nlcst-to-string": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/retext-stringify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
12 changes: 12 additions & 0 deletions packages/retext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"retext-latin": "^2.0.0",
"retext-stringify": "^2.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/retext/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
11 changes: 9 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ while (++index < parsers.length) {
eachParser(parsers[index])
}

/** @param {string} name */
function eachParser(name) {
test('retext-' + name, async (t) => {
t.plan(2)

const plugin = (await import('./packages/retext-' + name + '/index.js'))
.default
const fp = './packages/retext-' + name + '/index.js'

/** @type {import('./packages/retext/node_modules/unified').Plugin<[]>} */
// type-coverage:ignore-next-line
const plugin = (await import(fp)).default

const tree = unified().use(plugin).parse('Alfred')

Expand All @@ -60,6 +64,7 @@ function eachParser(name) {
test('.stringify', (t) => {
t.throws(
() => {
// @ts-expect-error: runtime.
retext().stringify(false)
},
/false/,
Expand All @@ -68,6 +73,7 @@ test('.stringify', (t) => {

t.throws(
() => {
// @ts-expect-error: runtime.
retext().stringify({})
},
/Expected node, got `\[object Object]`/,
Expand All @@ -76,6 +82,7 @@ test('.stringify', (t) => {

t.throws(
() => {
// @ts-expect-error: runtime.
retext().stringify()
},
/Expected node, got `undefined`/,
Expand Down
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"include": ["*.js"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"strict": true
}
}

0 comments on commit 7c5987c

Please sign in to comment.