Skip to content

Commit

Permalink
Migrate Esprima to SWC (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Apr 23, 2022
1 parent 99ac147 commit 888e0a7
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "lts/*"
- run: npm run lint
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "lts/*"
registry-url: "https://registry.npmjs.org"
cache: npm
- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["12", "14", "16"]
node-version: ["12", "14", "16", "18"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { lintRule } from "unified-lint-rule";
import { visit } from "unist-util-visit";
import { default as esprima } from "esprima";
import { default as swc } from "@swc/core";
import { default as yaml } from "js-yaml";

const remarkLintCodeBlockSyntax = lintRule("remark-lint:code-block-syntax", codeSyntax);
Expand Down Expand Up @@ -43,7 +43,10 @@ function codeSyntax(tree, file) {

function checkJs(code) {
try {
esprima.parseScript(code);
swc.parseSync(code, {
syntax: "ecmascript",
target: "es2022",
});
return null;
} catch (e) {
return e.message;
Expand Down
2 changes: 1 addition & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("JavaScript", () => {
{
column: 1,
line: 1,
message: "Invalid JavaScript: Line 1: Unexpected end of input",
message: expect.stringMatching(/^Invalid JavaScript:/),
ruleId: "code-block-syntax",
source: "remark-lint",
},
Expand Down
Loading

0 comments on commit 888e0a7

Please sign in to comment.