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 18, 2021
1 parent c636382 commit 375d791
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
coverage/
.DS_Store
*.d.ts
*.log
yarn.lock
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* @typedef Options
* Configuration.
* @property {string[]} [ignore]
* Phrases *not* to warn about.
*/

import {search} from 'nlcst-search'
import {toString} from 'nlcst-to-string'
import {findBefore} from 'unist-util-find-before'
Expand All @@ -8,6 +15,11 @@ const source = 'retext-passive'

const verbs = new Set(['am', 'are', 'were', 'being', 'is', 'been', 'was', 'be'])

/**
* Plugin to check for passive voice.
*
* @type {import('unified').Plugin<[Options?]>}
*/
export default function retextPassive(options = {}) {
const ignore = options.ignore || []
const phrases =
Expand Down
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,39 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js",
"list.d.ts",
"list.js"
],
"dependencies": {
"nlcst-search": "^3.0.0",
"nlcst-to-string": "^3.0.0",
"unified": "^10.0.0",
"unist-util-find-before": "^3.0.0",
"unist-util-position": "^4.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"retext": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.39.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && 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 @@ -65,5 +74,11 @@
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
17 changes: 9 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ test('retext-passive', (t) => {

retext()
.use(retextPassive)
.process(doc, (error, file) => {
.process(doc)
.then((file) => {
t.deepEqual(
[error].concat(file.messages.map((d) => String(d))),
file.messages.map((d) => String(d)),
[
null,
'1:8-1:16: Don’t use the passive voice',
'1:37-1:40: Don’t use the passive voice'
],
Expand All @@ -44,15 +44,16 @@ test('retext-passive', (t) => {
},
'should emit messages'
)
})
}, t.ifErr)

retext()
.use(retextPassive, {ignore: ['fed']})
.process(doc, (error, file) => {
.process(doc)
.then((file) => {
t.deepEqual(
[error, file.messages.map((d) => String(d))],
[null, ['1:8-1:16: Don’t use the passive voice']],
file.messages.map((d) => String(d)),
['1:8-1:16: Don’t use the passive voice'],
'should `ignore`'
)
})
}, t.ifErr)
})
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 375d791

Please sign in to comment.