Skip to content

Commit

Permalink
fix: throw error with correct loc (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Apr 18, 2022
1 parent 68d41a1 commit c497839
Show file tree
Hide file tree
Showing 10 changed files with 637 additions and 260 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
uses: actions/checkout@v3

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@master
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: yarn

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

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
run: yarn --frozen-lockfile

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This project is a [lerna][] monorepo, so packages releasing is controlled by [le

### Release a bete next version

Run `yarn release-next`
Run `yarn build && yarn release-next`

[contributing]: https://mdxjs.com/contributing
[lerna]: https://github.com/lerna/lerna
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
"typecov": "type-coverage"
},
"devDependencies": {
"@1stg/lib-config": "^5.3.0",
"@1stg/lib-config": "^5.5.0",
"@types/eslint": "^8.4.1",
"@types/eslint-plugin-markdown": "^2.0.0",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.23",
"@types/react": "^17.0.43",
"@types/unist": "^2.0.6",
"lerna": "^4.0.0",
"react": "^17.0.2",
"react": "^18.0.0",
"remark-frontmatter": "4.0.1",
"remark-gfm": "^3.0.1",
"remark-lint": "^9.1.1",
"remark-preset-lint-consistent": "^5.1.1",
"remark-preset-lint-markdown-style-guide": "^5.1.2",
Expand All @@ -48,7 +49,7 @@
"typescript": "^4.6.3"
},
"resolutions": {
"prettier": "^2.6.1"
"prettier": "^2.6.2"
},
"commitlint": {
"extends": [
Expand Down Expand Up @@ -95,6 +96,7 @@
"preset-lint-markdown-style-guide",
"preset-lint-recommended",
"preset-prettier",
"gfm",
"validate-links"
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"remark-mdx": "^2.1.1",
"remark-parse": "^10.0.1",
"remark-stringify": "^10.0.2",
"synckit": "^0.6.0",
"synckit": "^0.7.0",
"tslib": "^2.3.1",
"unified": "^10.1.2"
}
Expand Down
41 changes: 29 additions & 12 deletions packages/eslint-mdx/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'

import type { AST, Linter } from 'eslint'
import type { VFileMessage } from 'vfile-message'

import {
arrayify,
Expand All @@ -10,9 +11,13 @@ import {
} from './helpers'
import { getPhysicalFilename } from './processor'
import { traverse } from './traverse'
import type { ParserOptions } from './types'
import type { ParserOptions, WorkerParseResult } from './types'

export const AST_PROPS = ['body', 'comments'] as const
export const AST_PROPS = [
'body',
// disable comments temporarily -- #380
// 'comments'
] as const

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

const physicalFilename = getPhysicalFilename(filePath)

const { root, tokens, comments } = performSyncWork({
fileOptions: {
path: physicalFilename,
value: code,
},
physicalFilename,
isMdx,
ignoreRemarkConfig: ignoreRemarkConfig,
})
let result: WorkerParseResult

try {
result = performSyncWork({
fileOptions: {
path: physicalFilename,
value: code,
},
physicalFilename,
isMdx,
ignoreRemarkConfig: 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 { root, tokens, comments } = result

this._ast = {
...normalizePosition(root.position),
Expand All @@ -85,7 +103,6 @@ export class Parser {
}

for (const prop of AST_PROPS) {
// @ts-expect-error
this._ast[prop].push(...(node.data?.estree[prop] || []))
}
})
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-mdx/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { AST } from 'eslint'
import type { EsprimaToken } from 'espree/lib/token-translator'
import type { Comment as EsComment } from 'estree'
import type { Options } from 'micromark-extension-mdx-expression'
import { runAsWorker } from 'synckit'
import { extractProperties, runAsWorker } from 'synckit'
import type { FrozenProcessor } from 'unified'
import type { Parent } from 'unist'
import type { VFileMessage } from 'vfile-message'
Expand Down Expand Up @@ -184,7 +184,7 @@ runAsWorker(
}

return {
messages: JSON.parse(JSON.stringify(file.messages)) as VFileMessage[],
messages: file.messages.map(message => extractProperties(message)),
content: file.toString(),
}
}
Expand Down
Loading

0 comments on commit c497839

Please sign in to comment.