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 Aug 12, 2021
1 parent 5c215ec commit 1a1e7cc
Show file tree
Hide file tree
Showing 296 changed files with 4,649 additions and 1,499 deletions.
74 changes: 74 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,80 @@
coverage/
node_modules/
.DS_Store
/packages/remark-lint/*.d.ts
/packages/remark-lint-blockquote-indentation/*.d.ts
/packages/remark-lint-checkbox-character-style/*.d.ts
/packages/remark-lint-checkbox-content-indent/*.d.ts
/packages/remark-lint-code-block-style/*.d.ts
/packages/remark-lint-definition-case/*.d.ts
/packages/remark-lint-definition-spacing/*.d.ts
/packages/remark-lint-emphasis-marker/*.d.ts
/packages/remark-lint-fenced-code-flag/*.d.ts
/packages/remark-lint-fenced-code-marker/*.d.ts
/packages/remark-lint-file-extension/*.d.ts
/packages/remark-lint-final-definition/*.d.ts
/packages/remark-lint-final-newline/*.d.ts
/packages/remark-lint-first-heading-level/*.d.ts
/packages/remark-lint-hard-break-spaces/*.d.ts
/packages/remark-lint-heading-increment/*.d.ts
/packages/remark-lint-heading-style/*.d.ts
/packages/remark-lint-linebreak-style/*.d.ts
/packages/remark-lint-link-title-style/*.d.ts
/packages/remark-lint-list-item-bullet-indent/*.d.ts
/packages/remark-lint-list-item-content-indent/*.d.ts
/packages/remark-lint-list-item-indent/*.d.ts
/packages/remark-lint-list-item-spacing/*.d.ts
/packages/remark-lint-maximum-heading-length/*.d.ts
/packages/remark-lint-maximum-line-length/*.d.ts
/packages/remark-lint-no-auto-link-without-protocol/*.d.ts
/packages/remark-lint-no-blockquote-without-marker/*.d.ts
/packages/remark-lint-no-consecutive-blank-lines/*.d.ts
/packages/remark-lint-no-duplicate-defined-urls/*.d.ts
/packages/remark-lint-no-duplicate-definitions/*.d.ts
/packages/remark-lint-no-duplicate-headings/*.d.ts
/packages/remark-lint-no-duplicate-headings-in-section/*.d.ts
/packages/remark-lint-no-emphasis-as-heading/*.d.ts
/packages/remark-lint-no-empty-url/*.d.ts
/packages/remark-lint-no-file-name-articles/*.d.ts
/packages/remark-lint-no-file-name-consecutive-dashes/*.d.ts
/packages/remark-lint-no-file-name-irregular-characters/*.d.ts
/packages/remark-lint-no-file-name-mixed-case/*.d.ts
/packages/remark-lint-no-file-name-outer-dashes/*.d.ts
/packages/remark-lint-no-heading-content-indent/*.d.ts
/packages/remark-lint-no-heading-indent/*.d.ts
/packages/remark-lint-no-heading-like-paragraph/*.d.ts
/packages/remark-lint-no-heading-punctuation/*.d.ts
/packages/remark-lint-no-html/*.d.ts
/packages/remark-lint-no-inline-padding/*.d.ts
/packages/remark-lint-no-literal-urls/*.d.ts
/packages/remark-lint-no-missing-blank-lines/*.d.ts
/packages/remark-lint-no-multiple-toplevel-headings/*.d.ts
/packages/remark-lint-no-paragraph-content-indent/*.d.ts
/packages/remark-lint-no-reference-like-url/*.d.ts
/packages/remark-lint-no-shell-dollars/*.d.ts
/packages/remark-lint-no-shortcut-reference-image/*.d.ts
/packages/remark-lint-no-shortcut-reference-link/*.d.ts
/packages/remark-lint-no-table-indentation/*.d.ts
/packages/remark-lint-no-tabs/*.d.ts
/packages/remark-lint-no-undefined-references/*.d.ts
/packages/remark-lint-no-unneeded-full-reference-image/*.d.ts
/packages/remark-lint-no-unneeded-full-reference-link/*.d.ts
/packages/remark-lint-no-unused-definitions/*.d.ts
/packages/remark-lint-ordered-list-marker-style/*.d.ts
/packages/remark-lint-ordered-list-marker-value/*.d.ts
/packages/remark-lint-rule-style/*.d.ts
/packages/remark-lint-strikethrough-marker/*.d.ts
/packages/remark-lint-strong-marker/*.d.ts
/packages/remark-lint-table-cell-padding/*.d.ts
/packages/remark-lint-table-pipe-alignment/*.d.ts
/packages/remark-lint-table-pipes/*.d.ts
/packages/remark-lint-unordered-list-marker-style/*.d.ts
/packages/remark-preset-lint-consistent/*.d.ts
/packages/remark-preset-lint-markdown-style-guide/*.d.ts
/packages/remark-preset-lint-recommended/*.d.ts
/packages/unified-lint-rule/lib/*.d.ts
/script/**/*.d.ts
/*.d.ts
*.log
package-lock.json
yarn.lock
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
],
"type": "module",
"devDependencies": {
"@types/mdast": "^3.0.0",
"@types/parse-author": "^2.0.0",
"@types/pluralize": "^0.0.29",
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"comment-parser": "^1.0.0",
"lerna": "^4.0.0",
Expand All @@ -46,22 +50,27 @@
"remark-github": "^11.0.0",
"remark-toc": "^8.0.0",
"remark-validate-links": "^11.0.0",
"rimraf": "^3.0.0",
"strip-indent": "^4.0.0",
"tape": "^5.0.0",
"to-vfile": "^7.0.0",
"type-coverage": "^2.0.0",
"type-fest": "^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-packages": "node script/build-presets && node script/build-rules",
"build-workspace": "lerna run build",
"build-monorepo": "rimraf \"test.d.ts\" \"script/**/*.d.ts\" && tsc && type-coverage",
"build": "npm run build-packages && npm run build-workspace && npm run build-monorepo",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"generate:presets": "node script/build-presets",
"generate:rules": "node script/build-rules",
"generate": "npm run generate:presets && npm run generate:rules",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test": "npm run generate && npm run format && npm run test-coverage"
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -88,5 +97,11 @@
}
}
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
67 changes: 37 additions & 30 deletions packages/remark-lint-blockquote-indentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
* 9:3: Add 1 space between block quote and content
*/

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Blockquote} Blockquote
* @typedef {'consistent'|number} Options
*/

import {lintRule} from 'unified-lint-rule'
import plural from 'pluralize'
import {visit} from 'unist-util-visit'
Expand All @@ -56,41 +62,42 @@ import {generated} from 'unist-util-generated'

const remarkLintBlockquoteIndentation = lintRule(
'remark-lint:blockquote-indentation',
blockquoteIndentation
)

export default remarkLintBlockquoteIndentation

function blockquoteIndentation(tree, file, option) {
let preferred = typeof option === 'number' ? option : null

visit(tree, 'blockquote', (node) => {
if (generated(node) || node.children.length === 0) {
return
}
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
visit(tree, 'blockquote', (node) => {
if (generated(node) || node.children.length === 0) {
return
}

if (preferred) {
const diff = preferred - check(node)
if (option === 'consistent') {
option = check(node)
} else {
const diff = option - check(node)

if (diff !== 0) {
const abs = Math.abs(diff)
if (diff !== 0) {
const abs = Math.abs(diff)

file.message(
(diff > 0 ? 'Add' : 'Remove') +
' ' +
abs +
' ' +
plural('space', abs) +
' between block quote and content',
pointStart(node.children[0])
)
file.message(
(diff > 0 ? 'Add' : 'Remove') +
' ' +
abs +
' ' +
plural('space', abs) +
' between block quote and content',
pointStart(node.children[0])
)
}
}
} else {
preferred = check(node)
}
})
}
})
}
)

export default remarkLintBlockquoteIndentation

/**
* @param {Blockquote} node
* @returns {number}
*/
function check(node) {
return pointStart(node.children[0]).column - pointStart(node).column
}
15 changes: 14 additions & 1 deletion packages/remark-lint-blockquote-indentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/mdast": "^3.0.0",
"pluralize": "^8.0.0",
"unified": "^10.0.0",
"unified-lint-rule": "^1.0.0",
"unist-util-generated": "^2.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^4.0.0"
},
"xo": false
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
8 changes: 8 additions & 0 deletions packages/remark-lint-blockquote-indentation/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ Paragraph.

## Install

This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.

[npm][]:

```sh
npm install remark-lint-blockquote-indentation
```

This package exports no identifiers.
The default export is `remarkLintBlockquoteIndentation`.

## Use

You probably want to use it on the CLI through a config file:
Expand Down Expand Up @@ -175,6 +181,8 @@ abide by its terms.

[chat]: https://github.com/remarkjs/remark/discussions

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[npm]: https://docs.npmjs.com/cli/install

[health]: https://github.com/remarkjs/.github
Expand Down
4 changes: 4 additions & 0 deletions packages/remark-lint-blockquote-indentation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
Loading

0 comments on commit 1a1e7cc

Please sign in to comment.