Skip to content

Commit c497839

Browse files
authored
fix: throw error with correct loc (#382)
1 parent 68d41a1 commit c497839

File tree

10 files changed

+637
-260
lines changed

10 files changed

+637
-260
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,17 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout Repo
19-
uses: actions/checkout@master
19+
uses: actions/checkout@v3
2020

2121
- name: Setup Node.js ${{ matrix.node }}
22-
uses: actions/setup-node@master
22+
uses: actions/setup-node@v3
2323
with:
2424
node-version: ${{ matrix.node }}
25+
cache: yarn
2526

2627
- name: Link Yarn global binaries into PATH
2728
run: echo "$(yarn global bin)" >> $GITHUB_PATH
2829

29-
- name: Get yarn cache directory path
30-
id: yarn-cache-dir-path
31-
run: echo "::set-output name=dir::$(yarn cache dir)"
32-
33-
- uses: actions/cache@v2
34-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
35-
with:
36-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
37-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
38-
restore-keys: |
39-
${{ runner.os }}-yarn-
40-
4130
- name: Install Dependencies
4231
run: yarn --frozen-lockfile
4332

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This project is a [lerna][] monorepo, so packages releasing is controlled by [le
1616

1717
### Release a bete next version
1818

19-
Run `yarn release-next`
19+
Run `yarn build && yarn release-next`
2020

2121
[contributing]: https://mdxjs.com/contributing
2222
[lerna]: https://github.com/lerna/lerna

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626
"typecov": "type-coverage"
2727
},
2828
"devDependencies": {
29-
"@1stg/lib-config": "^5.3.0",
29+
"@1stg/lib-config": "^5.5.0",
3030
"@types/eslint": "^8.4.1",
3131
"@types/eslint-plugin-markdown": "^2.0.0",
3232
"@types/jest": "^27.4.1",
3333
"@types/node": "^17.0.23",
3434
"@types/react": "^17.0.43",
3535
"@types/unist": "^2.0.6",
3636
"lerna": "^4.0.0",
37-
"react": "^17.0.2",
37+
"react": "^18.0.0",
3838
"remark-frontmatter": "4.0.1",
39+
"remark-gfm": "^3.0.1",
3940
"remark-lint": "^9.1.1",
4041
"remark-preset-lint-consistent": "^5.1.1",
4142
"remark-preset-lint-markdown-style-guide": "^5.1.2",
@@ -48,7 +49,7 @@
4849
"typescript": "^4.6.3"
4950
},
5051
"resolutions": {
51-
"prettier": "^2.6.1"
52+
"prettier": "^2.6.2"
5253
},
5354
"commitlint": {
5455
"extends": [
@@ -95,6 +96,7 @@
9596
"preset-lint-markdown-style-guide",
9697
"preset-lint-recommended",
9798
"preset-prettier",
99+
"gfm",
98100
"validate-links"
99101
]
100102
},

packages/eslint-mdx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"remark-mdx": "^2.1.1",
3535
"remark-parse": "^10.0.1",
3636
"remark-stringify": "^10.0.2",
37-
"synckit": "^0.6.0",
37+
"synckit": "^0.7.0",
3838
"tslib": "^2.3.1",
3939
"unified": "^10.1.2"
4040
}

packages/eslint-mdx/src/parser.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path'
22

33
import type { AST, Linter } from 'eslint'
4+
import type { VFileMessage } from 'vfile-message'
45

56
import {
67
arrayify,
@@ -10,9 +11,13 @@ import {
1011
} from './helpers'
1112
import { getPhysicalFilename } from './processor'
1213
import { traverse } from './traverse'
13-
import type { ParserOptions } from './types'
14+
import type { ParserOptions, WorkerParseResult } from './types'
1415

15-
export const AST_PROPS = ['body', 'comments'] as const
16+
export const AST_PROPS = [
17+
'body',
18+
// disable comments temporarily -- #380
19+
// 'comments'
20+
] as const
1621

1722
export const DEFAULT_EXTENSIONS: readonly string[] = ['.mdx']
1823
export const MARKDOWN_EXTENSIONS: readonly string[] = ['.md']
@@ -59,15 +64,28 @@ export class Parser {
5964

6065
const physicalFilename = getPhysicalFilename(filePath)
6166

62-
const { root, tokens, comments } = performSyncWork({
63-
fileOptions: {
64-
path: physicalFilename,
65-
value: code,
66-
},
67-
physicalFilename,
68-
isMdx,
69-
ignoreRemarkConfig: ignoreRemarkConfig,
70-
})
67+
let result: WorkerParseResult
68+
69+
try {
70+
result = performSyncWork({
71+
fileOptions: {
72+
path: physicalFilename,
73+
value: code,
74+
},
75+
physicalFilename,
76+
isMdx,
77+
ignoreRemarkConfig: ignoreRemarkConfig,
78+
})
79+
} catch (err: unknown) {
80+
const error = err as VFileMessage
81+
throw Object.assign(new SyntaxError(error.message), {
82+
lineNumber: error.line,
83+
column: error.column,
84+
index: /* istanbul ignore next */ error.position?.start.offset,
85+
})
86+
}
87+
88+
const { root, tokens, comments } = result
7189

7290
this._ast = {
7391
...normalizePosition(root.position),
@@ -85,7 +103,6 @@ export class Parser {
85103
}
86104

87105
for (const prop of AST_PROPS) {
88-
// @ts-expect-error
89106
this._ast[prop].push(...(node.data?.estree[prop] || []))
90107
}
91108
})

packages/eslint-mdx/src/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { AST } from 'eslint'
99
import type { EsprimaToken } from 'espree/lib/token-translator'
1010
import type { Comment as EsComment } from 'estree'
1111
import type { Options } from 'micromark-extension-mdx-expression'
12-
import { runAsWorker } from 'synckit'
12+
import { extractProperties, runAsWorker } from 'synckit'
1313
import type { FrozenProcessor } from 'unified'
1414
import type { Parent } from 'unist'
1515
import type { VFileMessage } from 'vfile-message'
@@ -184,7 +184,7 @@ runAsWorker(
184184
}
185185

186186
return {
187-
messages: JSON.parse(JSON.stringify(file.messages)) as VFileMessage[],
187+
messages: file.messages.map(message => extractProperties(message)),
188188
content: file.toString(),
189189
}
190190
}

0 commit comments

Comments
 (0)