eslint-mdx
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -7,28 +7,4 @@ /// <reference types="node" /> | ||
export declare const arrayify: <T, R = T extends (infer S)[] ? S : T>(...args: T[]) => R[]; | ||
/** | ||
* Given a filepath, get the nearest path that is a regular file. | ||
* The filepath provided by eslint may be a virtual filepath rather than a file | ||
* on disk. This attempts to transform a virtual path into an on-disk path | ||
*/ | ||
export declare const getPhysicalFilename: (filename: string, child?: string) => string; | ||
/** | ||
* ! copied from https://github.com/just-jeb/angular-builders/blob/master/packages/custom-webpack/src/utils.ts#L53-L67 | ||
* | ||
* This uses a dynamic import to load a module which may be ESM. | ||
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript | ||
* will currently, unconditionally downlevel dynamic import into a require call. | ||
* require calls cannot load ESM code and will result in a runtime error. To workaround | ||
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import. | ||
* Once TypeScript provides support for keeping the dynamic import this workaround can | ||
* be dropped. | ||
* | ||
* @param modulePath The path of the module to load. | ||
* @returns A Promise that resolves to the dynamically imported module. | ||
*/ | ||
export declare const loadEsmModule: <T>(modulePath: URL | string) => Promise<T>; | ||
/** | ||
* Loads CJS and ESM modules based on extension | ||
* @param modulePath path to the module | ||
* @returns | ||
*/ | ||
export declare const loadModule: <T>(modulePath: string) => Promise<T>; | ||
@@ -35,0 +11,0 @@ export declare const requirePkg: <T>(plugin: string, prefix: string, filePath?: string) => Promise<T>; |
@@ -5,3 +5,2 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
/* eslint-disable unicorn/no-await-expression-member */ | ||
const node_fs_1 = tslib_1.__importDefault(require("node:fs")); | ||
@@ -17,7 +16,2 @@ const node_path_1 = tslib_1.__importDefault(require("node:path")); | ||
exports.arrayify = arrayify; | ||
/** | ||
* Given a filepath, get the nearest path that is a regular file. | ||
* The filepath provided by eslint may be a virtual filepath rather than a file | ||
* on disk. This attempts to transform a virtual path into an on-disk path | ||
*/ | ||
const getPhysicalFilename = (filename, child) => { | ||
@@ -31,4 +25,2 @@ try { | ||
const { code } = err; | ||
// https://github.com/eslint/eslint/issues/11989 | ||
// Additionally, it seems there is no `ENOTDIR` code on Windows... | ||
if (code === 'ENOTDIR' || code === 'ENOENT') { | ||
@@ -41,26 +33,4 @@ return (0, exports.getPhysicalFilename)(node_path_1.default.dirname(filename), filename); | ||
exports.getPhysicalFilename = getPhysicalFilename; | ||
/** | ||
* ! copied from https://github.com/just-jeb/angular-builders/blob/master/packages/custom-webpack/src/utils.ts#L53-L67 | ||
* | ||
* This uses a dynamic import to load a module which may be ESM. | ||
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript | ||
* will currently, unconditionally downlevel dynamic import into a require call. | ||
* require calls cannot load ESM code and will result in a runtime error. To workaround | ||
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import. | ||
* Once TypeScript provides support for keeping the dynamic import this workaround can | ||
* be dropped. | ||
* | ||
* @param modulePath The path of the module to load. | ||
* @returns A Promise that resolves to the dynamically imported module. | ||
*/ | ||
/* istanbul ignore next */ | ||
const loadEsmModule = (modulePath) => | ||
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func | ||
new Function('modulePath', `return import(modulePath);`)(modulePath); | ||
const loadEsmModule = (modulePath) => new Function('modulePath', `return import(modulePath);`)(modulePath); | ||
exports.loadEsmModule = loadEsmModule; | ||
/** | ||
* Loads CJS and ESM modules based on extension | ||
* @param modulePath path to the module | ||
* @returns | ||
*/ | ||
const loadModule = (modulePath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
@@ -71,24 +41,14 @@ const esModulePath = node_path_1.default.isAbsolute(modulePath) | ||
switch (node_path_1.default.extname(modulePath)) { | ||
/* istanbul ignore next */ | ||
case '.mjs': { | ||
return (yield (0, exports.loadEsmModule)(esModulePath)).default; | ||
} | ||
/* istanbul ignore next */ | ||
case '.cjs': { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-return | ||
return require(modulePath); | ||
} | ||
default: { | ||
// The file could be either CommonJS or ESM. | ||
// CommonJS is tried first then ESM if loading fails. | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-return | ||
return require(modulePath); | ||
} | ||
catch (err) { | ||
/* istanbul ignore if */ | ||
if (err.code === 'ERR_REQUIRE_ESM') { | ||
// Load the ESM configuration file using the TypeScript dynamic import workaround. | ||
// Once TypeScript provides support for keeping the dynamic import this workaround can be | ||
// changed to a direct dynamic import. | ||
return (yield (0, exports.loadEsmModule)(esModulePath)).default; | ||
@@ -111,3 +71,2 @@ } | ||
plugin, | ||
/* istanbul ignore next */ | ||
plugin.startsWith('@') | ||
@@ -132,3 +91,2 @@ ? plugin.replace('/', '/' + prefix) | ||
exports.requirePkg = requirePkg; | ||
/* istanbul ignore next -- used in worker */ | ||
const getPositionAtFactory = (text) => { | ||
@@ -148,3 +106,3 @@ const lines = text.split('\n'); | ||
} | ||
currOffset = nextOffset + 1; // add a line break `\n` offset | ||
currOffset = nextOffset + 1; | ||
} | ||
@@ -160,3 +118,3 @@ }; | ||
? null | ||
: /* istanbul ignore next -- used in worker */ (0, exports.getPositionAtFactory)(text); | ||
: (0, exports.getPositionAtFactory)(text); | ||
return { | ||
@@ -166,8 +124,6 @@ start: startOffset, | ||
loc: { | ||
start: | ||
/* istanbul ignore next -- used in worker */ 'line' in start | ||
start: 'line' in start | ||
? start | ||
: getPositionAt(startOffset), | ||
end: | ||
/* istanbul ignore next -- used in worker */ 'line' in end | ||
end: 'line' in end | ||
? end | ||
@@ -180,3 +136,2 @@ : getPositionAt(endOffset), | ||
exports.normalizePosition = normalizePosition; | ||
/* istanbul ignore next -- used in worker */ | ||
const prevCharOffsetFactory = (text) => (offset) => { | ||
@@ -191,3 +146,2 @@ for (let i = offset; i >= 0; i--) { | ||
exports.prevCharOffsetFactory = prevCharOffsetFactory; | ||
/* istanbul ignore next -- used in worker */ | ||
const nextCharOffsetFactory = (text) => { | ||
@@ -194,0 +148,0 @@ const total = text.length; |
@@ -47,3 +47,3 @@ "use strict"; | ||
column: error.column, | ||
index: /* istanbul ignore next */ (_a = error.position) === null || _a === void 0 ? void 0 : _a.start.offset, | ||
index: (_a = error.position) === null || _a === void 0 ? void 0 : _a.start.offset, | ||
}); | ||
@@ -62,4 +62,3 @@ } | ||
exports.parser = new Parser(); | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
exports.parse = exports.parser.parse, exports.parseForESLint = exports.parser.parseForESLint; | ||
//# sourceMappingURL=parser.js.map |
@@ -22,3 +22,2 @@ "use strict"; | ||
}); | ||
// eslint-disable-next-line sonarjs/cognitive-complexity | ||
visit(root, node => { | ||
@@ -55,6 +54,4 @@ var _a; | ||
} | ||
// will always add 1 in `nextCharOffset`, so we minus 1 here | ||
let lastAttrOffset = nodeNameStart + nodeNameLength - 1; | ||
for (const attr of node.attributes) { | ||
// already handled by acorn | ||
if (attr.type === 'mdxJsxExpressionAttribute') { | ||
@@ -73,9 +70,2 @@ (0, assert_1.ok)(attr.data); | ||
} | ||
/** | ||
* not available yet | ||
* @see https://github.com/mdx-js/mdx/issues/2034 | ||
*/ | ||
// const attrPos = attr.position | ||
// const attrStart = attrPos.start.offset | ||
// const attrEnd = attrPos.end.offset | ||
const attrStart = nextCharOffset(lastAttrOffset + 1); | ||
@@ -94,3 +84,2 @@ (0, assert_1.ok)(attrStart != null); | ||
tokens.push(newToken(tt.eq, attrEqualOffset, attrEqualOffset + 1, '=')); | ||
// `mdxJsxAttributeValueExpression`, already handled by acorn | ||
if (typeof attrValue === 'object') { | ||
@@ -116,3 +105,2 @@ const data = attrValue.data; | ||
const nextChar = text[nextOffset]; | ||
// self closing tag | ||
if (nextChar === '/') { | ||
@@ -119,0 +107,0 @@ tokens.push(newToken(tt.slash, nextOffset, nextOffset + 1, '/')); |
@@ -5,4 +5,2 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
/* eslint-disable @typescript-eslint/consistent-type-imports */ | ||
/* eslint-disable unicorn/no-await-expression-member */ | ||
const node_path_1 = tslib_1.__importDefault(require("node:path")); | ||
@@ -16,2 +14,4 @@ const node_url_1 = require("node:url"); | ||
let acorn; | ||
let acornJsx; | ||
let acornParser; | ||
let tokTypes; | ||
@@ -26,2 +26,3 @@ let jsxTokTypes; | ||
const getRemarkMdxOptions = (tokens) => ({ | ||
acorn: acornParser, | ||
acornOptions: { | ||
@@ -58,10 +59,3 @@ ecmaVersion: 'latest', | ||
if (result) { | ||
/* istanbul ignore next */ | ||
const { plugins = [], settings } = | ||
// type-coverage:ignore-next-line -- cosmiconfig's typings issue | ||
(result.config || {}); | ||
// disable this rule automatically since we already have a parser option `extensions` | ||
// only disable this plugin if there are at least one plugin enabled | ||
// otherwise it is redundant | ||
/* istanbul ignore else */ | ||
const { plugins = [], settings } = (result.config || {}); | ||
if (plugins.length > 0) { | ||
@@ -72,3 +66,2 @@ try { | ||
catch (_a) { | ||
// just ignore if the package does not exist | ||
} | ||
@@ -84,5 +77,3 @@ } | ||
const [plugin, ...pluginSettings] = (0, helpers_1.arrayify)(pluginWithSettings); | ||
return (yield processor).use( | ||
/* istanbul ignore next */ | ||
typeof plugin === 'string' | ||
return (yield processor).use(typeof plugin === 'string' | ||
? yield (0, helpers_1.requirePkg)(plugin, 'remark', result.filepath) | ||
@@ -107,2 +98,7 @@ : plugin, ...pluginSettings); | ||
sharedTokens.length = 0; | ||
if (!acorn) { | ||
acorn = yield (0, helpers_1.loadEsmModule)('acorn'); | ||
acornJsx = yield (0, helpers_1.loadEsmModule)('acorn-jsx'); | ||
acornParser = acorn.Parser.extend(acornJsx.default()); | ||
} | ||
const processor = yield (0, exports.getRemarkProcessor)(physicalFilename, isMdx, ignoreRemarkConfig); | ||
@@ -126,11 +122,2 @@ if (process) { | ||
} | ||
/** | ||
* unified plugins are using ESM version of acorn, | ||
* so we have to use the same version as well, | ||
* otherwise the TokenType will be different class | ||
* @see also https://github.com/acornjs/acorn-jsx/issues/133 | ||
*/ | ||
if (!acorn) { | ||
acorn = yield (0, helpers_1.loadEsmModule)('acorn'); | ||
} | ||
if (!tokTypes) { | ||
@@ -140,4 +127,3 @@ tokTypes = acorn.tokTypes; | ||
if (!jsxTokTypes) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
jsxTokTypes = (yield (0, helpers_1.loadEsmModule)('acorn-jsx')).default({ | ||
jsxTokTypes = acornJsx.default({ | ||
allowNamespacedObjects: true, | ||
@@ -160,3 +146,2 @@ })(acorn.Parser).acornJsx.tokTypes; | ||
const processed = new WeakSet(); | ||
// TODO: merge with `tokens.ts` | ||
if (isMdx) { | ||
@@ -244,5 +229,3 @@ const prevCharOffset = (0, helpers_1.prevCharOffsetFactory)(text); | ||
lastAttrOffset = attrValEnd; | ||
return Object.assign(Object.assign({}, normalizeNode(attrValStart, attrValEnd + 1)), { type: 'JSXSpreadAttribute', | ||
// https://github.com/mdx-js/eslint-mdx/pull/394#discussion_r872974843 | ||
argument: attr.data.estree.body[0] | ||
return Object.assign(Object.assign({}, normalizeNode(attrValStart, attrValEnd + 1)), { type: 'JSXSpreadAttribute', argument: attr.data.estree.body[0] | ||
.expression.properties[0].argument }); | ||
@@ -324,11 +307,6 @@ } | ||
} | ||
/** | ||
* Copied from @see https://github.com/eslint/espree/blob/main/lib/espree.js#L206-L220 | ||
*/ | ||
const templateElement = node; | ||
const startOffset = -1; | ||
const endOffset = templateElement.tail ? 1 : 2; | ||
// @ts-expect-error - unavailable for typing from estree | ||
templateElement.start += startOffset; | ||
// @ts-expect-error - unavailable for typing from estree | ||
templateElement.end += endOffset; | ||
@@ -335,0 +313,0 @@ if (templateElement.range) { |
{ | ||
"name": "eslint-mdx", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "ESLint Parser for MDX", | ||
@@ -8,33 +8,2 @@ "repository": "git+https://github.com/mdx-js/eslint-mdx.git", | ||
"author": "JounQin (https://www.1stG.me) <admin@1stg.me>", | ||
"donate": { | ||
"recipients": [ | ||
{ | ||
"name": "unts", | ||
"platform": "opencollective", | ||
"address": "https://opencollective.com/unts", | ||
"weight": 60 | ||
}, | ||
{ | ||
"name": "rxts", | ||
"platform": "opencollective", | ||
"address": "https://opencollective.com/rxts", | ||
"weight": 20 | ||
}, | ||
{ | ||
"name": "1stG", | ||
"email": "i@1stg.me", | ||
"weight": 20, | ||
"platforms": [ | ||
{ | ||
"platform": "opencollective", | ||
"address": "https://opencollective.com/1stG" | ||
}, | ||
{ | ||
"platform": "patreon", | ||
"address": "https://www.patreon.com/1stG" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"funding": { | ||
@@ -68,11 +37,11 @@ "type": "opencollective", | ||
"cosmiconfig": "^7.0.1", | ||
"espree": "^9.3.2", | ||
"estree-util-visit": "^1.1.0", | ||
"remark-mdx": "^2.1.2", | ||
"espree": "^9.4.0", | ||
"estree-util-visit": "^1.2.0", | ||
"remark-mdx": "^2.1.3", | ||
"remark-parse": "^10.0.1", | ||
"remark-stringify": "^10.0.2", | ||
"synckit": "^0.8.1", | ||
"synckit": "^0.8.4", | ||
"tslib": "^2.4.0", | ||
"unified": "^10.1.2", | ||
"unist-util-visit": "^4.1.0", | ||
"unist-util-visit": "^4.1.1", | ||
"uvu": "^0.5.6", | ||
@@ -79,0 +48,0 @@ "vfile": "^5.3.4" |
@@ -21,3 +21,3 @@ <p align="center"> | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org) | ||
[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets) | ||
@@ -47,3 +47,3 @@ > [ESLint][] Parser/Plugin for [MDX][], helps you lint all ES syntaxes. | ||
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/JounQin.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx) | ||
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/unifiedjs.vscode-mdx)](https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx) | ||
@@ -50,0 +50,0 @@ [VSCode MDX][]\: Integrates with [VSCode ESLint][], syntaxes highlighting and error reporting. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78545
1000
Updatedespree@^9.4.0
Updatedestree-util-visit@^1.2.0
Updatedremark-mdx@^2.1.3
Updatedsynckit@^0.8.4
Updatedunist-util-visit@^4.1.1