Skip to content
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
1 change: 1 addition & 0 deletions packages/remark-lint/src/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import yamlComments from './rules/yaml/index.mjs';
/**
* @typedef {Object} Options
* @property {Array<string>} releasedVersions The released versions, for validating the YAML
* @property {Record<string, string>} typeMap The type map
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,22 @@ const testCases = [
input: 'This is {invalid}.',
expected: ['Invalid type reference: {invalid}'],
},
{
name: 'custom references',
input: 'This is a {custom} type.',
expected: [],
options: {
typeMap: {
custom: '...',
},
},
},
];

describe('invalid-type-reference', () => {
for (const { name, input, expected } of testCases) {
it(name, () => testRule(invalidTypeReference, input, expected));
for (const { name, input, expected, options } of testCases) {
it(name, () =>
testRule(invalidTypeReference, input, expected, {}, options)
);
}
});
10 changes: 8 additions & 2 deletions packages/remark-lint/src/rules/__tests__/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { unified } from 'unified';
/**
* Tests a markdown rule against a markdown string
*/
export const testRule = (rule, markdown, expected, vfileOptions = {}) => {
export const testRule = (
rule,
markdown,
expected,
vfileOptions = {},
ruleOptions = {}
) => {
// Parse the markdown once
const tree = unified().use(remarkParse).parse(markdown);

Expand All @@ -19,7 +25,7 @@ export const testRule = (rule, markdown, expected, vfileOptions = {}) => {
};

// Execute the rule
rule()(tree, vfile, () => {});
rule(ruleOptions)(tree, vfile, () => {});

// Assert that the expected messages were reported
assert.deepEqual(
Expand Down
6 changes: 3 additions & 3 deletions packages/remark-lint/src/rules/invalid-type-reference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const REPLACE_RE = /\s*\|\s*/g;

/**
* Ensures that all type references are valid
* @type {import('unified-lint-rule').Rule}
* @type {import('unified-lint-rule').Rule<, import('../api.mjs').Options>}
*/
const invalidTypeReference = (tree, vfile) => {
const invalidTypeReference = (tree, vfile, { typeMap = {} }) => {
visit(tree, createQueries.UNIST.isTextWithType, node => {
const types = node.value.match(createQueries.QUERIES.normalizeTypes);

Expand All @@ -36,7 +36,7 @@ const invalidTypeReference = (tree, vfile) => {
node.value = node.value.replace(type, normalized);
}

if (transformTypeToReferenceLink(type) === type) {
if (transformTypeToReferenceLink(type, typeMap) === type) {
vfile.message(`Invalid type reference: ${type}`, node);
}
});
Expand Down
58 changes: 51 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading