Skip to content
Open
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
3 changes: 3 additions & 0 deletions package.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the newly released Bun 1.3 now enforces strict dependencies in package.json. If we use transitive dependencies like @types/unist, @types/mdast, or semver, it throws errors:

image image

So, I've added @types/unist, @types/mdast, and semver to the dev dependencies.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"devDependencies": {
"@eslint/js": "^9.36.0",
"@eslint/json": "^0.13.2",
"@types/mdast": "^4.0.4",
"@types/unist": "^3.0.3",
"c8": "^10.1.3",
"dedent": "^1.5.3",
"eslint": "^9.36.0",
Expand All @@ -84,6 +86,7 @@
"lint-staged": "^15.2.9",
"mocha": "^11.6.0",
"prettier": "^3.3.3",
"semver": "^7.7.3",
"typescript": "^5.9.2",
"yorkie": "^2.0.0"
},
Expand Down
7 changes: 6 additions & 1 deletion src/rules/no-html.js
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule already supports CR line endings, so I only refactored the code.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
* @author Nicholas C. Zakas
*/

//-----------------------------------------------------------------------------
// Imports
//-----------------------------------------------------------------------------

import { lineEndingPattern } from "../util.js";

//-----------------------------------------------------------------------------
// Type Definitions
//-----------------------------------------------------------------------------
Expand All @@ -20,7 +26,6 @@

const htmlTagPattern =
/<(?<tagName>[a-z0-9]+(?:-[a-z0-9]+)*)(?:\s(?:[^>"']|"[^"]*"|'[^']*')*)?>/giu;
const lineEndingPattern = /\r\n?|\n/u;

//-----------------------------------------------------------------------------
// Rule Definition
Expand Down
16 changes: 4 additions & 12 deletions src/rules/no-reference-like-urls.js
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Motivated by #525, I've simplified the regex a bit.

Since imageBang and title can be retrieved directly from the node's information, I've updated the code to access them directly from the nodes.

(This rule already supports CR line endings, so I only refactored the code.)

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { normalizeIdentifier } from "micromark-util-normalize-identifier";

/** Pattern to match both inline links: `[text](url)` and images: `![alt](url)`, with optional title */
const linkOrImagePattern =
/(?<imageBang>!)?\[(?<label>(?:\\.|[^()\\]|\([\s\S]*\))*?)\]\((?<destination>[ \t]*(?:\r\n?|\n)?(?<![ \t])[ \t]*(?:<[^>]*>|[^ \t()]+))(?:[ \t]*(?:\r\n?|\n)?(?<![ \t])[ \t]*(?<title>"[^"]*"|'[^']*'|\([^)]*\)))?[ \t]*(?:\r\n?|\n)?(?<![ \t])[ \t]*\)$/u;
/\[(?<label>(?:\\.|[^()\\]|\([\s\S]*\))*?)\]\((?<destination>[ \t]*\r?\n?(?<![ \t])[ \t]*(?:<[^>]*>|[^ \t()]+))(?:[ \t]*\r?\n?(?<![ \t])[ \t]*(?:"[^"]*"|'[^']*'|\([^)]*\)))?[ \t]*\r?\n?(?<![ \t])[ \t]*\)$/u;

//-----------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -75,17 +75,9 @@ export default {

const match = linkOrImagePattern.exec(text);
if (match !== null) {
const {
imageBang,
label,
destination,
title: titleRaw,
} = match.groups;
const title = titleRaw?.slice(1, -1);

const isImage = !!imageBang;
const type = isImage ? "image" : "link";
const prefix = isImage ? "!" : "";
const { label, destination } = match.groups;
const { type, title } = node;
const prefix = type === "image" ? "!" : "";
const url =
normalizeIdentifier(destination).toLowerCase();

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-reversed-media-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/** Matches reversed link/image syntax like `(text)[url]`, ignoring escaped characters like `\(text\)[url]`. */
const reversedPattern =
/(?<=(?<!\\)(?:\\{2})*)\((?<label>(?:\\.|[^()\\]|\([\s\S]*\))*)\)\[(?<url>(?:\\.|[^\]\\\n])*)\](?!\()/gu;
/(?<=(?<!\\)(?:\\{2})*)\((?<label>(?:\\.|[^()\\]|\([\s\S]*\))*)\)\[(?<url>(?:\\.|[^\]\\\r\n])*)\](?!\()/gu;

/**
* Checks if a match is within any skip range
Expand Down
3 changes: 3 additions & 0 deletions tests/rules/no-reversed-media-syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ ruleTester.run("no-reversed-media-syntax", rule, {
"![foo](bar)",
"![foo](#bar)",
"![foo](http://bar.com)",
"(foo)[bar\r\n]",
"(foo)[bar\r]",
"(foo)[bar\n]",
"(foo)[bar](http://bar.com)",
" myObj.getFiles(test)[0]",
dedent`
Expand Down