Skip to content

Commit 89a913c

Browse files
authored
feat: Add CSS tolerant parsing mode (eslint#78)
1 parent efd344c commit 89a913c

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@codemirror/lang-json": "^6.0.1",
3939
"@codemirror/lang-markdown": "^6.2.5",
4040
"@codemirror/language": "^6.10.3",
41-
"@eslint/css": "^0.1.0",
41+
"@eslint/css": "^0.2.0",
4242
"@eslint/js": "^9.9.0",
4343
"@eslint/json": "^0.4.1",
4444
"@eslint/markdown": "^6.1.1",

src/components/ast/css-ast.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ import { ErrorState } from "../error-boundary";
1010
export const CssAst: FC = () => {
1111
const { code, cssOptions, viewModes } = useExplorer();
1212
const { astView } = viewModes;
13-
const { cssMode } = cssOptions;
13+
const { cssMode, tolerant } = cssOptions;
1414
const language = css.languages[cssMode];
15-
const result = language.parse({ body: code.css });
15+
const result = language.parse(
16+
{ body: code.css },
17+
{
18+
languageOptions: { tolerant },
19+
},
20+
);
1621

1722
if (!result.ok) {
1823
const message = parseError(result.errors[0]);

src/components/options.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,21 @@ const MarkdownPanel: React.FC = () => {
6767
};
6868

6969
const CssPanel: React.FC = () => {
70-
return null;
70+
const explorer = useExplorer();
71+
const { cssOptions, setCssOptions } = explorer;
72+
const { tolerant } = cssOptions;
73+
return (
74+
<div className="flex items-center gap-1.5">
75+
<Switch
76+
id="tolerant"
77+
checked={tolerant}
78+
onCheckedChange={(value: boolean) => {
79+
setCssOptions({ ...cssOptions, tolerant: value });
80+
}}
81+
/>
82+
<Label htmlFor="tolerant">Tolerant Parsing</Label>
83+
</div>
84+
);
7185
};
7286

7387
const JavaScriptPanel = () => {

src/hooks/use-explorer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export type MarkdownOptions = {
4545

4646
export type CssOptions = {
4747
cssMode: CssMode;
48+
tolerant: boolean;
4849
};
4950

5051
export type PathIndex = {

src/lib/const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ export const defaultMarkdownOptions: MarkdownOptions = {
385385

386386
export const defaultCssOptions: CssOptions = {
387387
cssMode: "css",
388+
tolerant: false,
388389
};
389390

390391
export const defaultPathIndex: PathIndex = {

0 commit comments

Comments
 (0)