+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(website): change enabledNurseryRules to All/Recommended select #3810

Merged
merged 5 commits into from
Nov 23, 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
7 changes: 4 additions & 3 deletions website/src/playground/PlaygroundLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
QuoteStyle,
TrailingComma,
Semicolons,
LintRules,
} from "./types";
import {
createLocalStorage,
Expand Down Expand Up @@ -318,9 +319,9 @@ function initState(
semicolons:
(searchParams.get("semicolons") as Semicolons) ??
defaultPlaygroundState.settings.semicolons,
enabledNurseryRules:
searchParams.get("enabledNurseryRules") === "true" ||
defaultPlaygroundState.settings.enabledNurseryRules,
lintRules:
(searchParams.get("lintRules") as LintRules) ??
defaultPlaygroundState.settings.lintRules,
enabledLinting:
searchParams.get("enabledLinting") === "true" ||
defaultPlaygroundState.settings.enabledLinting,
Expand Down
1 change: 1 addition & 0 deletions website/src/playground/styles/_diagnostics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ul.diagnostics-list {
padding-right: 10px;
cursor: pointer;
display: flex;
white-space: pre;

img {
margin: 7px 10px;
Expand Down
2 changes: 1 addition & 1 deletion website/src/playground/styles/_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}

select, input[type=number] {
width: 100px;
width: 110px;
}

select, input[type=number], .input-container {
Expand Down
39 changes: 21 additions & 18 deletions website/src/playground/tabs/SettingsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
IndentStyle,
LintRules,
PlaygroundState,
QuoteProperties,
QuoteStyle,
Expand Down Expand Up @@ -41,7 +42,7 @@ export default function SettingsTab({
quoteProperties,
trailingComma,
semicolons,
enabledNurseryRules,
lintRules,
enabledLinting,
},
},
Expand Down Expand Up @@ -74,9 +75,9 @@ export default function SettingsTab({
setPlaygroundState,
"semicolons",
);
const setEnabledNurseryRules = createPlaygroundSettingsSetter(
const setLintRules = createPlaygroundSettingsSetter(
setPlaygroundState,
"enabledNurseryRules",
"lintRules",
);
const setEnabledLinting = createPlaygroundSettingsSetter(
setPlaygroundState,
Expand Down Expand Up @@ -210,8 +211,8 @@ export default function SettingsTab({
setSemicolons={setSemicolons}
/>
<LinterSettings
enabledNurseryRules={enabledNurseryRules}
setEnabledNurseryRules={setEnabledNurseryRules}
lintRules={lintRules}
setLintRules={setLintRules}
enabledLinting={enabledLinting}
setEnabledLinting={setEnabledLinting}
/>
Expand Down Expand Up @@ -597,13 +598,13 @@ function FormatterSettings({
}

function LinterSettings({
enabledNurseryRules,
setEnabledNurseryRules,
lintRules,
setLintRules,
enabledLinting,
setEnabledLinting,
}: {
enabledNurseryRules: boolean;
setEnabledNurseryRules: (value: boolean) => void;
lintRules: LintRules;
setLintRules: (value: LintRules) => void;
enabledLinting: boolean;
setEnabledLinting: (value: boolean) => void;
}) {
Expand All @@ -622,16 +623,18 @@ function LinterSettings({
<label htmlFor="linting-enabled">Linter enabled</label>
</div>
<div className="field-row">
<input
id="nursery-rules"
aria-describedby="nursery-rules-description"
name="nursery-rules"
type="checkbox"
<label htmlFor="trailingComma">Lint Rules</label>
<select
id="lint-rules"
aria-describedby="lint-rules-description"
name="lint-rules"
disabled={!enabledLinting}
checked={enabledNurseryRules}
onChange={(e) => setEnabledNurseryRules(e.target.checked)}
/>
<label htmlFor="nursery-rules">Nursery lint rules</label>
value={lintRules ?? LintRules.Recommended}
onChange={(e) => setLintRules(e.target.value as LintRules)}
>
<option value={LintRules.Recommended}>Recommended</option>
<option value={LintRules.All}>All</option>
</select>
</div>
</section>
</>
Expand Down
9 changes: 7 additions & 2 deletions website/src/playground/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export enum QuoteStyle {
Single = "single",
}

export enum LintRules {
Recommended = "recommended",
All = "all",
}

export enum QuoteProperties {
AsNeeded = "as-needed",
Preserve = "preserve",
Expand Down Expand Up @@ -93,7 +98,7 @@ export interface PlaygroundSettings {
quoteProperties: QuoteProperties;
trailingComma: TrailingComma;
semicolons: Semicolons;
enabledNurseryRules: boolean;
lintRules: LintRules;
enabledLinting: boolean;
}

Expand Down Expand Up @@ -132,7 +137,7 @@ export const defaultPlaygroundState: PlaygroundState = {
quoteProperties: QuoteProperties.AsNeeded,
trailingComma: TrailingComma.All,
semicolons: Semicolons.Always,
enabledNurseryRules: true,
lintRules: LintRules.Recommended,
enabledLinting: true,
},
};
Expand Down
14 changes: 12 additions & 2 deletions website/src/playground/workers/romeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import init, {
} from "@rometools/wasm-web";
import {
IndentStyle,
LintRules,
LoadingState,
PlaygroundSettings,
QuoteProperties,
Expand Down Expand Up @@ -65,7 +66,7 @@ self.addEventListener("message", async (e) => {
indentWidth,
quoteStyle,
quoteProperties,
enabledNurseryRules,
lintRules,
enabledLinting,
trailingComma,
semicolons,
Expand Down Expand Up @@ -98,10 +99,19 @@ self.addEventListener("message", async (e) => {
},
};

if (enabledNurseryRules) {
if (lintRules === LintRules.All) {
configuration.linter = {
enabled: enabledLinting,
rules: {
correctness: {
noRestrictedGlobals: "error",
noUndeclaredVariables: "error",
noUnusedVariables: "error",
noUselessFragments: "error",
},
style: {
useFragmentSyntax: "error",
},
nursery: {
noConstAssign: "error",
useExhaustiveDependencies: "error",
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载