Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw error with correct loc #382

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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