Skip to content

Commit

Permalink
feat!: bump all unified ecosystem dependencies, support mdx v3 (#486)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Caldwell <jaswrks@users.noreply.github.com>
  • Loading branch information
JounQin and jaswrks committed Dec 5, 2023
1 parent 7ca1ffe commit 508e7ce
Show file tree
Hide file tree
Showing 26 changed files with 3,937 additions and 6,050 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-bikes-sparkle.md
@@ -0,0 +1,6 @@
---
"eslint-mdx": major
"eslint-plugin-mdx": major
---

feat!: bump all unified ecosystem dependencies, support mdx v3
6 changes: 6 additions & 0 deletions .changeset/swift-cycles-mix.md
@@ -0,0 +1,6 @@
---
"eslint-mdx": major
"eslint-plugin-mdx": major
---

chore!: require node >= 18, drop node 12, 14 and 16
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
@@ -1,5 +1,5 @@
{
"node": "16",
"node": "18",
"packages": [
"packages/*"
],
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -14,16 +14,15 @@ jobs:
- ubuntu-latest
- windows-latest
node:
- 16
- 18
- 20
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pkg-size.yml
Expand Up @@ -12,12 +12,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
- name: Setup Node.js LTS
uses: actions/setup-node@v4
with:
node-version: 16
node-version: lts/*
cache: yarn

- name: Package Size Report
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Expand Up @@ -11,15 +11,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 16
uses: actions/setup-node@v3
- name: Setup Node.js LTS
uses: actions/setup-node@v4
with:
node-version: 16
node-version: lts/*
cache: yarn

- name: Install Dependencies
Expand Down
35 changes: 22 additions & 13 deletions package.json
Expand Up @@ -9,7 +9,7 @@
"workspaces": [
"packages/*"
],
"packageManager": "yarn@1.22.19",
"packageManager": "yarn@1.22.21",
"scripts": {
"build": "run-p build:*",
"build:r": "r -f es2015",
Expand All @@ -27,25 +27,34 @@
},
"devDependencies": {
"@1stg/lib-config": "^12.0.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@types/eslint": "^8.44.1",
"@types/eslint-plugin-markdown": "^2.0.0",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.6",
"@types/react": "^18.2.18",
"@types/unist": "^2.0.6",
"jest": "^29.6.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@types/eslint": "^8.44.8",
"@types/eslint-plugin-markdown": "^2.0.2",
"@types/jest": "^29.5.10",
"@types/node": "^20.10.3",
"@types/react": "^18.2.42",
"@types/unist": "^3.0.2",
"jest": "^29.7.0",
"patch-package": "^8.0.0",
"react": "^18.2.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"type-coverage": "^2.26.0",
"typescript": "^5.1.6",
"type-coverage": "^2.27.0",
"typescript": "^5.3.2",
"yarn-deduplicate": "^6.0.2"
},
"resolutions": {
"prettier": "^2.8.8"
"@types/acorn": "^6.0.0",
"@types/mdast": "^4.0.3",
"acorn": "^8.11.2",
"cliui": "npm:@isaacs/cliui@^8.0.2",
"eslint-plugin-markdown": "JounQin/eslint-plugin-markdown#feat/bump",
"mdast-util-frontmatter": "^2.0.1",
"mdast-util-gfm": "^3.0.0",
"prettier": "^2.8.8",
"unified": "^11.0.4",
"unified-engine": "^11.2.0"
},
"commitlint": {
"extends": [
Expand Down
24 changes: 12 additions & 12 deletions packages/eslint-mdx/package.json
Expand Up @@ -11,7 +11,7 @@
},
"license": "MIT",
"engines": {
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
"node": ">=18.0.0"
},
"main": "lib/index.js",
"module": "lib/index.es2015.mjs",
Expand All @@ -30,19 +30,19 @@
"eslint": ">=8.0.0"
},
"dependencies": {
"acorn": "^8.10.0",
"acorn": "^8.11.2",
"acorn-jsx": "^5.3.2",
"espree": "^9.6.1",
"estree-util-visit": "^1.2.1",
"remark-mdx": "^2.3.0",
"remark-parse": "^10.0.2",
"remark-stringify": "^10.0.3",
"synckit": "^0.8.5",
"tslib": "^2.6.1",
"unified": "^10.1.2",
"unified-engine": "^10.1.0",
"unist-util-visit": "^4.1.2",
"estree-util-visit": "^2.0.0",
"remark-mdx": "^3.0.0",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"synckit": "^0.8.6",
"tslib": "^2.6.2",
"unified": "^11.0.4",
"unified-engine": "^11.2.0",
"unist-util-visit": "^5.0.0",
"uvu": "^0.5.6",
"vfile": "^5.3.7"
"vfile": "^6.0.1"
}
}
1 change: 0 additions & 1 deletion packages/eslint-mdx/src/helpers.ts
Expand Up @@ -77,7 +77,6 @@ export const getPositionAtFactory = (text: string) => {
return {
line,
column: offset - currOffset,
offset,
}
}

Expand Down
11 changes: 6 additions & 5 deletions packages/eslint-mdx/src/parser.ts
Expand Up @@ -62,11 +62,12 @@ export class Parser {
ignoreRemarkConfig,
})
} catch (err: unknown) {
const error = err as VFileMessage
throw Object.assign(new SyntaxError(error.message), {
lineNumber: error.line,
column: error.column,
index: /* istanbul ignore next */ error.position?.start.offset,
const { message, line, column, place } = err as VFileMessage
const point = place && ('start' in place ? place.start : place)
throw Object.assign(new SyntaxError(message), {
lineNumber: line,
column,
index: /* istanbul ignore next */ point?.offset,
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-mdx/src/tokens.ts
@@ -1,5 +1,7 @@
/// <reference types="remark-mdx" />

import type { Token, TokenType, tokTypes } from 'acorn'
import type { Root } from 'remark-mdx'
import type { Root } from 'mdast'
import type { visit as visitor } from 'unist-util-visit'
import { ok as assert } from 'uvu/assert'

Expand Down Expand Up @@ -29,6 +31,7 @@ export const restoreTokens = (
value?: string,
): Token => ({
type,
// @ts-expect-error -- FIXME: `value` is a valid property of `Token`
value,
start,
end,
Expand Down
33 changes: 19 additions & 14 deletions packages/eslint-mdx/src/worker.ts
Expand Up @@ -25,14 +25,14 @@ import type {
} from 'estree-jsx'
import type {
BlockContent,
PhrasingContent,
Literal as MdastLiteral,
PhrasingContent,
Root,
} from 'mdast'
import type { Options } from 'micromark-extension-mdx-expression'
import type { Root } from 'remark-mdx'
import { extractProperties, runAsWorker } from 'synckit'
import type { FrozenProcessor } from 'unified'
import type { Config, Configuration } from 'unified-engine/lib/configuration'
import type { Processor } from 'unified'
import type { Configuration, ConfigResult } from 'unified-engine'
import type { Node } from 'unist'
import { ok as assert } from 'uvu/assert'
import type { VFileMessage } from 'vfile-message'
Expand Down Expand Up @@ -60,13 +60,16 @@ let tt: Record<string, TokenType> & typeof _tokTypes

let TokenTranslator: typeof import('espree/lib/token-translator')['default']

export const processorCache = new Map<string, FrozenProcessor>()
export const processorCache = new Map<
string,
Processor<Root, undefined, undefined, Root, string>
>()

const getRemarkConfig = async (searchFrom: string) => {
if (!config) {
const { Configuration } = await loadEsmModule<
typeof import('unified-engine/lib/configuration')
>('unified-engine/lib/configuration.js')
typeof import('unified-engine')
>('unified-engine')
config = new Configuration({
cwd: process.cwd(),
packageField: 'remarkConfig',
Expand All @@ -76,10 +79,10 @@ const getRemarkConfig = async (searchFrom: string) => {
})
}

return new Promise<Config>((resolve, reject) =>
config.load(searchFrom, (error, result) =>
error ? reject(error) : resolve(result),
),
return new Promise<ConfigResult>((resolve, reject) =>
config.load(searchFrom, (error, result) => {
error ? reject(error) : resolve(result)
}),
)
}

Expand Down Expand Up @@ -270,7 +273,7 @@ runAsWorker(
const text = fileOptions.value as string
const tokenTranslator = new TokenTranslator(tt, text)

const root = processor.parse(fileOptions) as Root
const root = processor.parse(fileOptions)

const body: Program['body'] = []
const comments: Comment[] = []
Expand Down Expand Up @@ -372,7 +375,7 @@ runAsWorker(
processed.add(child)

if (child.data && 'estree' in child.data && child.data.estree) {
const estree = child.data.estree as Program
const { estree } = child.data

assert(estree.body.length <= 1)

Expand Down Expand Up @@ -638,7 +641,9 @@ runAsWorker(
})
}

const estree = (node.data?.estree || {
const estree = ((node.data &&
'estree' in node.data &&
node.data.estree) || {
body: [],
comments: [],
}) as Program
Expand Down
14 changes: 7 additions & 7 deletions packages/eslint-plugin-mdx/package.json
Expand Up @@ -11,7 +11,7 @@
},
"license": "MIT",
"engines": {
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
"node": ">=18.0.0"
},
"main": "lib/index.js",
"module": "lib/index.es2015.mjs",
Expand All @@ -33,11 +33,11 @@
"dependencies": {
"eslint-mdx": "^2.2.0",
"eslint-plugin-markdown": "^3.0.1",
"remark-mdx": "^2.3.0",
"remark-parse": "^10.0.2",
"remark-stringify": "^10.0.3",
"tslib": "^2.6.1",
"unified": "^10.1.2",
"vfile": "^5.3.7"
"remark-mdx": "^3.0.0",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"tslib": "^2.6.2",
"unified": "^11.0.4",
"vfile": "^6.0.1"
}
}
1 change: 0 additions & 1 deletion packages/eslint-plugin-mdx/src/processors/remark.ts
Expand Up @@ -10,7 +10,6 @@ import { processorOptions as defaultProcessorOptions } from './options'
export const createRemarkProcessor = (
processorOptions = defaultProcessorOptions,
): Linter.Processor => ({
// @ts-expect-error -- FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65826
meta: {
name: 'mdx/remark',
version: meta.version,
Expand Down
30 changes: 16 additions & 14 deletions packages/eslint-plugin-mdx/src/rules/remark.ts
Expand Up @@ -72,7 +72,7 @@ export const remark: Rule.RuleModule = {
fatal,
line,
column,
position: { start, end },
place,
} of messages) {
// https://github.com/remarkjs/remark-lint/issues/65#issuecomment-220800231
/* istanbul ignore next */
Expand All @@ -89,22 +89,24 @@ export const remark: Rule.RuleModule = {
ruleId,
severity,
}

const point = {
line,
// ! eslint ast column is 0-indexed, but unified is 1-indexed
column: column - 1,
}

context.report({
// related to https://github.com/eslint/eslint/issues/14198
message: JSON.stringify(message),
loc: {
line,
// ! eslint ast column is 0-indexed, but unified is 1-indexed
column: column - 1,
start: {
...start,
column: start.column - 1,
},
end: {
...end,
column: end.column - 1,
},
},
loc:
/* istanbul ignore next */ 'start' in place
? {
...point,
start: { ...place.start, column: place.start.column - 1 },
end: { ...place.end, column: place.end.column - 1 },
}
: point,
node,
fix:
fixedText === sourceText
Expand Down

0 comments on commit 508e7ce

Please sign in to comment.