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

Commit

Permalink
feat(website): add feature to use unrecommended rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanary159357 committed Nov 21, 2022
1 parent 861eb07 commit 4d0e665
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
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 @@ -277,9 +278,9 @@ export function usePlaygroundState(): [
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
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

0 comments on commit 4d0e665

Please sign in to comment.