Skip to content

Commit

Permalink
Refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 16, 2023
1 parent 0beb67b commit db9755f
Show file tree
Hide file tree
Showing 41 changed files with 234 additions and 89 deletions.
8 changes: 6 additions & 2 deletions packages/remark-lint-blockquote-indentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@
*/

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

/**
* @typedef {'consistent' | number} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
20 changes: 13 additions & 7 deletions packages/remark-lint-checkbox-character-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@

/**
* @typedef {import('mdast').Root} Root
*
*/

/**
* @typedef Styles
* @property {'x'|'X'|'consistent'} [checked='consistent']
* @property {' '|'\x09'|'consistent'} [unchecked='consistent']
*
* @typedef {'consistent'|Styles} Options
* Styles.
* @property {'x' | 'X' | 'consistent'} [checked='consistent']
* Preferred style to use for checked checkboxes (default: `'consistent'`).
* @property {' ' | '\t' | 'consistent'} [unchecked='consistent']
* Preferred style to use for unchecked checkboxes (default: `'consistent'`).
*
* @typedef {'consistent' | Styles} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand All @@ -109,9 +115,9 @@ const remarkLintCheckboxCharacterStyle = lintRule(
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
const value = String(file)
/** @type {'x'|'X'|'consistent'} */
/** @type {'x' | 'X' | 'consistent'} */
let checked = 'consistent'
/** @type {' '|'\x09'|'consistent'} */
/** @type {' ' | '\x09' | 'consistent'} */
let unchecked = 'consistent'

if (typeof option === 'object') {
Expand Down
9 changes: 7 additions & 2 deletions packages/remark-lint-code-block-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@

/**
* @typedef {import('mdast').Root} Root
* @typedef {'fenced'|'indented'} Style
* @typedef {'consistent'|Style} Options
*/

/**
* @typedef {'fenced' | 'indented'} Style
* Styles.
* @typedef {'consistent' | Style} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
9 changes: 7 additions & 2 deletions packages/remark-lint-emphasis-marker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@

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

/**
* @typedef {'*' | '_'} Marker
* Styles.
* @typedef {'consistent' | Marker} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
11 changes: 9 additions & 2 deletions packages/remark-lint-fenced-code-flag/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,21 @@

/**
* @typedef {import('mdast').Root} Root
*
*/

/**
* @typedef {Array<string>} Flags
* Language flags.
*
* @typedef FlagMap
* Configuration.
* @property {Flags} [flags]
* Language flags.
* @property {boolean} [allowEmpty=false]
* Allow language flags to be omitted (default: `false`).
*
* @typedef {Flags|FlagMap} Options
* @typedef {Flags | FlagMap} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
9 changes: 7 additions & 2 deletions packages/remark-lint-fenced-code-marker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@

/**
* @typedef {import('mdast').Root} Root
* @typedef {'~'|'`'} Marker
* @typedef {'consistent'|Marker} Options
*/

/**
* @typedef {'~' | '`'} Marker
* Styles.
* @typedef {'consistent' | Marker} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
4 changes: 4 additions & 0 deletions packages/remark-lint-file-extension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@

/**
* @typedef {import('mdast').Root} Root
*/

/**
* @typedef {string} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
16 changes: 11 additions & 5 deletions packages/remark-lint-first-heading-level/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@
*/

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Heading} Heading
* @typedef {import('mdast').HTML} HTML
* @typedef {import('mdast').Heading['depth']} Depth
* @typedef {import('mdast').Root} Root
*/

/**
* @typedef {Heading['depth']} Depth
* Styles.
* @typedef {Depth} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand All @@ -128,7 +134,7 @@ const remarkLintFirstHeadingLevel = lintRule(
(tree, file, option = 1) => {
visit(tree, (node) => {
if (!generated(node)) {
/** @type {Depth|undefined} */
/** @type {Depth | undefined} */
let rank

if (node.type === 'heading') {
Expand All @@ -153,10 +159,10 @@ export default remarkLintFirstHeadingLevel

/**
* @param {HTML} node
* @returns {Depth|undefined}
* @returns {Depth | undefined}
*/
function infer(node) {
const results = node.value.match(re)
// @ts-expect-error: can be castes fine.
// @ts-expect-error: can be casted fine.
return results ? Number(results[1]) : undefined
}
6 changes: 5 additions & 1 deletion packages/remark-lint-heading-increment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@
*/

/**
* @typedef {import('mdast').Heading} Heading
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Heading['depth']} Depth
*/

/**
* @typedef {Heading['depth']} Depth
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
9 changes: 7 additions & 2 deletions packages/remark-lint-heading-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@

/**
* @typedef {import('mdast').Root} Root
* @typedef {'atx'|'atx-closed'|'setext'} Type
* @typedef {'consistent'|Type} Options
*/

/**
* @typedef {'atx' | 'atx-closed' | 'setext'} Type
* Styles.
* @typedef {'consistent' | Type} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
9 changes: 7 additions & 2 deletions packages/remark-lint-linebreak-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@

/**
* @typedef {import('mdast').Root} Root
* @typedef {'unix'|'windows'} Type
* @typedef {'consistent'|Type} Options
*/

/**
* @typedef {'unix' | 'windows'} Type
* Styles.
* @typedef {'consistent' | Type} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
9 changes: 7 additions & 2 deletions packages/remark-lint-link-title-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@

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

/**
* @typedef {'"' | '\'' | '()'} Marker
* Styles.
* @typedef {'consistent' | Marker} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-lint-list-item-content-indent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const remarkLintListItemContentIndent = lintRule(

visit(tree, 'listItem', (node) => {
let index = -1
/** @type {number|undefined} */
/** @type {number | undefined} */
let style

while (++index < node.children.length) {
Expand Down
6 changes: 5 additions & 1 deletion packages/remark-lint-list-item-indent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@

/**
* @typedef {import('mdast').Root} Root
* @typedef {'tab-size'|'space'|'mixed'} Options
*/

/**
* @typedef {'tab-size' | 'space' | 'mixed'} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
4 changes: 3 additions & 1 deletion packages/remark-lint-list-item-spacing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@
* @typedef {import('mdast').ListItem} ListItem
*
* @typedef Options
* @property {boolean} [checkBlanks=false]
* Options.
* @property {boolean | null | undefined} [checkBlanks=false]
* Adhere to CommonMark looseness instead of markdown-style-guide preference.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
4 changes: 4 additions & 0 deletions packages/remark-lint-maximum-heading-length/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@

/**
* @typedef {import('mdast').Root} Root
*/

/**
* @typedef {number} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
9 changes: 5 additions & 4 deletions packages/remark-lint-maximum-line-length/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Parent} Parent
*/

/**
* @typedef {number} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down Expand Up @@ -160,9 +163,7 @@ const remarkLintMaximumLineLength = lintRule(
// the wrap.
// However, when they do, and there’s whitespace after it, they are not
// allowed.
visit(tree, (node, pos, parent_) => {
const parent = /** @type {Parent} */ (parent_)

visit(tree, (node, pos, parent) => {
if (
(node.type === 'link' ||
node.type === 'image' ||
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-lint-no-consecutive-blank-lines/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const remarkLintNoConsecutiveBlankLines = lintRule(
*
* @param {Point} start
* @param {Point} end
* @param {0|1|2} max
* @param {0 | 1 | 2} max
*/
function compare(start, end, max) {
const diff = end.line - start.line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
*/

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Heading} Heading
* @typedef {import('mdast').Root} Root
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@

/**
* @typedef {import('mdast').Root} Root
*
* @typedef {RegExp|string} Options
*/

/**
* @typedef {RegExp | string} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
4 changes: 4 additions & 0 deletions packages/remark-lint-no-heading-punctuation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@

/**
* @typedef {import('mdast').Root} Root
*/

/**
* @typedef {string} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
8 changes: 6 additions & 2 deletions packages/remark-lint-no-missing-blank-lines/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@

/**
* @typedef {import('mdast').Root} Root
*
*/

/**
* @typedef Options
* @property {boolean} [exceptTightLists=false]
* Options.
* @property {boolean | null | undefined} [exceptTightLists=false]
* Allow tight list items.
*/

import {lintRule} from 'unified-lint-rule'
Expand Down
6 changes: 5 additions & 1 deletion packages/remark-lint-no-multiple-toplevel-headings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Heading} Heading
*/

/**
* @typedef {Heading['depth']} Options
* Options.
*/

import {lintRule} from 'unified-lint-rule'
Expand All @@ -61,7 +65,7 @@ const remarkLintNoMultipleToplevelHeadings = lintRule(
},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 1) => {
/** @type {string|undefined} */
/** @type {string | undefined} */
let duplicate

visit(tree, 'heading', (node) => {
Expand Down
Loading

0 comments on commit db9755f

Please sign in to comment.