Skip to content

Commit

Permalink
fix: swap custom glob-to-regexp w. minimatch
Browse files Browse the repository at this point in the history
This will be more robust and universal.
Especially for Windows paths with `\`.

Closes #12 #13
  • Loading branch information
JulianCataldo committed Sep 22, 2022
1 parent 8053916 commit e7022d6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 168 deletions.
150 changes: 0 additions & 150 deletions glob-to-regexp.ts

This file was deleted.

6 changes: 2 additions & 4 deletions index.ts
Expand Up @@ -6,6 +6,7 @@
/* eslint-disable max-lines */
import fs from 'node:fs';
import path from 'node:path';
import minimatch from 'minimatch';
/* ·········································································· */
import yaml, { isNode, LineCounter } from 'yaml';
import type { Document } from 'yaml';
Expand All @@ -18,8 +19,6 @@ import type { VFileMessage } from 'vfile-message';
import { lintRule } from 'unified-lint-rule';
import type { VFile } from 'unified-lint-rule/lib';
import type { Root, YAML } from 'mdast';
/* ·········································································· */
import { globToRegExp } from './glob-to-regexp.js';
/* —————————————————————————————————————————————————————————————————————————— */

const url = 'https://github.com/JulianCataldo/remark-lint-frontmatter-schema';
Expand Down Expand Up @@ -204,8 +203,7 @@ function validateFrontmatter(
/* Remove appended `./` or `/` */
const mdPathCleaned = path.join(mdFilePath);

const globber = globToRegExp(mdPathCleaned);
if (globber.test(vFile.path)) {
if (minimatch(vFile.path, mdPathCleaned)) {
schemaRelPath = globSchemaPath;
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"minimatch": "^5.1.0",
"unified-lint-rule": "^2.1.1",
"yaml": "^2.1.1"
},
Expand All @@ -24,9 +25,9 @@
"@semantic-release/github": "8.0.6",
"@semantic-release/npm": "9.0.1",
"@types/eslint": "8.4.6",
"@types/glob-to-regexp": "0.4.1",
"@types/json-schema": "7.0.11",
"@types/mdast": "3.0.10",
"@types/minimatch": "^5.1.2",
"@types/node": "18.7.16",
"@types/prettier": "2.7.0",
"@types/unist": "2.0.6",
Expand Down
23 changes: 12 additions & 11 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions tsconfig.json
Expand Up @@ -9,7 +9,7 @@
"resolveJsonModule": true,
// Enable stricter transpilation for better output.
"isolatedModules": true,
"types": ["node", "unist", "unified"],
"types": ["node", "unist", "unified", "minimatch"],

"allowJs": true,

Expand All @@ -28,5 +28,5 @@
"outDir": "./dist"
},

"include": ["./index.ts", "./glob-to-regexp.ts"]
"include": ["./index.ts"]
}

0 comments on commit e7022d6

Please sign in to comment.