eslint-plugin-mdx
Advanced tools
Comparing version 1.14.1 to 1.15.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.15.0](https://github.com/mdx-js/eslint-mdx/compare/v1.14.1...v1.15.0) (2021-08-21) | ||
### Features | ||
* resolve custom remark config on parsing ([#337](https://github.com/mdx-js/eslint-mdx/issues/337)) ([94fcb4c](https://github.com/mdx-js/eslint-mdx/commit/94fcb4c1346d9bfdec61a8335b65e536d5b59ac4)) | ||
## [1.14.1](https://github.com/mdx-js/eslint-mdx/compare/v1.14.0...v1.14.1) (2021-07-14) | ||
@@ -8,0 +19,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { arrayify, last, isJsxNode, DEFAULT_EXTENSIONS, MARKDOWN_EXTENSIONS } from 'eslint-mdx'; | ||
import { arrayify, last, isJsxNode, DEFAULT_EXTENSIONS, MARKDOWN_EXTENSIONS, getPhysicalFilename, getRemarkProcessor } from 'eslint-mdx'; | ||
import { version } from 'eslint/package.json'; | ||
@@ -8,8 +8,2 @@ import { processors } from 'eslint-plugin-markdown'; | ||
import vfile from 'vfile'; | ||
import fs from 'fs'; | ||
import { cosmiconfigSync } from 'cosmiconfig'; | ||
import remarkMdx from 'remark-mdx'; | ||
import remarkParse from 'remark-parse'; | ||
import remarkStringify from 'remark-stringify'; | ||
import unified from 'unified'; | ||
@@ -350,79 +344,2 @@ const base = { | ||
const requirePkg = (plugin, prefix, filePath) => { | ||
if (filePath && /^\.\.?([/\\]|$)/.test(plugin)) { | ||
plugin = path.resolve(path.dirname(filePath), plugin); | ||
} | ||
prefix = prefix.endsWith("-") ? prefix : prefix + "-"; | ||
const packages = [ | ||
plugin, | ||
plugin.startsWith("@") ? plugin.replace("/", "/" + prefix) : prefix + plugin | ||
]; | ||
let error; | ||
for (const pkg of packages) { | ||
try { | ||
return require(pkg); | ||
} catch (err) { | ||
if (!error) { | ||
error = err; | ||
} | ||
} | ||
} | ||
throw error; | ||
}; | ||
const getPhysicalFilename = (filename) => { | ||
try { | ||
if (fs.statSync(filename).isFile()) { | ||
return filename; | ||
} | ||
} catch (err) { | ||
if (err.code === "ENOTDIR") { | ||
return getPhysicalFilename(path.dirname(filename)); | ||
} | ||
} | ||
return filename; | ||
}; | ||
const remarkProcessor = unified().use(remarkParse).freeze(); | ||
const explorer = cosmiconfigSync("remark", { | ||
packageProp: "remarkConfig" | ||
}); | ||
const processorCache = new Map(); | ||
const getRemarkProcessor = (searchFrom, isMdx) => { | ||
const initCacheKey = `${String(isMdx)}-${searchFrom}`; | ||
let cachedProcessor = processorCache.get(initCacheKey); | ||
if (cachedProcessor) { | ||
return cachedProcessor; | ||
} | ||
const result = explorer.search(searchFrom); | ||
const cacheKey = result ? `${String(isMdx)}-${result.filepath}` : ""; | ||
cachedProcessor = processorCache.get(cacheKey); | ||
if (cachedProcessor) { | ||
return cachedProcessor; | ||
} | ||
if (result) { | ||
const { plugins = [], settings } = result.config || {}; | ||
if (plugins.length > 0) { | ||
try { | ||
plugins.push([require.resolve("remark-lint-file-extension"), false]); | ||
} catch (e) { | ||
} | ||
} | ||
const initProcessor = remarkProcessor().use({ settings }).use(remarkStringify); | ||
if (isMdx) { | ||
initProcessor.use(remarkMdx); | ||
} | ||
cachedProcessor = plugins.reduce((processor, pluginWithSettings) => { | ||
const [plugin, ...pluginSettings] = arrayify(pluginWithSettings); | ||
return processor.use(typeof plugin === "string" ? requirePkg(plugin, "remark", result.filepath) : plugin, ...pluginSettings); | ||
}, initProcessor).freeze(); | ||
} else { | ||
const initProcessor = remarkProcessor().use(remarkStringify); | ||
if (isMdx) { | ||
initProcessor.use(remarkMdx); | ||
} | ||
cachedProcessor = initProcessor.freeze(); | ||
} | ||
processorCache.set(initCacheKey, cachedProcessor).set(cacheKey, cachedProcessor); | ||
return cachedProcessor; | ||
}; | ||
var __defProp = Object.defineProperty; | ||
@@ -555,2 +472,2 @@ var __defProps = Object.defineProperties; | ||
export { DEFAULT_LANGUAGE_MAPPER, base, codeBlocks, configs, getGlobals, getPhysicalFilename, getRemarkProcessor, getShortLang, noJsxHtmlComments, noUnusedExpressions, overrides, processorCache, processorOptions, remark$2 as processors, recommended, remark, remarkProcessor, requirePkg, rules }; | ||
export { DEFAULT_LANGUAGE_MAPPER, base, codeBlocks, configs, getGlobals, getShortLang, noJsxHtmlComments, noUnusedExpressions, overrides, processorOptions, remark$2 as processors, recommended, remark, rules }; |
@@ -1,2 +0,2 @@ | ||
import { arrayify, last, isJsxNode, DEFAULT_EXTENSIONS, MARKDOWN_EXTENSIONS } from 'eslint-mdx'; | ||
import { arrayify, last, isJsxNode, DEFAULT_EXTENSIONS, MARKDOWN_EXTENSIONS, getPhysicalFilename, getRemarkProcessor } from 'eslint-mdx'; | ||
import { version } from 'eslint/package.json'; | ||
@@ -8,8 +8,2 @@ import { processors } from 'eslint-plugin-markdown'; | ||
import vfile from 'vfile'; | ||
import fs from 'fs'; | ||
import { cosmiconfigSync } from 'cosmiconfig'; | ||
import remarkMdx from 'remark-mdx'; | ||
import remarkParse from 'remark-parse'; | ||
import remarkStringify from 'remark-stringify'; | ||
import unified from 'unified'; | ||
@@ -350,79 +344,2 @@ const base = { | ||
const requirePkg = (plugin, prefix, filePath) => { | ||
if (filePath && /^\.\.?([/\\]|$)/.test(plugin)) { | ||
plugin = path.resolve(path.dirname(filePath), plugin); | ||
} | ||
prefix = prefix.endsWith("-") ? prefix : prefix + "-"; | ||
const packages = [ | ||
plugin, | ||
plugin.startsWith("@") ? plugin.replace("/", "/" + prefix) : prefix + plugin | ||
]; | ||
let error; | ||
for (const pkg of packages) { | ||
try { | ||
return require(pkg); | ||
} catch (err) { | ||
if (!error) { | ||
error = err; | ||
} | ||
} | ||
} | ||
throw error; | ||
}; | ||
const getPhysicalFilename = (filename) => { | ||
try { | ||
if (fs.statSync(filename).isFile()) { | ||
return filename; | ||
} | ||
} catch (err) { | ||
if (err.code === "ENOTDIR") { | ||
return getPhysicalFilename(path.dirname(filename)); | ||
} | ||
} | ||
return filename; | ||
}; | ||
const remarkProcessor = unified().use(remarkParse).freeze(); | ||
const explorer = cosmiconfigSync("remark", { | ||
packageProp: "remarkConfig" | ||
}); | ||
const processorCache = new Map(); | ||
const getRemarkProcessor = (searchFrom, isMdx) => { | ||
const initCacheKey = `${String(isMdx)}-${searchFrom}`; | ||
let cachedProcessor = processorCache.get(initCacheKey); | ||
if (cachedProcessor) { | ||
return cachedProcessor; | ||
} | ||
const result = explorer.search(searchFrom); | ||
const cacheKey = result ? `${String(isMdx)}-${result.filepath}` : ""; | ||
cachedProcessor = processorCache.get(cacheKey); | ||
if (cachedProcessor) { | ||
return cachedProcessor; | ||
} | ||
if (result) { | ||
const { plugins = [], settings } = result.config || {}; | ||
if (plugins.length > 0) { | ||
try { | ||
plugins.push([require.resolve("remark-lint-file-extension"), false]); | ||
} catch (e) { | ||
} | ||
} | ||
const initProcessor = remarkProcessor().use({ settings }).use(remarkStringify); | ||
if (isMdx) { | ||
initProcessor.use(remarkMdx); | ||
} | ||
cachedProcessor = plugins.reduce((processor, pluginWithSettings) => { | ||
const [plugin, ...pluginSettings] = arrayify(pluginWithSettings); | ||
return processor.use(typeof plugin === "string" ? requirePkg(plugin, "remark", result.filepath) : plugin, ...pluginSettings); | ||
}, initProcessor).freeze(); | ||
} else { | ||
const initProcessor = remarkProcessor().use(remarkStringify); | ||
if (isMdx) { | ||
initProcessor.use(remarkMdx); | ||
} | ||
cachedProcessor = initProcessor.freeze(); | ||
} | ||
processorCache.set(initCacheKey, cachedProcessor).set(cacheKey, cachedProcessor); | ||
return cachedProcessor; | ||
}; | ||
var __defProp = Object.defineProperty; | ||
@@ -555,2 +472,2 @@ var __defProps = Object.defineProperties; | ||
export { DEFAULT_LANGUAGE_MAPPER, base, codeBlocks, configs, getGlobals, getPhysicalFilename, getRemarkProcessor, getShortLang, noJsxHtmlComments, noUnusedExpressions, overrides, processorCache, processorOptions, remark$2 as processors, recommended, remark, remarkProcessor, requirePkg, rules }; | ||
export { DEFAULT_LANGUAGE_MAPPER, base, codeBlocks, configs, getGlobals, getShortLang, noJsxHtmlComments, noUnusedExpressions, overrides, processorOptions, remark$2 as processors, recommended, remark, rules }; |
import { noJsxHtmlComments } from './no-jsx-html-comments'; | ||
import { noUnusedExpressions } from './no-unused-expressions'; | ||
import { remark } from './remark'; | ||
export * from './helpers'; | ||
export * from './types'; | ||
@@ -6,0 +5,0 @@ export { noJsxHtmlComments, noUnusedExpressions, remark }; |
@@ -12,3 +12,2 @@ "use strict"; | ||
Object.defineProperty(exports, "remark", { enumerable: true, get: function () { return remark_1.remark; } }); | ||
tslib_1.__exportStar(require("./helpers"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
@@ -15,0 +14,0 @@ exports.rules = { |
@@ -9,3 +9,2 @@ "use strict"; | ||
const vfile_1 = tslib_1.__importDefault(require("vfile")); | ||
const helpers_1 = require("./helpers"); | ||
const workerPath = require.resolve('../worker'); | ||
@@ -43,5 +42,5 @@ // call `creatSyncFn` lazily for performance, it is already cached inside, related #323 | ||
} | ||
const physicalFilename = helpers_1.getPhysicalFilename(filename); | ||
const physicalFilename = eslint_mdx_1.getPhysicalFilename(filename); | ||
const sourceText = sourceCode.getText(node); | ||
const remarkProcessor = helpers_1.getRemarkProcessor(physicalFilename, isMdx); | ||
const remarkProcessor = eslint_mdx_1.getRemarkProcessor(physicalFilename, isMdx); | ||
const fileOptions = { | ||
@@ -48,0 +47,0 @@ path: physicalFilename, |
import type { Linter } from 'eslint'; | ||
import type { ExpressionStatement, Node } from 'estree'; | ||
import type { Attacher } from 'unified'; | ||
export interface WithParent { | ||
@@ -10,7 +9,2 @@ parent: NodeWithParent; | ||
} | ||
export declare type RemarkPlugin = Attacher | string; | ||
export interface RemarkConfig { | ||
settings: Record<string, string>; | ||
plugins: Array<RemarkPlugin | [RemarkPlugin, ...unknown[]]>; | ||
} | ||
export interface RemarkLintMessage { | ||
@@ -17,0 +11,0 @@ reason: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const eslint_mdx_1 = require("eslint-mdx"); | ||
const synckit_1 = require("synckit"); | ||
const vfile_1 = tslib_1.__importDefault(require("vfile")); | ||
const rules_1 = require("./rules"); | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
synckit_1.runAsWorker((fileOptions, physicalFilename, isMdx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const remarkProcessor = rules_1.getRemarkProcessor(physicalFilename, isMdx); | ||
const remarkProcessor = eslint_mdx_1.getRemarkProcessor(physicalFilename, isMdx); | ||
const file = vfile_1.default(fileOptions); | ||
@@ -23,3 +22,3 @@ try { | ||
}; | ||
})); | ||
})).catch(console.error); | ||
//# sourceMappingURL=worker.js.map |
{ | ||
"name": "eslint-plugin-mdx", | ||
"version": "1.14.1", | ||
"version": "1.15.0", | ||
"description": "ESLint Plugin for MDX", | ||
@@ -35,14 +35,9 @@ "repository": "git+https://github.com/mdx-js/eslint-mdx.git", | ||
"dependencies": { | ||
"cosmiconfig": "^7.0.0", | ||
"eslint-mdx": "^1.14.1", | ||
"eslint-mdx": "^1.15.0", | ||
"eslint-plugin-markdown": "^2.2.0", | ||
"remark-mdx": "^1.6.22", | ||
"remark-parse": "^8.0.3", | ||
"remark-stringify": "^8.1.1", | ||
"synckit": "^0.3.4", | ||
"tslib": "^2.3.0", | ||
"unified": "^9.2.1", | ||
"tslib": "^2.3.1", | ||
"vfile": "^4.2.1" | ||
}, | ||
"gitHead": "442cc022e45cdc355157f530f8e486489727ae89" | ||
"gitHead": "a7afce656975c9927f4174f1a480fddaa57f80a3" | ||
} |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6
4
102947
61
1497
- Removedcosmiconfig@^7.0.0
- Removedremark-mdx@^1.6.22
- Removedremark-parse@^8.0.3
- Removedremark-stringify@^8.1.1
- Removedunified@^9.2.1
Updatedeslint-mdx@^1.15.0
Updatedtslib@^2.3.1