Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit 7d8f7b6

Browse files
authored
feat: support json5 (#11)
1 parent 224befa commit 7d8f7b6

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: node_js
22
node_js:
3-
- 12
3+
- 12
44
branches:
5-
only:
6-
- master
5+
only:
6+
- master
77
script:
8-
- npm run test:all
8+
- npm run test:all

package-lock.json

Lines changed: 21 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"core-js": "^3.6.5",
4343
"eslint": "^7.10.0",
4444
"esquery": "^1.3.1",
45+
"json5": "^2.1.3",
4546
"query-string": "^6.13.5",
4647
"react": "^16.13.1",
4748
"react-bootstrap": "^1.3.0",
@@ -56,6 +57,7 @@
5657
"@types/codemirror": "0.0.98",
5758
"@types/eslint": "^7.2.4",
5859
"@types/jest": "^26.0.14",
60+
"@types/json5": "0.0.30",
5961
"@types/react": "^16.9.51",
6062
"@types/react-bootstrap": "^0.32.24",
6163
"@types/react-dom": "^16.9.8",

src/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, useEffect, ChangeEvent } from "react";
22
import { Container, Row, Col, Tabs, Tab, Spinner } from "react-bootstrap";
3+
import JSON5 from "json5";
34
import { CodeEditor } from "@/components/CodeEditor";
45
import { RuleConfig } from "@/components/RuleConfig";
56
import { LintMessages } from "@/components/LintMessages";
@@ -52,7 +53,7 @@ export const App: FC = () => {
5253

5354
const handleRuleEditing = (ruleStr: string) => {
5455
try {
55-
const rules = JSON.parse(ruleStr);
56+
const rules = JSON5.parse(ruleStr);
5657
setRules(rules);
5758
setRuleConfigError(null);
5859
} catch (error) {
@@ -109,7 +110,7 @@ export const App: FC = () => {
109110
<Row>
110111
<Col className="bottom-col">
111112
<Tabs>
112-
<Tab eventKey="rules" title="Rules">
113+
<Tab eventKey="rules" title="Rules (json5)">
113114
<RuleConfig
114115
initial={rules}
115116
ruleConfig={rules}

src/components/RuleConfig.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from "react";
22
import CodeMirror from "codemirror";
33
import { EDITING_TIMEOUT } from "@/constants";
44
import { debounce } from "@/shared/debounce";
5+
import JSON5 from "json5";
56
import type { FC } from "react";
67
import type { Linter } from "eslint";
78
import "codemirror/lib/codemirror.css";
@@ -25,7 +26,7 @@ const CODE_MIRROR_OPTIONS = {
2526

2627
export const RuleConfig: FC<Props> = (props) => {
2728
const [text, setText] = useState<string>(
28-
JSON.stringify(props.initial, null, 2)
29+
JSON5.stringify(props.initial, null, 2)
2930
);
3031
const ref = useRef<HTMLTextAreaElement>(null);
3132

src/shared/query-params-state.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import JSON5 from "json5";
12
import type { Linter } from "eslint";
23
import type { ParserOptions } from "@typescript-eslint/parser";
34

@@ -13,12 +14,12 @@ export const queryParamsState = {
1314
const decoded = decodeURIComponent(
1415
escape(atob(location.hash.replace("#", "")))
1516
);
16-
return JSON.parse(decoded);
17+
return JSON5.parse(decoded);
1718
} catch {}
1819
return {};
1920
},
2021
set(state: QueryParamsState): void {
21-
const encoded = btoa(unescape(encodeURIComponent(JSON.stringify(state))));
22+
const encoded = btoa(unescape(encodeURIComponent(JSON5.stringify(state))));
2223
location.hash = encoded;
2324
},
2425
};

0 commit comments

Comments
 (0)